使用ffmpeg,根据开始和结束时间切换视频 [英] Cutting the videos based on start and end time using ffmpeg

查看:4800
本文介绍了使用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

通过使用上述命令,我想将视频从 00:00:03 切换到 00:00:08 。但是,这不是在这些时间之间切割视频,而是在11秒钟之内剪辑视频。任何人都可以帮我解决这个问题吗?

By using the above command i want to cut the video from 00:00:03 to 00:00:08. But it is not cutting the video between those times instead of that it is cutting the video with first 11 seconds. can anyone help me how resolve this?

编辑1:

尝试使用 mark4o 建议的以下命令切割

I have tried to cut by using the following command which is suggested by mark4o

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

但显示以下错误。

编码器'aac'是实验性的,但实验编解码器未启用

the encoder 'aac' is experimental but experimental codecs are not enabled

所以我添加了 -strict -2 进入命令ie,

so i added the -strict -2 into the command i.e.,

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 -strict -2 cut.mp4

现在运行正常。

推荐答案

您可能没有3秒的关键帧。因为非关键帧编码与其他帧的差异,所以它们需要从先前的关键帧开始的所有数据。

You probably do not have a keyframe at the 3 second mark. Because non-keyframes encode differences from other frames, they require all of the data starting with the previous keyframe.

使用mp4容器,关键帧,无需使用编辑列表进行重新编码。换句话说,如果3s之前的最接近的关键帧是0s,那么它将从0开始复制视频,并使用编辑列表来告诉玩家开始播放3秒。

With the mp4 container it is possible to cut at a non-keyframe without re-encoding using an edit list. 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.

如果您使用的是git master中的最新的ffmpeg ,那么使用编辑列表将会使用您使用的命令提供。如果这不适合您,那么您可能使用的是旧版本的ffmpeg,或者您的播放器不支持编辑列表。有些玩家将忽略编辑列表,并始终从头到尾播放文件中的所有媒体。

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. 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. Some players will ignore the edit list and always play all of the media in the file from beginning to end.

如果要精确地从非关键帧开始切割,希望它从不支持编辑列表的播放器上的所需点开始播放,或者想要确保剪切部分实际上不在输出文件中(例如,如果它包含机密信息),那么可以通过重新编码,以便在所需的开始时间精确地存在关键帧。如果您不指定 copy ,则重新编码是默认值。例如:

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 copy. For example:

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

当重新编码时,您还可能希望包含其他与质量相关的选项或特定AAC编码器。有关详细信息,请参阅ffmpeg的 x264编码指南视频和 AAC编码指南用于音频。

When re-encoding you may also wish to include additional quality-related options or a particular AAC encoder. For details, see ffmpeg's x264 Encoding Guide for video and AAC Encoding Guide for audio.

另外, -t 选项指定持续时间,而不是结束时间。上述命令将编码8s的视频,从3s开始。从3s开始,在8s结束,使用 -t 5 。如果您正在使用当前版本的ffmpeg,您还可以在上述命令中将 -t 替换为 -to 以结束在指定的时间。

Also, the -t option specifies a duration, not an end time. The above command will encode 8s of video starting at 3s. To start at 3s and end at 8s use -t 5. If you are using a current version of ffmpeg you can also replace -t with -to in the above command to end at the specified time.

这篇关于使用ffmpeg,根据开始和结束时间切换视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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