[FFmpeg-devel] [PATCH 09/11] doc/examples/transcode: fix timestamps scaling
Stefano Sabatini
stefasab at gmail.com
Sat Sep 2 18:19:19 EEST 2023
Set pkt_timebase in the decoder and in the decoded frame, use it for
the filterchain source, and rescale the filtered frame to the target
encoder time_base.
This fixes filtering in case the time base was not set in the decoder,
causing the error:
[in @ 0x5647fc26ec80] Invalid time base 0/1
---
doc/examples/transcode.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index b94fdbede2..524bb47f50 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -276,7 +276,7 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
snprintf(args, sizeof(args),
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
- dec_ctx->time_base.num, dec_ctx->time_base.den,
+ dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
dec_ctx->sample_aspect_ratio.num,
dec_ctx->sample_aspect_ratio.den);
@@ -303,6 +303,7 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
}
} else if (dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
char buf[64];
+
buffersrc = avfilter_get_by_name("abuffer");
buffersink = avfilter_get_by_name("abuffersink");
if (!buffersrc || !buffersink) {
@@ -317,7 +318,7 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
av_channel_layout_describe(&dec_ctx->ch_layout, buf, sizeof(buf));
snprintf(args, sizeof(args),
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s",
- dec_ctx->time_base.num, dec_ctx->time_base.den, dec_ctx->sample_rate,
+ dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den, dec_ctx->sample_rate,
av_get_sample_fmt_name(dec_ctx->sample_fmt),
buf);
@@ -470,6 +471,7 @@ static int encode_write_frame(unsigned int stream_index, int flush)
if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE) {
filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base,
stream->enc_ctx->time_base);
+ filt_frame->time_base = stream->enc_ctx->time_base;
log_frame(filt_frame, stream_index, "encoder <-");
}
--
2.34.1
More information about the ffmpeg-devel
mailing list