提交 7a11c82f 编写于 作者: M Michael Niedermayer 提交者: Anton Khirnov

vsrc_buffer: add sample_aspect_ratio fields to arguments.

This fixes aspect handling in ffmpeg.

This is based on a patch by Baptiste.
Signed-off-by: NAnton Khirnov <anton@khirnov.net>
上级 2f84bb42
...@@ -13,6 +13,9 @@ libavutil: 2011-04-18 ...@@ -13,6 +13,9 @@ libavutil: 2011-04-18
API changes, most recent first: API changes, most recent first:
2011-04-xx - xxxxxx - lavfi 2.2.0 - vsrc_buffer
Add sample_aspect_ratio fields to vsrc_buffer arguments
2011-04-21 - 94f7451 - lavc 53.1.0 - avcodec.h 2011-04-21 - 94f7451 - lavc 53.1.0 - avcodec.h
Add CODEC_CAP_SLICE_THREADS for codecs supporting sliced threading. Add CODEC_CAP_SLICE_THREADS for codecs supporting sliced threading.
......
...@@ -1190,7 +1190,7 @@ This source is mainly intended for a programmatic use, in particular ...@@ -1190,7 +1190,7 @@ This source is mainly intended for a programmatic use, in particular
through the interface defined in @file{libavfilter/vsrc_buffer.h}. through the interface defined in @file{libavfilter/vsrc_buffer.h}.
It accepts the following parameters: It accepts the following parameters:
@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den} @var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}
All the parameters need to be explicitely defined. All the parameters need to be explicitely defined.
...@@ -1209,15 +1209,20 @@ name. ...@@ -1209,15 +1209,20 @@ name.
@item timebase_num, timebase_den @item timebase_num, timebase_den
Specify numerator and denomitor of the timebase assumed by the Specify numerator and denomitor of the timebase assumed by the
timestamps of the buffered frames. timestamps of the buffered frames.
@item sample_aspect_ratio.num, sample_aspect_ratio.den
Specify numerator and denominator of the sample aspect ratio assumed
by the video frames.
@end table @end table
For example: For example:
@example @example
buffer=320:240:yuv410p:1:24 buffer=320:240:yuv410p:1:24:1:1
@end example @end example
will instruct the source to accept video frames with size 320x240 and will instruct the source to accept video frames with size 320x240 and
with format "yuv410p" and assuming 1/24 as the timestamps timebase. with format "yuv410p", assuming 1/24 as the timestamps timebase and
square pixels (1:1 sample aspect ratio).
Since the pixel format with name "yuv410p" corresponds to the number 6 Since the pixel format with name "yuv410p" corresponds to the number 6
(check the enum PixelFormat definition in @file{libavutil/pixfmt.h}), (check the enum PixelFormat definition in @file{libavutil/pixfmt.h}),
this example corresponds to: this example corresponds to:
......
...@@ -344,13 +344,21 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) ...@@ -344,13 +344,21 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
AVCodecContext *codec = ost->st->codec; AVCodecContext *codec = ost->st->codec;
AVCodecContext *icodec = ist->st->codec; AVCodecContext *icodec = ist->st->codec;
FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt }; FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt };
AVRational sample_aspect_ratio;
char args[255]; char args[255];
int ret; int ret;
graph = avfilter_graph_alloc(); graph = avfilter_graph_alloc();
snprintf(args, 255, "%d:%d:%d:%d:%d", ist->st->codec->width, if (ist->st->sample_aspect_ratio.num){
ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE); sample_aspect_ratio = ist->st->sample_aspect_ratio;
}else
sample_aspect_ratio = ist->st->codec->sample_aspect_ratio;
snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d", ist->st->codec->width,
ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE,
sample_aspect_ratio.num, sample_aspect_ratio.den);
ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"), ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"),
"src", args, NULL, graph); "src", args, NULL, graph);
if (ret < 0) if (ret < 0)
...@@ -404,6 +412,8 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) ...@@ -404,6 +412,8 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
codec->width = ist->output_video_filter->inputs[0]->w; codec->width = ist->output_video_filter->inputs[0]->w;
codec->height = ist->output_video_filter->inputs[0]->h; codec->height = ist->output_video_filter->inputs[0]->h;
codec->sample_aspect_ratio = ost->st->sample_aspect_ratio =
ist->output_video_filter->inputs[0]->sample_aspect_ratio;
return 0; return 0;
} }
...@@ -2784,6 +2794,10 @@ static void opt_frame_aspect_ratio(const char *arg) ...@@ -2784,6 +2794,10 @@ static void opt_frame_aspect_ratio(const char *arg)
ffmpeg_exit(1); ffmpeg_exit(1);
} }
frame_aspect_ratio = ar; frame_aspect_ratio = ar;
x = vfilters ? strlen(vfilters) : 0;
vfilters = av_realloc(vfilters, x+100);
snprintf(vfilters+x, x+100, "%csetdar=%f\n", x?',':' ', ar);
} }
static int opt_metadata(const char *opt, const char *arg) static int opt_metadata(const char *opt, const char *arg)
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "libavutil/samplefmt.h" #include "libavutil/samplefmt.h"
#define LIBAVFILTER_VERSION_MAJOR 2 #define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 1 #define LIBAVFILTER_VERSION_MINOR 2
#define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_MICRO 0
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
......
...@@ -68,8 +68,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ...@@ -68,8 +68,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
int n = 0; int n = 0;
if (!args || if (!args ||
(n = sscanf(args, "%d:%d:%127[^:]:%d:%d", &c->w, &c->h, pix_fmt_str, &c->time_base.num, &c->time_base.den)) != 5) { (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str,
av_log(ctx, AV_LOG_ERROR, "Expected 5 arguments, but only %d found in '%s'\n", n, args); &c->time_base.num, &c->time_base.den,
&c->pixel_aspect.num, &c->pixel_aspect.den)) != 7) {
av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but only %d found in '%s'\n", n, args);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) { if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
...@@ -100,6 +102,7 @@ static int config_props(AVFilterLink *link) ...@@ -100,6 +102,7 @@ static int config_props(AVFilterLink *link)
link->w = c->w; link->w = c->w;
link->h = c->h; link->h = c->h;
link->sample_aspect_ratio = c->pixel_aspect;
link->time_base = c->time_base; link->time_base = c->time_base;
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册