diff mbox series

[FFmpeg-devel,08/13] fftools/ffmpeg: stop calling adjust_frame_pts_to_encoder_tb() for audio

Message ID 20221126081911.31275-8-anton@khirnov.net
State Accepted
Commit 86a71d6b3c11da9fd0606ddf814affa92eef83cf
Headers show
Series [FFmpeg-devel,01/13] fftools/ffmpeg: stop explicitly closing decoders | 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 Nov. 26, 2022, 8:19 a.m. UTC
Almost none of that function's complexity is useful for audio, it can
be replaced by a simple av_rescale_q().
---
 fftools/ffmpeg.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2ee40890a9..cb65f26100 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -933,15 +933,22 @@  static int submit_encode_frame(OutputFile *of, OutputStream *ost,
 static void do_audio_out(OutputFile *of, OutputStream *ost,
                          AVFrame *frame)
 {
+    AVCodecContext *enc = ost->enc_ctx;
     int ret;
 
-    adjust_frame_pts_to_encoder_tb(of, ost, frame);
-
     if (!check_recording_time(ost, ost->next_pts, ost->enc_ctx->time_base))
         return;
 
     if (frame->pts == AV_NOPTS_VALUE)
         frame->pts = ost->next_pts;
+    else {
+        int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
+        frame->pts =
+            av_rescale_q(frame->pts, frame->time_base, enc->time_base) -
+            av_rescale_q(start_time, AV_TIME_BASE_Q,   enc->time_base);
+    }
+    frame->time_base = enc->time_base;
+
     ost->next_pts = frame->pts + frame->nb_samples;
 
     ret = submit_encode_frame(of, ost, frame);