[FFmpeg-devel] [PATCH 08/27] fftools/ffmpeg_enc: merge -force_key_frames source/source_no_drop

Anton Khirnov anton at khirnov.net
Tue Sep 19 22:10:35 EEST 2023


Always use the functionality of the latter, which makes more sense as it
avoids losing keyframes due to vsync code dropping frames.

Deprecate the 'source_no_drop' value, as it is now redundant.
---
 doc/ffmpeg.texi                             |  5 -----
 fftools/ffmpeg.h                            |  3 +++
 fftools/ffmpeg_enc.c                        |  5 +----
 fftools/ffmpeg_mux_init.c                   |  6 +++++-
 tests/ref/fate/force_key_frames-source-drop | 22 ++++++++++-----------
 5 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index d2864ff37e..ea473e14e8 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1060,7 +1060,6 @@ Deprecated see -bsf
 @item -force_key_frames[:@var{stream_specifier}] @var{time}[, at var{time}...] (@emph{output,per-stream})
 @item -force_key_frames[:@var{stream_specifier}] expr:@var{expr} (@emph{output,per-stream})
 @item -force_key_frames[:@var{stream_specifier}] source (@emph{output,per-stream})
- at item -force_key_frames[:@var{stream_specifier}] source_no_drop (@emph{output,per-stream})
 
 @var{force_key_frames} can take arguments of the following form:
 
@@ -1121,10 +1120,6 @@ starting from second 13:
 @item source
 If the argument is @code{source}, ffmpeg will force a key frame if
 the current frame being encoded is marked as a key frame in its source.
-
- at item source_no_drop
-If the argument is @code{source_no_drop}, ffmpeg will force a key frame if
-the current frame being encoded is marked as a key frame in its source.
 In cases where this particular source frame has to be dropped,
 enforce the next available frame to become a key frame instead.
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 2e8f1db9b6..eaa663e718 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -58,6 +58,7 @@
 #define FFMPEG_OPT_ADRIFT_THRESHOLD 1
 #define FFMPEG_OPT_ENC_TIME_BASE_NUM 1
 #define FFMPEG_OPT_TOP 1
+#define FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP 1
 
 enum VideoSyncMethod {
     VSYNC_AUTO = -1,
@@ -484,7 +485,9 @@ typedef enum {
 
 enum {
     KF_FORCE_SOURCE         = 1,
+#if FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP
     KF_FORCE_SOURCE_NO_DROP = 2,
+#endif
 };
 
 typedef struct KeyframeForceCtx {
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1db67d1497..0ad3a7b6b1 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1105,10 +1105,7 @@ static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf,
             kf->expr_const_values[FKF_N_FORCED]     += 1;
             goto force_keyframe;
         }
-    } else if (kf->type == KF_FORCE_SOURCE &&
-               (in_picture->flags & AV_FRAME_FLAG_KEY) && !dup_idx) {
-            goto force_keyframe;
-    } else if (kf->type == KF_FORCE_SOURCE_NO_DROP && !dup_idx) {
+    } else if (kf->type == KF_FORCE_SOURCE && !dup_idx) {
         int dropped_keyframe = kf->dropped_keyframe;
         kf->dropped_keyframe = 0;
         if ((in_picture->flags & AV_FRAME_FLAG_KEY) || dropped_keyframe)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 9d6f442068..f35680e355 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2509,8 +2509,12 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o)
             // parse it only for static kf timings
         } else if (!strcmp(forced_keyframes, "source")) {
             ost->kf.type = KF_FORCE_SOURCE;
+#if FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP
         } else if (!strcmp(forced_keyframes, "source_no_drop")) {
-            ost->kf.type = KF_FORCE_SOURCE_NO_DROP;
+            av_log(ost, AV_LOG_WARNING, "The 'source_no_drop' value for "
+                   "-force_key_frames is deprecated, use just 'source'\n");
+            ost->kf.type = KF_FORCE_SOURCE;
+#endif
         } else {
             int ret = parse_forced_key_frames(ost, &ost->kf, mux, forced_keyframes);
             if (ret < 0)
diff --git a/tests/ref/fate/force_key_frames-source-drop b/tests/ref/fate/force_key_frames-source-drop
index 99aa2ae826..220c0f0f88 100644
--- a/tests/ref/fate/force_key_frames-source-drop
+++ b/tests/ref/fate/force_key_frames-source-drop
@@ -9,14 +9,14 @@
 0,          2,          3,        1,       24, 0x589c06e0, F=0x0, S=1,        8
 0,          3,          4,        1,       24, 0x4a700621, F=0x0, S=1,        8
 0,          4,          5,        1,       24, 0x4f300661, F=0x0, S=1,        8
-0,          5,          6,        1,       24, 0x53f006a1, F=0x0, S=1,        8
-0,          6,          7,        1,       24, 0x58b006e1, F=0x0, S=1,        8
-0,          7,          8,        1,       24, 0x4a840622, F=0x0, S=1,        8
-0,          8,          9,        1,       24, 0x4f440662, F=0x0, S=1,        8
-0,          9,         10,        1,       24, 0x540406a2, F=0x0, S=1,        8
-0,         10,         11,        1,       24, 0x58c406e2, F=0x0, S=1,        8
-0,         11,         12,        1,       24, 0x4a980623, F=0x0, S=1,        8
-0,         12,         13,        1,       24, 0x4f580663, F=0x0, S=1,        8
-0,         13,         14,        1,       24, 0x541806a3, F=0x0, S=1,        8
-0,         14,         15,        1,       24, 0x58d806e3, F=0x0, S=1,        8
-0,         15,         16,        1,       24, 0x4aac0624, F=0x0, S=1,        8
+0,          5,          6,        1,       57, 0x7a110e90, S=1,        8
+0,          6,          7,        1,       24, 0x4f1c0660, F=0x0, S=1,        8
+0,          7,          8,        1,       24, 0x53dc06a0, F=0x0, S=1,        8
+0,          8,          9,        1,       24, 0x589c06e0, F=0x0, S=1,        8
+0,          9,         10,        1,       24, 0x4a700621, F=0x0, S=1,        8
+0,         10,         11,        1,       24, 0x4f300661, F=0x0, S=1,        8
+0,         11,         12,        1,       24, 0x53f006a1, F=0x0, S=1,        8
+0,         12,         13,        1,       24, 0x58b006e1, F=0x0, S=1,        8
+0,         13,         14,        1,       24, 0x4a840622, F=0x0, S=1,        8
+0,         14,         15,        1,       57, 0x88850f14, S=1,        8
+0,         15,         16,        1,       57, 0x7aa20e95, S=1,        8
-- 
2.40.1



More information about the ffmpeg-devel mailing list