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