diff mbox series

[FFmpeg-devel,06/36] fftools/ffmpeg: rework applying input -r

Message ID 20230517102029.541-6-anton@khirnov.net
State Accepted
Commit 30a3fee24f8a5d38c59ae157ac04cf23dcb064e5
Headers show
Series [FFmpeg-devel,01/36] fftools/ffmpeg: shorten a variable name | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Anton Khirnov May 17, 2023, 10:19 a.m. UTC
Do not use a separate counter for CFR timestamps forced with -r used as
an input option. Set durations properly and let estimation code do the
rest.
---
 fftools/ffmpeg.c | 10 +++++++---
 fftools/ffmpeg.h |  4 ----
 2 files changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9e5e56e9e7..e368f5a148 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -985,7 +985,7 @@  static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
     // durations, then this should be simplified.
 
     // prefer frame duration for containers with timestamps
-    if (frame->duration > 0 && !ifile->format_nots)
+    if (frame->duration > 0 && (!ifile->format_nots || ist->framerate.num))
         return frame->duration;
 
     if (ist->dec_ctx->framerate.den && ist->dec_ctx->framerate.num) {
@@ -1090,8 +1090,12 @@  static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output,
 
     frame->pts = frame->best_effort_timestamp;
 
-    if (ist->framerate.num)
-        frame->pts = ist->cfr_next_pts++;
+    // forced fixed framerate
+    if (ist->framerate.num) {
+        frame->pts       = AV_NOPTS_VALUE;
+        frame->duration  = 1;
+        frame->time_base = av_inv_q(ist->framerate);
+    }
 
     // no timestamp available - extrapolate from previous frame duration
     if (frame->pts == AV_NOPTS_VALUE)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f88792d7eb..3c7991c73a 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -372,10 +372,6 @@  typedef struct InputStream {
 
     int64_t filter_in_rescale_delta_last;
 
-    // when forcing constant input framerate through -r,
-    // this contains the pts that will be given to the next decoded frame
-    int64_t cfr_next_pts;
-
     int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
 
     AVDictionary *decoder_opts;