[FFmpeg-devel] [PATCH 2/4 v2] ffmpeg: move AVFrame time base adjustment into a function

Jan Ekström jeebjp at gmail.com
Mon Sep 14 23:08:36 EEST 2020


On Mon, Sep 14, 2020 at 12:31 AM Jan Ekström <jeebjp at gmail.com> wrote:
>

Diff between v1 and v2 follows:

- Forgotten to be removed debug logs removed.
- Still log debug_ts even in case of nullptr AVFrame or AV_NOPTS_VALUE.

Decided against separating the logging because this way it's a
self-contained package and the goto lets us do an early exit.

Jan

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5425ba245d..8874da9268 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -900,11 +900,11 @@ static int check_recording_time(OutputStream *ost)
 static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
                                              AVFrame *frame)
 {
+    double float_pts = AV_NOPTS_VALUE; // this is identical to
frame.pts but with higher precision
     if (!frame || frame->pts == AV_NOPTS_VALUE ||
         !ost->filter || !ost->filter->graph->graph)
-        return AV_NOPTS_VALUE;
+        goto early_exit;

-    double float_pts = AV_NOPTS_VALUE; // this is identical to
frame.pts but with higher precision
     AVFilterContext *filter = ost->filter->filter;
     AVCodecContext *enc = ost->enc_ctx;

@@ -914,13 +914,6 @@ static double
adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
     int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);

     tb.den <<= extra_bits;
-    av_log(NULL, AV_LOG_VERBOSE,
-           "%s: frame pts: %"PRId64" start_time: %"PRId64", "
-           "filter_tb: %d/%d, tb: %d/%d\n",
-           __FUNCTION__, frame->pts, start_time,
-           filter_tb.num, filter_tb.den,
-           tb.num, tb.den);
-
     float_pts =
         av_rescale_q(frame->pts, filter_tb, tb) -
         av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
@@ -932,15 +925,14 @@ static double
adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
         av_rescale_q(frame->pts, filter_tb, enc->time_base) -
         av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);

-    av_log(NULL, AV_LOG_VERBOSE,
-           "%s: post-adjustment PTS: %"PRId64"\n",
-           __FUNCTION__, frame->pts);
+early_exit:

     if (debug_ts) {
         av_log(NULL, AV_LOG_INFO, "filter -> pts:%s pts_time:%s
exact:%f time_base:%d/%d\n",
-                av_ts2str(frame->pts), av_ts2timestr(frame->pts,
&enc->time_base),
-                float_pts,
-                enc->time_base.num, enc->time_base.den);
+               frame ? av_ts2str(frame->pts) : "NULL",
+               frame ? av_ts2timestr(frame->pts, &enc->time_base) : "NULL",
+               float_pts,
+               enc->time_base.num, enc->time_base.den);
     }

     return float_pts;


More information about the ffmpeg-devel mailing list