diff mbox series

[FFmpeg-devel,06/12] fftools/ffmpeg_enc: unbreak -force_key_frames source_no_drop

Message ID 20231003153526.19228-6-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/12] fftools/ffmpeg_enc: move handling video frame duration to video_sync_process() | expand

Checks

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

Commit Message

Anton Khirnov Oct. 3, 2023, 3:35 p.m. UTC
Unlike the 'source' mode, which preserves source keyframe-marking as-is,
the 'source_no_drop' mode attempts to keep track of keyframes dropped by
framerate conversion and mark the next output frame as key in such
cases. However,
* c75be061487 broke this functionality entirely, and made it equivalent
  to 'source'
* even before it would only work when the frame immediately following
  the dropped keyframe is preserved and not dropped as well

Also, drop a redundant check for 'frame' in setting dropped_keyframe, as
it is redundant with the check on the above line.
---
 fftools/ffmpeg_enc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index b928bf208c..42f64a4a49 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1066,7 +1066,7 @@  finish:
     }
 
     ost->last_dropped = *nb_frames == *nb_frames_prev && frame;
-    ost->kf.dropped_keyframe = ost->last_dropped && frame && (frame->flags & AV_FRAME_FLAG_KEY);
+    ost->kf.dropped_keyframe |= ost->last_dropped && (frame->flags & AV_FRAME_FLAG_KEY);
 }
 
 static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf,
@@ -1109,8 +1109,9 @@  static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf,
                (in_picture->flags & AV_FRAME_FLAG_KEY) && !dup_idx) {
             goto force_keyframe;
     } else if (kf->type == KF_FORCE_SOURCE_NO_DROP && !dup_idx) {
+        int dropped_keyframe = kf->dropped_keyframe;
         kf->dropped_keyframe = 0;
-        if ((in_picture->flags & AV_FRAME_FLAG_KEY) || kf->dropped_keyframe)
+        if ((in_picture->flags & AV_FRAME_FLAG_KEY) || dropped_keyframe)
             goto force_keyframe;
     }