diff mbox series

[FFmpeg-devel,3/3] doc/examples/transcode: convert timestamps between filtering and encoding

Message ID 20230531153205.24424-3-anton@khirnov.net
State Accepted
Commit ba32f284983037bcf65c8eb372703cd15bc35078
Headers show
Series [FFmpeg-devel,1/3] doc/examples/transcode: set packet timebase for decoding | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov May 31, 2023, 3:32 p.m. UTC
The timebases do not have to match.
---
 doc/examples/transcode.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Paul B Mahol May 31, 2023, 4:04 p.m. UTC | #1
LGTM
diff mbox series

Patch

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 2e1491f432..ebe5ad2a42 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -439,6 +439,10 @@  static int encode_write_frame(unsigned int stream_index, int flush)
     /* encode filtered frame */
     av_packet_unref(enc_pkt);
 
+    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);
+
     ret = avcodec_send_frame(stream->enc_ctx, filt_frame);
 
     if (ret < 0)
@@ -493,6 +497,7 @@  static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index)
             break;
         }
 
+        filter->filtered_frame->time_base = av_buffersink_get_time_base(filter->buffersink_ctx);;
         filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE;
         ret = encode_write_frame(stream_index, 0);
         av_frame_unref(filter->filtered_frame);