使用默认编码器将.JPGs转换为.MP4时,无论持续时间如何,什么ffmpeg命令行将强制最后一帧成为关键帧?
我已经看到了用于控制关键帧的ffmpg选项-force_key_frames(如下所示),但是看不到它如何提供此结果。
-force_key_frames[:stream_specifier] time[,time...] (output,per-stream)
-force_key_frames[:stream_specifier] expr:expr (output,per-stream)
Force key frames at the specified timestamps, more precisely at the first frames after each specified time.
If the argument is prefixed with expr:, the string expr is interpreted like an expression and is evaluated for each frame. A key frame is forced in case the evaluation is non-zero.
If one of the times is "chapters[delta]", it is expanded into the time of the beginning of all chapters in the file, shifted by delta, expressed as a time in seconds. This option can be useful to ensure that a seek point is present at a chapter mark or any other designated place in the output file.
For example, to insert a key frame at 5 minutes, plus key frames 0.1 second before the beginning of every chapter:
-force_key_frames 0:05:00,chapters-0.1
The expression in expr can contain the following constants:
n
the number of current processed frame, starting from 0
n_forced
the number of forced frames
prev_forced_n
the number of the previous forced frame, it is NAN when no keyframe was forced yet
prev_forced_t
the time of the previous forced frame, it is NAN when no keyframe was forced yet
t
the time of the current processed frame
For example to force a key frame every 5 seconds, you can specify:
-force_key_frames expr:gte(t,n_forced*5)
To force a key frame 5 seconds after the time of the last forced one, starting from second 13:
-force_key_frames expr:if(isnan(prev_forced_t),gte(t,13),gte(t,prev_forced_t+5))
Note that forcing too many keyframes is very harmful for the lookahead algorithms of certain encoders: using fixed-GOP options or similar would be more efficient.