History

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.

Stefano Sabatini committed 15 years ago

Commit 77e9dee1 parent 1ba572710 files · +28 −15Browse files

Unified · Split

10 files
  1. cmdutils.c +1 −0
  2. doc/APIchanges +3 −0
  3. ffmpeg.c +3 −4
  4. ffplay.c +1 −1
  5. libavcodec/avcodec.h +7 −0
  6. libavcodec/utils.c +3 −0
  7. libavcodec/version.h +1 −1
  8. libavfilter/vsrc_buffer.c +5 −5
  9. libavfilter/vsrc_buffer.h +2 −2
  10. libavfilter/vsrc_movie.c +2 −2
cmdutils.c+1−0
@@ -912,6 +912,7 @@ int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame, · 911 unmodified lines
912912 frame->top_field_first = picref->video->top_field_first;
913913 frame->key_frame = picref->video->key_frame;
914914 frame->pict_type = picref->video->pict_type;
915+ frame->sample_aspect_ratio = picref->video->pixel_aspect;
915916
916917 return 1;
917918 }
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2011-04-18 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2011-05-01 - xxxxxxx - lavc 53.3.0 - AVFrame
17+ Add a sample_aspect_ratio field to AVFrame.
18+
1619 2011-05-01 - xxxxxxx - lavc 53.2.0 - AVFrame
1720 Add a pkt_pos field to AVFrame.
1821
ffmpeg.c+3−4
@@ -1631,13 +1631,12 @@ static int output_packet(AVInputStream *ist, int ist_index, · 1630 unmodified lines
16311631 for(i=0;i<nb_ostreams;i++) {
16321632 ost = ost_table[i];
16331633 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;
16371636 // add it to be filtered
16381637 av_vsrc_buffer_add_frame2(ost->input_video_filter, &picture,
16391638 ist->pts,
1640− sar, ist->st->codec->width, ist->st->codec->height,
1639+ ist->st->codec->width, ist->st->codec->height,
16411640 ist->st->codec->pix_fmt, ""); //TODO user setable params
16421641 }
16431642 }
ffplay.c+1−1
@@ -1688,7 +1688,7 @@ static int input_request_frame(AVFilterLink *link) · 1687 unmodified lines
16881688
16891689 picref->pts = pts;
16901690 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;
16921692 avfilter_start_frame(link, picref);
16931693 avfilter_draw_slice(link, 0, link->h, 1);
16941694 avfilter_end_frame(link);
libavcodec/avcodec.h+7−0
@@ -1011,6 +1011,13 @@ typedef struct AVPanScan{ · 1010 unmodified lines
10111011 * - decoding: Read by user.\
10121012 */\
10131013 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;\
10141021
10151022
10161023 #define FF_QSCALE_TYPE_MPEG1 0
libavcodec/utils.c+3−0
@@ -455,6 +455,7 @@ void avcodec_get_frame_defaults(AVFrame *pic){ · 454 unmodified lines
455455 pic->pts = pic->best_effort_timestamp = AV_NOPTS_VALUE;
456456 pic->pkt_pos = -1;
457457 pic->key_frame= 1;
458+ pic->sample_aspect_ratio = (AVRational){0, 1};
458459 }
459460
460461 AVFrame *avcodec_alloc_frame(void){
@@ -737,6 +738,8 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi · 276 unmodified lines
737738 avpkt);
738739 picture->pkt_dts= avpkt->dts;
739740 picture->pkt_pos= avpkt->pos;
741+ if (!picture->sample_aspect_ratio.num)
742+ picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
740743 }
741744
742745 emms_c(); //needed to avoid an emms_c() call before every return;
libavcodec/version.h+1−1
@@ -21,7 +21,7 @@ · 20 unmodified lines
2121 #define AVCODEC_VERSION_H
2222
2323 #define LIBAVCODEC_VERSION_MAJOR 53
24−#define LIBAVCODEC_VERSION_MINOR 2
24+#define LIBAVCODEC_VERSION_MINOR 3
2525 #define LIBAVCODEC_VERSION_MICRO 0
2626
2727 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
libavfilter/vsrc_buffer.c+5−5
@@ -39,7 +39,7 @@ typedef struct { · 38 unmodified lines
3939 } BufferSourceContext;
4040
4141 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,
4343 int height, enum PixelFormat pix_fmt,
4444 const char *sws_param)
4545 {
@@ -104,20 +104,20 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, · 58 unmodified lines
104104 c->frame.top_field_first = frame->top_field_first;
105105 c->frame.key_frame = frame->key_frame;
106106 c->frame.pict_type = frame->pict_type;
107+ c->frame.sample_aspect_ratio = frame->sample_aspect_ratio;
107108 c->pts = pts;
108− c->pixel_aspect = pixel_aspect;
109109 c->has_frame = 1;
110110
111111 return 0;
112112 }
113113
114114 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
115− int64_t pts, AVRational pixel_aspect)
115+ int64_t pts)
116116 {
117117 BufferSourceContext *c = buffer_filter->priv;
118118
119119 return av_vsrc_buffer_add_frame2(buffer_filter, frame,
120− pts, pixel_aspect, c->w,
120+ pts, c->w,
121121 c->h, c->pix_fmt, "");
122122 }
123123
@@ -190,7 +190,7 @@ static int request_frame(AVFilterLink *link) · 66 unmodified lines
190190 picref->format, link->w, link->h);
191191
192192 picref->pts = c->pts;
193− picref->video->pixel_aspect = c->pixel_aspect;
193+ picref->video->pixel_aspect = c->frame.sample_aspect_ratio;
194194 picref->video->interlaced = c->frame.interlaced_frame;
195195 picref->video->top_field_first = c->frame.top_field_first;
196196 picref->video->key_frame = c->frame.key_frame;
libavfilter/vsrc_buffer.h+2−2
@@ -31,10 +31,10 @@ · 30 unmodified lines
3131 #include "avfilter.h"
3232
3333 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
34− int64_t pts, AVRational pixel_aspect);
34+ int64_t pts);
3535
3636 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,
3838 int height, enum PixelFormat pix_fmt,
3939 const char *sws_param);
4040
libavfilter/vsrc_movie.c+2−2
@@ -247,8 +247,8 @@ static int movie_get_frame(AVFilterLink *outlink) · 246 unmodified lines
247247 movie->frame->pkt_dts : movie->frame->pkt_pts;
248248
249249 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;
252252 movie->picref->video->interlaced = movie->frame->interlaced_frame;
253253 movie->picref->video->top_field_first = movie->frame->top_field_first;
254254 movie->picref->video->key_frame = movie->frame->key_frame;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t