[FFmpeg-devel] [PATCH 2/5] Extend buffer source to accept the time base for the output PTS.
Stefano Sabatini
stefano.sabatini-lala
Mon Oct 11 12:19:36 CEST 2010
---
ffmpeg.c | 5 +++--
libavfilter/vsrc_buffer.c | 19 +++++++++++++++----
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index e0463a9..bfb7f7e 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -424,8 +424,9 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
if ((ret = avfilter_open(&ist->output_video_filter, &output_filter, "out")) < 0)
return ret;
- snprintf(args, 255, "%d:%d:%d", ist->st->codec->width,
- ist->st->codec->height, ist->st->codec->pix_fmt);
+ snprintf(args, 255, "%d:%d:%d:%d:%d", ist->st->codec->width,
+ ist->st->codec->height, ist->st->codec->pix_fmt,
+ ist->st->time_base.num, ist->st->time_base.den);
if ((ret = avfilter_init_filter(ist->input_video_filter, args, NULL)) < 0)
return ret;
if ((ret = avfilter_init_filter(ist->output_video_filter, NULL, &codec->pix_fmt)) < 0)
diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index fa9d135..12ded54 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -33,6 +33,7 @@ typedef struct {
int has_frame;
int h, w;
enum PixelFormat pix_fmt;
+ AVRational time_base; ///< time_base used for expressing the PTS
AVRational pixel_aspect;
} BufferSourceContext;
@@ -40,6 +41,7 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
int64_t pts, AVRational pixel_aspect)
{
BufferSourceContext *c = buffer_filter->priv;
+ AVFilterLink *inlink = buffer_filter->inputs[0];
if (c->has_frame) {
av_log(buffer_filter, AV_LOG_ERROR,
@@ -53,7 +55,16 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
c->frame.interlaced_frame= frame->interlaced_frame;
c->frame.top_field_first = frame->top_field_first;
- c->pts = pts;
+
+ if (av_cmp_q(inlink->time_base, c->time_base)) {
+ c->pts = av_rescale_q(pts, inlink->time_base, c->time_base);
+ av_log(buffer_filter, AV_LOG_DEBUG,
+ "Converting PTS tb1:%d/%d pts1:%"PRId64" -> tb2:%d/%d pts2:%"PRId64"\n",
+ inlink->time_base.num, inlink->time_base.den, pts,
+ c->time_base.num, c->time_base.den, c->pts);
+ } else
+ c->pts = pts;
+
c->pixel_aspect = pixel_aspect;
c->has_frame = 1;
@@ -66,8 +77,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
char pix_fmt_str[128];
int n = 0;
- if (!args || (n = sscanf(args, "%d:%d:%127s", &c->w, &c->h, pix_fmt_str)) != 3) {
- av_log(ctx, AV_LOG_ERROR, "Expected 3 arguments, but only %d found in '%s'\n", n, args ? 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) {
+ av_log(ctx, AV_LOG_ERROR, "Expected 5 arguments, but only %d found in '%s'\n", n, args);
return AVERROR(EINVAL);
}
if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
@@ -122,7 +134,6 @@ static int request_frame(AVFilterLink *link)
av_image_copy(picref->data, picref->linesize,
c->frame.data, c->frame.linesize,
picref->format, link->w, link->h);
-
picref->pts = c->pts;
picref->video->pixel_aspect = c->pixel_aspect;
picref->video->interlaced = c->frame.interlaced_frame;
--
1.7.1
More information about the ffmpeg-devel
mailing list