History

Add sample_aspect_ratio fields to vsrc_buffer arguments. This fixes aspect handling in ffmpeg This is based on a patch by baptiste

Michael Niedermayer committed 15 years ago

Commit 7b3ea551 parent 14b171c5 files · +33 −8Browse files

Unified · Split

5 files
  1. doc/APIchanges +3 −0
  2. doc/filters.texi +8 −3
  3. ffmpeg.c +16 −2
  4. libavfilter/avfilter.h +1 −1
  5. libavfilter/vsrc_buffer.c +5 −2
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2009-03-08 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2011-01-31 - X - lavfi 1.76.0 - vsrc_buffer
17+ Add sample_aspect_ratio fields to vsrc_buffer arguments
18+
1619 2011-01-31 - X - lavfi 1.75.0 - AVFilterLink sample_aspect_ratio
1720 Add sample_aspect_ratio field to AVFilterLink.
1821
doc/filters.texi+8−3
@@ -1014,7 +1014,7 @@ This source is mainly intended for a programmatic use, in particular · 1013 unmodified lines
10141014 through the interface defined in @file{libavfilter/vsrc_buffer.h}.
10151015
10161016 It accepts the following parameters:
1017−@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}
1017+@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}
10181018
10191019 All the parameters need to be explicitely defined.
10201020
@@ -1033,15 +1033,20 @@ name. · 12 unmodified lines
10331033 @item timebase_num, timebase_den
10341034 Specify numerator and denomitor of the timebase assumed by the
10351035 timestamps of the buffered frames.
1036+
1037+@item sample_aspect_ratio.num, sample_aspect_ratio.den
1038+Specify numerator and denominator of the sample aspect ratio assumed
1039+by the video frames.
10361040 @end table
10371041
10381042 For example:
10391043 @example
1040−buffer=320:240:yuv410p:1:24
1044+buffer=320:240:yuv410p:1:24:1:1
10411045 @end example
10421046
10431047 will instruct the source to accept video frames with size 320x240 and
1044−with format "yuv410p" and assuming 1/24 as the timestamps timebase.
1048+with format "yuv410p", assuming 1/24 as the timestamps timebase and
1049+square pixels (1:1 sample aspect ratio).
10451050 Since the pixel format with name "yuv410p" corresponds to the number 6
10461051 (check the enum PixelFormat definition in @file{libavutil/pixfmt.h}),
10471052 this example corresponds to:
ffmpeg.c+16−2
@@ -355,13 +355,21 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) · 354 unmodified lines
355355 AVCodecContext *codec = ost->st->codec;
356356 AVCodecContext *icodec = ist->st->codec;
357357 FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt };
358+ AVRational sample_aspect_ratio;
358359 char args[255];
359360 int ret;
360361
361362 graph = avfilter_graph_alloc();
362363
363− snprintf(args, 255, "%d:%d:%d:%d:%d", ist->st->codec->width,
364− ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE);
364+ if (ist->st->sample_aspect_ratio.num){
365+ sample_aspect_ratio = ist->st->sample_aspect_ratio;
366+ }else
367+ sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;
368+
369+ snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d", ist->st->codec->width,
370+ ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,
371+ sample_aspect_ratio.num, sample_aspect_ratio.den);
372+
365373 ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"),
366374 "src", args, NULL, graph);
367375 if (ret < 0)
@@ -415,6 +423,8 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) · 47 unmodified lines
415423
416424 codec->width = ist->output_video_filter->inputs[0]->w;
417425 codec->height = ist->output_video_filter->inputs[0]->h;
426+ codec->sample_aspect_ratio = ost->st->sample_aspect_ratio =
427+ ist->output_video_filter->inputs[0]->sample_aspect_ratio;
418428
419429 return 0;
420430 }
@@ -2845,6 +2855,10 @@ static void opt_frame_aspect_ratio(const char *arg) · 2424 unmodified lines
28452855 ffmpeg_exit(1);
28462856 }
28472857 frame_aspect_ratio = ar;
2858+
2859+ x = vfilters ? strlen(vfilters) : 0;
2860+ vfilters = av_realloc(vfilters, x+100);
2861+ snprintf(vfilters+x, x+100, "%csetdar=%f\n", x?',':' ', ar);
28482862 }
28492863
28502864 static int opt_metadata(const char *opt, const char *arg)
libavfilter/avfilter.h+1−1
@@ -27,7 +27,7 @@ · 26 unmodified lines
2727 #include "libavcore/samplefmt.h"
2828
2929 #define LIBAVFILTER_VERSION_MAJOR 1
30−#define LIBAVFILTER_VERSION_MINOR 75
30+#define LIBAVFILTER_VERSION_MINOR 76
3131 #define LIBAVFILTER_VERSION_MICRO 0
3232
3333 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
libavfilter/vsrc_buffer.c+5−2
@@ -68,8 +68,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) · 67 unmodified lines
6868 int n = 0;
6969
7070 if (!args ||
71− (n = sscanf(args, "%d:%d:%127[^:]:%d:%d", &c->w, &c->h, pix_fmt_str, &c->time_base.num, &c->time_base.den)) != 5) {
72− av_log(ctx, AV_LOG_ERROR, "Expected 5 arguments, but only %d found in '%s'\n", n, args);
71+ (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str,
72+ &c->time_base.num, &c->time_base.den,
73+ &c->pixel_aspect.num, &c->pixel_aspect.den)) != 7) {
74+ av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but only %d found in '%s'\n", n, args);
7375 return AVERROR(EINVAL);
7476 }
7577 if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
@@ -100,6 +102,7 @@ static int config_props(AVFilterLink *link) · 24 unmodified lines
100102
101103 link->w = c->w;
102104 link->h = c->h;
105+ link->sample_aspect_ratio = c->pixel_aspect;
103106 link->time_base = c->time_base;
104107
105108 return 0;

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