From b58dbb5b031c33cdb88f13cc533f623e82cdbcbd Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Fri, 29 Apr 2011 13:04:47 +0200 Subject: [PATCH] lavc: add a sample_aspect_ratio field to AVFrame The sample aspect ratio is a per-frame property, so it makes sense to define it in AVFrame rather than in the codec/stream context. Simplify application-level sample aspect ratio information extraction, and allow further simplifications. --- avplay.c | 2 +- cmdutils.c | 1 + libavcodec/avcodec.h | 7 +++++++ libavcodec/pthread.c | 1 + libavcodec/utils.c | 2 ++ libavfilter/vsrc_movie.c | 4 ++-- 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/avplay.c b/avplay.c index bf1ac1b3f2..bf246f2382 100644 --- a/avplay.c +++ b/avplay.c @@ -1651,7 +1651,7 @@ static int input_request_frame(AVFilterLink *link) picref->pts = pts; picref->pos = pkt.pos; - picref->video->pixel_aspect = priv->is->video_st->codec->sample_aspect_ratio; + picref->video->pixel_aspect = priv->frame->sample_aspect_ratio; avfilter_start_frame(link, picref); avfilter_draw_slice(link, 0, link->h, 1); avfilter_end_frame(link); diff --git a/cmdutils.c b/cmdutils.c index 1c2bf4696b..c5c2c1ced0 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -1047,6 +1047,7 @@ int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame, frame->top_field_first = picref->video->top_field_first; frame->key_frame = picref->video->key_frame; frame->pict_type = picref->video->pict_type; + frame->sample_aspect_ratio = picref->video->pixel_aspect; return 1; } diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5d39b98123..eb6826bcb0 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1258,6 +1258,13 @@ typedef struct AVFrame { * decoding: set by AVCodecContext.get_buffer() */ uint8_t **extended_data; + + /** + * sample aspect ratio for the video frame, 0/1 if unknown\unspecified + * - encoding: unused + * - decoding: Read by user. + */ + AVRational sample_aspect_ratio; } AVFrame; struct AVCodecInternal; diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index f842edf861..17dd12da6c 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -599,6 +599,7 @@ int ff_thread_decode_frame(AVCodecContext *avctx, *picture = p->frame; *got_picture_ptr = p->got_frame; picture->pkt_dts = p->avpkt.dts; + picture->sample_aspect_ratio = avctx->sample_aspect_ratio; /* * A later call with avkpt->size == 0 may loop over all threads, diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 7e9ddb2e35..7c1a7aea2a 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -584,6 +584,7 @@ void avcodec_get_frame_defaults(AVFrame *pic){ pic->pts= AV_NOPTS_VALUE; pic->key_frame= 1; + pic->sample_aspect_ratio = (AVRational){0, 1}; } AVFrame *avcodec_alloc_frame(void){ @@ -858,6 +859,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi ret = avctx->codec->decode(avctx, picture, got_picture_ptr, avpkt); picture->pkt_dts= avpkt->dts; + picture->sample_aspect_ratio = avctx->sample_aspect_ratio; } emms_c(); //needed to avoid an emms_c() call before every return; diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index dec499904e..a1764732b6 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -248,8 +248,8 @@ static int movie_get_frame(AVFilterLink *outlink) movie->frame->pkt_dts : movie->frame->pkt_pts; movie->picref->pos = movie->frame->reordered_opaque; - movie->picref->video->pixel_aspect = st->sample_aspect_ratio.num ? - st->sample_aspect_ratio : movie->codec_ctx->sample_aspect_ratio; + if (!movie->frame->sample_aspect_ratio.num) + movie->picref->video->pixel_aspect = st->sample_aspect_ratio; movie->picref->video->interlaced = movie->frame->interlaced_frame; movie->picref->video->top_field_first = movie->frame->top_field_first; movie->picref->video->key_frame = movie->frame->key_frame; -- 2.11.0