Insert keyframe into m4v/mp4 at specific times

試著忘記壹切 提交于 2020-01-16 08:45:26

问题


I have a program for educators (written with electronjs framework) that plays videos, skipping to preset points in the video as defined in a companion JSON file. Sometimes there is a significant lag after a skip, and this answer suggests that the lag is there because of infrequent keyframes.

Assuming this is correct, I would like to insert keyframes at exact points in the mp4 file where I know the player will skip to. However, some of these video files are already quite large, so I do not want to decrease the keyframe interval, thereby making the files even larger. I only need to force a handful of keyframes in the entire file.

I would like to be able to pass an argument (to ffmpeg, for example) with the times at which I want to force keyframes. Preferably, I would like to do this without re-encoding the entire video (just like this unanswered question), but if I have to reencode the video, I could do that too.


回答1:


You can use ffmpeg to insert keyframes where you want them using the -force_key_frames option.

eg:

./ffmpeg -i input.mp4 -c:a copy -c:v copy -force_key_frames 0:05:00,0:10:00 out.mp4

will put a keyframe as close to the 5 and 10s mark as it can. The time values can be in hh:mm:ss format, or just seconds (single values, no colons).

You can check if there are frames inserted where you want them using:

./ffprobe -select_streams v:0 -skip_frame nokey -show_entries frame=pkt_pts_time out.mp4


来源:https://stackoverflow.com/questions/51995276/insert-keyframe-into-m4v-mp4-at-specific-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!