ffmpegh.264keyframeh.265transcode

Maintain keyframes when transcoding and removing b-frames


I need to transcode a video from H.265 in a .mov container to H.264 in a .mkv container and would like to remove b-frames. The command to do that with ffmpeg is relatively straightforward [0], but it appears to be removing keyframes and using scene detection for when to use them.

Is there a way to have it maintain the keyframes in the output?

0: ffmpeg -i <input.mov> -vcodec libx264 -bf 0 -acodec copy <output.mkv>


Solution

  • Use

    ffmpeg -i <input.mov> -force_key_frames source -vcodec libx264 -bf 0 -acodec copy <output.mkv>

    This will place KFs at same timestamps* as in the source.

    *note that bacause of timestamp rounding due to a likely change of track timebase, the timestamps may not be identical.