本文翻译自:Cutting the videos based on start and end time using ffmpeg I tried to cut the video using the start and end time of the video by using the following command 我尝试通过使用以下命令使用视频的开始和结束时间剪切视频 ffmpeg -ss 00:00:03 -t 00:00:08 -i movie.mp4 -acodec copy -vcodec copy -async 1 cut.mp4 By using the above command i want to cut the video from Edit 1: 编辑1: I have tried to cut by using the following command which is suggested by mark4o 我试图通过使用mark4o建议的以下命令进行剪切 But it was shown the following error. 但是显示以下错误。 the encoder 'aac' is experimental but experimental codecs are not enabled 编码器“ aac”是实验性的,但未启用实验性编解码器 so i added the ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 -strict -2 cut.mp4 Now it is working fine. 现在工作正常。 #1楼参考:https:///question/1FOB0/使用ffmpeg根据开始和结束时间剪切视频 #2楼You probably do not have a keyframe at the 3 second mark. 您可能在3秒标记处没有关键帧。 Because non-keyframes encode differences from other frames, they require all of the data starting with the previous keyframe. 由于非关键帧编码与其他帧的差异,因此它们需要从前一个关键帧开始的所有数据。 With the mp4 container it is possible to cut at a non-keyframe without re-encoding using an edit list. 使用mp4容器,可以在非关键帧处进行剪切,而无需使用编辑列表进行重新编码。 In other words, if the closest keyframe before 3s is at 0s then it will copy the video starting at 0s and use an edit list to tell the player to start playing 3 seconds in. 换句话说,如果最接近3s的关键帧位于0s,则它将复制从0s开始的视频,并使用编辑列表告诉播放器开始播放3秒。 If you are using the latest ffmpeg from git master it will do this using an edit list when invoked using the command that you provided. 如果您使用的是git master中的最新ffmpeg ,则在使用提供的命令调用该列表时,将使用编辑列表来执行此操作。 If this is not working for you then you are probably either using an older version of ffmpeg, or your player does not support edit lists. 如果这不适合您,则可能是您使用的是较旧版本的ffmpeg,或者您的播放器不支持编辑列表。 Some players will ignore the edit list and always play all of the media in the file from beginning to end. 一些播放器将忽略编辑列表,并始终从头到尾播放文件中的所有媒体。 If you want to cut precisely starting at a non-keyframe and want it to play starting at the desired point on a player that does not support edit lists, or want to ensure that the cut portion is not actually in the output file (for example if it contains confidential information), then you can do that by re-encoding so that there will be a keyframe precisely at the desired start time. 如果要从非关键帧开始精确剪切,并且希望它在不支持编辑列表的播放器上从所需点开始播放,或者要确保剪切部分实际上不在输出文件中(例如, (如果其中包含机密信息),则可以通过重新编码来实现,这样就可以在所需的开始时间准确显示关键帧。 Re-encoding is the default if you do not specify When re-encoding you may also wish to include additional quality-related options or a particular AAC encoder. 重新编码时,您可能还希望包括其他与质量相关的选项或特定的AAC编码器。 For details, see ffmpeg's x264 Encoding Guide for video and AAC Encoding Guide for audio. 有关详细信息,请参阅ffmpeg的x264视频编码指南和AAC音频编码指南 。 Also, the #3楼 ffmpeg -i movie.mp4 -vf trim=3:8 cut.mp4 将所有内容从秒3减至秒8。 #4楼 Use -c copy for make in instantly. 使用-c复制即可即时制作。 In that case ffmpeg will not re-encode video, just will cut to according size. 在这种情况下,ffmpeg不会重新编码视频,只会切成适当的大小。 #5楼Try using this. 尝试使用这个。 It is the fastest and best ffmpeg-way I have figure it out: 这是我弄清楚的最快最好的ffmpeg方式: ffmpeg -ss 00:01:00 -i input.mp4 -to 00:02:00 -c copy output.mp4 This command trims your video in seconds! 此命令可在几秒钟内修剪您的视频! I have explained it on my blog here : 我已经解释它在我的博客在这里 :
The timing format is: hh:mm:ss 计时格式为: hh:mm:ss Please note that the current highly upvoted answer is outdated and the trim would be extremely slow. 请注意,当前高度评价的答案已过时,修剪将非常慢。 For more information, look at this official ffmpeg article . 有关更多信息,请参见ffmpeg官方文章 。 #6楼To cut based on start and end time from the source video and avoid having to do math, specify the end time as the input option and the start time as the output option. 要基于源视频的开始时间和结束时间进行剪切并避免进行数学运算,请指定结束时间作为输入选项,并指定开始时间作为输出选项。 This will produce a 15 second cut from 0:45 to 1:00. 这将在0:45到1:00之间产生15秒的切换。 This is because when It's slower than seeking since the omitted segment is still processed before being discarded, but this is the only way to do it as far as I know. 这比查找要慢,因为省略的段在丢弃之前仍会进行处理,但是据我所知,这是唯一的方法。 If you're clipping from deep within a large file, it's more prudent to just do the math and use |
|