我正在尝试连接几个.mp4文件。我首先创建中间.mpg剪辑,然后用'cat'命令将它们合并在一起;然后将其转换为.mp4文件
例如,
ffmpeg -i input1.mp4 -qscale:v 1 intermediate1.mpg
ffmpeg -i input2.mp4 -qscale:v 1 intermediate2.mpg
//现在将它们合并在一起
cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg
ffmpeg -i intermediate_all.mpg -qscale:v 2 output.mp4
现在,我想合并目录中的所有.mpg文件 如果我有最多9个.mpg文件
,则以下命令有效cat folder/*.mpg > intermediate_all.mpg
但是,如果我有超过9个.mpg文件,那么电影序列会中断,这意味着没有。否则显示10个剪辑。 1张我不想要的剪辑。我可以使用ffmpeg遵循任何命名约定。在imagemagick中,我可以轻松使用以下语法并且它可以工作,但在ffmpeg中它不起作用。
cat folder/%d.mpg or cat folder/%d.mpg[0-10]
答案 0 :(得分:0)
不确定。创建中间文件时,请按以下方式填充数字:
ffmpeg -i input1.mp4 -qscale:v 1 intermediate01.mpg
ffmpeg -i input2.mp4 -qscale:v 1 intermediate02.mpg
然后当你执行cat *.mpg
时,它会以正确的顺序拾取它们。如果您使用循环来制作中间文件,请使用printf
对这些数字进行零填充:
#!/bin/bash
for i in {1..20}; do
inname=input${i}.mp4
outname=$(printf "intermediate%03d.mpg" $i)
echo Converting "$inname" to "$outname"
ffmpeg -i "$inname" -qscale:v 1 "$outname"
done
<强>输出强>
Converting input1.mp4 to intermediate001.mpg
ffmpeg -i input1.mp4 -qscale:v 1 intermediate001.mpg
Converting input2.mp4 to intermediate002.mpg
ffmpeg -i input2.mp4 -qscale:v 1 intermediate002.mpg
Converting input3.mp4 to intermediate003.mpg
ffmpeg -i input3.mp4 -qscale:v 1 intermediate003.mpg
Converting input4.mp4 to intermediate004.mpg
ffmpeg -i input4.mp4 -qscale:v 1 intermediate004.mpg
Converting input5.mp4 to intermediate005.mpg
ffmpeg -i input5.mp4 -qscale:v 1 intermediate005.mpg
Converting input6.mp4 to intermediate006.mpg
ffmpeg -i input6.mp4 -qscale:v 1 intermediate006.mpg
Converting input7.mp4 to intermediate007.mpg
ffmpeg -i input7.mp4 -qscale:v 1 intermediate007.mpg
Converting input8.mp4 to intermediate008.mpg
ffmpeg -i input8.mp4 -qscale:v 1 intermediate008.mpg
Converting input9.mp4 to intermediate009.mpg
ffmpeg -i input9.mp4 -qscale:v 1 intermediate009.mpg
Converting input10.mp4 to intermediate010.mpg
ffmpeg -i input10.mp4 -qscale:v 1 intermediate010.mpg
Converting input11.mp4 to intermediate011.mpg
ffmpeg -i input11.mp4 -qscale:v 1 intermediate011.mpg
Converting input12.mp4 to intermediate012.mpg
ffmpeg -i input12.mp4 -qscale:v 1 intermediate012.mpg
Converting input13.mp4 to intermediate013.mpg
ffmpeg -i input13.mp4 -qscale:v 1 intermediate013.mpg
Converting input14.mp4 to intermediate014.mpg
ffmpeg -i input14.mp4 -qscale:v 1 intermediate014.mpg
Converting input15.mp4 to intermediate015.mpg
ffmpeg -i input15.mp4 -qscale:v 1 intermediate015.mpg
Converting input16.mp4 to intermediate016.mpg
ffmpeg -i input16.mp4 -qscale:v 1 intermediate016.mpg
Converting input17.mp4 to intermediate017.mpg
ffmpeg -i input17.mp4 -qscale:v 1 intermediate017.mpg
Converting input18.mp4 to intermediate018.mpg
ffmpeg -i input18.mp4 -qscale:v 1 intermediate018.mpg
Converting input19.mp4 to intermediate019.mpg
ffmpeg -i input19.mp4 -qscale:v 1 intermediate019.mpg
Converting input20.mp4 to intermediate020.mpg
ffmpeg -i input20.mp4 -qscale:v 1 intermediate020.mpg
答案 1 :(得分:0)
这是我刚刚使用PHP作为脚本语言制作的解决方案。我们可以使用PHP的自然顺序算法。
$line = '';
$files = glob($location . "/*.mpg");
natsort($files);
foreach ($files as $filename)
{
$line .= " " . $filename;
}
$command = "cat $line > $location/intermediate_all.mpg";
exec($command);