bash 使用 FFmpeg 将视频分割成等长的片段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41576298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:36:15  来源:igfitidea点击:

Use FFmpeg to split a video into equal-length segments

bashvideosplitffmpeg

提问by amateur3057

I need to split many videos of unknown length into 2-minute chunks. I can use the accepted answer from https://unix.stackexchange.com/questions/1670/how-can-i-use-ffmpeg-to-split-mpeg-video-into-10-minute-chunksto do this, but this would require copying, pasting, and modifying many lines and manually calculating how many 2-minute parts are in each video (not a big deal for a few videos, but after a while it gets really tedious).

我需要将许多未知长度的视频分成 2 分钟的块。我可以使用https://unix.stackexchange.com/questions/1670/how-can-i-use-ffmpeg-to-split-mpeg-video-into-10-minute-chunks 中接受的答案来做到这一点,但这需要复制、粘贴和修改多行,并手动计算每个视频中有多少 2 分钟的部分(对于一些视频来说没什么大不了的,但一段时间后会变得非常乏味)。

I have used code in the past in which all I have to do is specify the input video, the start time, segment length, and the output name and by running it in a .sh file in the same folder as the input video it generates all the necessary separate videos which are labeled "output_video01," "output_video02," etc. However, somehow it doesn't want to work on my new computer. Other answers which claim to be able to do this don't work for me, either (when run as either a .bat or .sh file). I believe the code I previously used was:

我过去使用过代码,其中我所要做的就是指定输入视频、开始时间、片段长度和输出名称,然后在与它生成的输入视频相同的文件夹中的 .sh 文件中运行它标记为“output_video01”、“output_video02”等的所有必要的单独视频。但是,不知何故,它不想在我的新计算机上运行。其他声称能够做到这一点的答案对我来说也不起作用(当作为 .bat 或 .sh 文件运行时)。我相信我以前使用的代码是:

ffmpeg -i "input_video.MTS" -ss 164 -f segment -segment_time 120 -vcodec copy -reset_timestamps 1 -map 0:0 -an output_video%d.MTS

Another suggestion that doesn't work for me but apparently works for others (see https://superuser.com/a/820773/313829):

另一个对我不起作用但显然适用于其他人的建议(参见https://superuser.com/a/820773/313829):

ffmpeg -i input_video.MTS -c copy -map 0 -segment_time 8 -f segment output_video%03d.MTS

I currently have Windows 10 with the anniversary update build in which I have enabled Bash, but for some reason it doesn't want to work. I can't even see the error it gives me because the window closes so abruptly.

我目前拥有带有周年更新版本的 Windows 10,我在其中启用了 Bash,但由于某种原因它不想工作。我什至看不到它给我的错误,因为窗口突然关闭。

回答by amateur3057

The original code (that didn't work for me) was:

原始代码(对我不起作用)是:

ffmpeg -i input_video.MTS -c copy -map 0 -segment_time 8 -f segment output_video%03d.MTS

The code that did end up working for me:

最终对我有用的代码:

ffmpeg -i input_video.MTS -c copy -map 0 -segment_time 8 -f segment output_video%%03d.MTS

The "%" needed to be "%%". Also, it worked in a .bat file (not .sh).

“%”必须是“%%”。此外,它在 .bat 文件(不是 .sh)中工作。