Hi! Attached patch allows users to know about specific properties of a decoded stream, two examples included.
To be split in two or three, version bumps missing. Please comment, Carl Eugen
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 738f4db..c8b70d7 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3173,6 +3173,16 @@ typedef struct AVCodecContext { * - decoding: set by user through AVOPtions (NO direct access) */ char *codec_whitelist; + + /* + * Properties of the stream that gets decoded + * To be accessed through av_codec_get_properties() (NO direct access) + * - encoding: unused + * - decoding: set by libavcodec + */ + unsigned properties; +#define FF_CODEC_PROPERTY_LOSSLESS 0x00000001 +#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002 } AVCodecContext; AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx); @@ -3181,6 +3191,8 @@ void av_codec_set_pkt_timebase (AVCodecContext *avctx, AVRational const AVCodecDescriptor *av_codec_get_codec_descriptor(const AVCodecContext *avctx); void av_codec_set_codec_descriptor(AVCodecContext *avctx, const AVCodecDescriptor *desc); +unsigned av_codec_get_codec_properties(const AVCodecContext *avctx); + int av_codec_get_lowres(const AVCodecContext *avctx); void av_codec_set_lowres(AVCodecContext *avctx, int val); diff --git a/libavcodec/h264.c b/libavcodec/h264.c index f62ad6a..eb834f1 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -886,6 +886,7 @@ static void decode_postinit(H264Context *h, int setup_finished) memcpy(sd->data, h->a53_caption, h->a53_caption_size); av_freep(&h->a53_caption); h->a53_caption_size = 0; + h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } cur->mmco_reset = h->mmco_reset; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index f85eabf..f046f8a 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2058,6 +2058,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, goto fail; break; case SOF3: + s->avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS; s->lossless = 1; s->ls = 0; s->progressive = 0; @@ -2065,6 +2066,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, goto fail; break; case SOF48: + s->avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS; s->lossless = 1; s->ls = 1; s->progressive = 0; diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index b0e5ae9..9947e5b 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1685,6 +1685,7 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) if (sd) memcpy(sd->data, s1->a53_caption, s1->a53_caption_size); av_freep(&s1->a53_caption); + avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } if (s1->has_stereo3d) { diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 0701786..fe5ac01 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1293,6 +1293,11 @@ MAKE_ACCESSORS(AVCodecContext, codec, int, lowres) MAKE_ACCESSORS(AVCodecContext, codec, int, seek_preroll) MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix) +unsigned av_codec_get_codec_properties(const AVCodecContext *codec) +{ + return codec->properties; +} + int av_codec_get_max_lowres(const AVCodec *codec) { return codec->max_lowres; @@ -3147,6 +3152,13 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) if (encode) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", q=%d-%d", enc->qmin, enc->qmax); + } else { + if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS) + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", Closed Captions"); + if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS) + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", lossless"); } break; case AVMEDIA_TYPE_AUDIO: diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 6888326..5b5ad99 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -733,6 +733,8 @@ static int decode_frame_header(AVCodecContext *ctx, s->uvac_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0; s->lossless = s->yac_qi == 0 && s->ydc_qdelta == 0 && s->uvdc_qdelta == 0 && s->uvac_qdelta == 0; + if (s->lossless) + ctx->properties |= FF_CODEC_PROPERTY_LOSSLESS; /* segmentation header info */ s->segmentation.ignore_refmap = 0; diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 723a847..8caa6a2 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -1417,6 +1417,7 @@ static int webp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, chunk_size, 0); if (ret < 0) return ret; + avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS; } bytestream2_skip(&gb, chunk_size); break;
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel