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.
Unified · Split
| @@ -912,6 +912,7 @@ int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame, · 911 unmodified lines | ||
| 912 | 912 | frame->top_field_first = picref->video->top_field_first; |
| 913 | 913 | frame->key_frame = picref->video->key_frame; |
| 914 | 914 | frame->pict_type = picref->video->pict_type; |
| 915 | + frame->sample_aspect_ratio = picref->video->pixel_aspect; | |
| 915 | 916 | |
| 916 | 917 | return 1; |
| 917 | 918 | } |
| @@ -13,6 +13,9 @@ libavutil: 2011-04-18 · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | API changes, most recent first: |
| 15 | 15 | |
| 16 | +2011-05-01 - xxxxxxx - lavc 53.3.0 - AVFrame | |
| 17 | + Add a sample_aspect_ratio field to AVFrame. | |
| 18 | + | |
| 16 | 19 | 2011-05-01 - xxxxxxx - lavc 53.2.0 - AVFrame |
| 17 | 20 | Add a pkt_pos field to AVFrame. |
| 18 | 21 | |
| @@ -1631,13 +1631,12 @@ static int output_packet(AVInputStream *ist, int ist_index, · 1630 unmodified lines | ||
| 1631 | 1631 | for(i=0;i<nb_ostreams;i++) { |
| 1632 | 1632 | ost = ost_table[i]; |
| 1633 | 1633 | if (ost->input_video_filter && ost->source_index == ist_index) { |
| 1634 | − AVRational sar; | |
| 1635 | − if (ist->st->sample_aspect_ratio.num) sar = ist->st->sample_aspect_ratio; | |
| 1636 | − else sar = ist->st->codec->sample_aspect_ratio; | |
| 1634 | + if (!picture.sample_aspect_ratio.num) | |
| 1635 | + picture.sample_aspect_ratio = ist->st->sample_aspect_ratio; | |
| 1637 | 1636 | // add it to be filtered |
| 1638 | 1637 | av_vsrc_buffer_add_frame2(ost->input_video_filter, &picture, |
| 1639 | 1638 | ist->pts, |
| 1640 | − sar, ist->st->codec->width, ist->st->codec->height, | |
| 1639 | + ist->st->codec->width, ist->st->codec->height, | |
| 1641 | 1640 | ist->st->codec->pix_fmt, ""); //TODO user setable params |
| 1642 | 1641 | } |
| 1643 | 1642 | } |
| @@ -1688,7 +1688,7 @@ static int input_request_frame(AVFilterLink *link) · 1687 unmodified lines | ||
| 1688 | 1688 | |
| 1689 | 1689 | picref->pts = pts; |
| 1690 | 1690 | picref->pos = priv->frame->pkt_pos; |
| 1691 | − picref->video->pixel_aspect = priv->is->video_st->codec->sample_aspect_ratio; | |
| 1691 | + picref->video->pixel_aspect = priv->frame->sample_aspect_ratio; | |
| 1692 | 1692 | avfilter_start_frame(link, picref); |
| 1693 | 1693 | avfilter_draw_slice(link, 0, link->h, 1); |
| 1694 | 1694 | avfilter_end_frame(link); |
| @@ -1011,6 +1011,13 @@ typedef struct AVPanScan{ · 1010 unmodified lines | ||
| 1011 | 1011 | * - decoding: Read by user.\ |
| 1012 | 1012 | */\ |
| 1013 | 1013 | int64_t pkt_pos;\ |
| 1014 | +\ | |
| 1015 | + /**\ | |
| 1016 | + * reordered sample aspect ratio for the video frame, 0/1 if unknown\unspecified | |
| 1017 | + * - encoding: unused\ | |
| 1018 | + * - decoding: Read by user.\ | |
| 1019 | + */\ | |
| 1020 | + AVRational sample_aspect_ratio;\ | |
| 1014 | 1021 | |
| 1015 | 1022 | |
| 1016 | 1023 | #define FF_QSCALE_TYPE_MPEG1 0 |
| @@ -455,6 +455,7 @@ void avcodec_get_frame_defaults(AVFrame *pic){ · 454 unmodified lines | ||
| 455 | 455 | pic->pts = pic->best_effort_timestamp = AV_NOPTS_VALUE; |
| 456 | 456 | pic->pkt_pos = -1; |
| 457 | 457 | pic->key_frame= 1; |
| 458 | + pic->sample_aspect_ratio = (AVRational){0, 1}; | |
| 458 | 459 | } |
| 459 | 460 | |
| 460 | 461 | AVFrame *avcodec_alloc_frame(void){ |
| @@ -737,6 +738,8 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi · 276 unmodified lines | ||
| 737 | 738 | avpkt); |
| 738 | 739 | picture->pkt_dts= avpkt->dts; |
| 739 | 740 | picture->pkt_pos= avpkt->pos; |
| 741 | + if (!picture->sample_aspect_ratio.num) | |
| 742 | + picture->sample_aspect_ratio = avctx->sample_aspect_ratio; | |
| 740 | 743 | } |
| 741 | 744 | |
| 742 | 745 | emms_c(); //needed to avoid an emms_c() call before every return; |
| @@ -21,7 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | #define AVCODEC_VERSION_H |
| 22 | 22 | |
| 23 | 23 | #define LIBAVCODEC_VERSION_MAJOR 53 |
| 24 | −#define LIBAVCODEC_VERSION_MINOR 2 | |
| 24 | +#define LIBAVCODEC_VERSION_MINOR 3 | |
| 25 | 25 | #define LIBAVCODEC_VERSION_MICRO 0 |
| 26 | 26 | |
| 27 | 27 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -39,7 +39,7 @@ typedef struct { · 38 unmodified lines | ||
| 39 | 39 | } BufferSourceContext; |
| 40 | 40 | |
| 41 | 41 | int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, |
| 42 | − int64_t pts, AVRational pixel_aspect, int width, | |
| 42 | + int64_t pts, int width, | |
| 43 | 43 | int height, enum PixelFormat pix_fmt, |
| 44 | 44 | const char *sws_param) |
| 45 | 45 | { |
| @@ -104,20 +104,20 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, · 58 unmodified lines | ||
| 104 | 104 | c->frame.top_field_first = frame->top_field_first; |
| 105 | 105 | c->frame.key_frame = frame->key_frame; |
| 106 | 106 | c->frame.pict_type = frame->pict_type; |
| 107 | + c->frame.sample_aspect_ratio = frame->sample_aspect_ratio; | |
| 107 | 108 | c->pts = pts; |
| 108 | − c->pixel_aspect = pixel_aspect; | |
| 109 | 109 | c->has_frame = 1; |
| 110 | 110 | |
| 111 | 111 | return 0; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, |
| 115 | − int64_t pts, AVRational pixel_aspect) | |
| 115 | + int64_t pts) | |
| 116 | 116 | { |
| 117 | 117 | BufferSourceContext *c = buffer_filter->priv; |
| 118 | 118 | |
| 119 | 119 | return av_vsrc_buffer_add_frame2(buffer_filter, frame, |
| 120 | − pts, pixel_aspect, c->w, | |
| 120 | + pts, c->w, | |
| 121 | 121 | c->h, c->pix_fmt, ""); |
| 122 | 122 | } |
| 123 | 123 | |
| @@ -190,7 +190,7 @@ static int request_frame(AVFilterLink *link) · 66 unmodified lines | ||
| 190 | 190 | picref->format, link->w, link->h); |
| 191 | 191 | |
| 192 | 192 | picref->pts = c->pts; |
| 193 | − picref->video->pixel_aspect = c->pixel_aspect; | |
| 193 | + picref->video->pixel_aspect = c->frame.sample_aspect_ratio; | |
| 194 | 194 | picref->video->interlaced = c->frame.interlaced_frame; |
| 195 | 195 | picref->video->top_field_first = c->frame.top_field_first; |
| 196 | 196 | picref->video->key_frame = c->frame.key_frame; |
| @@ -31,10 +31,10 @@ · 30 unmodified lines | ||
| 31 | 31 | #include "avfilter.h" |
| 32 | 32 | |
| 33 | 33 | int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, |
| 34 | − int64_t pts, AVRational pixel_aspect); | |
| 34 | + int64_t pts); | |
| 35 | 35 | |
| 36 | 36 | int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, |
| 37 | − int64_t pts, AVRational pixel_aspect, int width, | |
| 37 | + int64_t pts, int width, | |
| 38 | 38 | int height, enum PixelFormat pix_fmt, |
| 39 | 39 | const char *sws_param); |
| 40 | 40 | |
| @@ -247,8 +247,8 @@ static int movie_get_frame(AVFilterLink *outlink) · 246 unmodified lines | ||
| 247 | 247 | movie->frame->pkt_dts : movie->frame->pkt_pts; |
| 248 | 248 | |
| 249 | 249 | movie->picref->pos = movie->frame->pkt_pos; |
| 250 | − movie->picref->video->pixel_aspect = st->sample_aspect_ratio.num ? | |
| 251 | − st->sample_aspect_ratio : movie->codec_ctx->sample_aspect_ratio; | |
| 250 | + if (!movie->frame->sample_aspect_ratio.num) | |
| 251 | + movie->picref->video->pixel_aspect = st->sample_aspect_ratio; | |
| 252 | 252 | movie->picref->video->interlaced = movie->frame->interlaced_frame; |
| 253 | 253 | movie->picref->video->top_field_first = movie->frame->top_field_first; |
| 254 | 254 | movie->picref->video->key_frame = movie->frame->key_frame; |