diff mbox series

[FFmpeg-devel,09/11] doc/examples/transcode: fix timestamps scaling

Message ID 20230902151921.1712373-10-stefasab@gmail.com
State New
Headers show
Series [FFmpeg-devel,01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Stefano Sabatini Sept. 2, 2023, 3:19 p.m. UTC
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 mbox series

Patch

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 <-");
     }