在特定时间将关键帧插入m4v/mp4 [英] Insert keyframe into m4v/mp4 at specific times

查看:107
本文介绍了在特定时间将关键帧插入m4v/mp4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于教育者的程序(用electronjs框架编写),该程序可以播放视频,并跳至伴随JSON文件中定义的视频中的预设点.有时,跳过后会出现明显的延迟,并且此答案表明存在延迟是因为关键帧不常见.

假设这是正确的,我想在mp4文件的确切位置插入关键帧,我知道播放器会跳到该关键点.但是,其中一些视频文件已经很大,因此我不想减小关键帧间隔,从而使文件更大.我只需要在整个文件中强制几个关键帧即可.

我希望能够将要强制关键帧的时间传递给参数(例如,传递给ffmpeg).最好是,我不想重新编码整个视频(就像这个未回答的问题)那样,但是如果我必须重新编码视频,我也可以做到.

解决方案

您可以使用ffmpeg使用-force_key_frames选项在关键帧中插入关键帧.

例如:

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

将把关键帧尽可能地靠近5和10s标记.时间值可以采用hh:mm:ss格式,也可以仅为秒(单个值,无冒号).

您可以使用以下方法检查是否在需要的位置插入了帧:

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

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.

解决方案

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

这篇关于在特定时间将关键帧插入m4v/mp4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆