当用户上传视频时,我会制作2种尺寸。早些时候,我这样做分两步,如下面的
第一尺寸:
ffmpeg -i in.mp4 -filter:v "scale=iw*min(1170/iw\,300/ih):ih*min(1170/iw\,300/ih), pad=1170:300:(1170-iw*min(1170/iw\,300/ih))/2:(300-ih*min(1170/iw\,300/ih))/2" out.mp4
第二尺寸:
ffmpeg -i in.mp4 -filter:v "scale=iw*min(365/iw\,172/ih):ih*min(365/iw\,172/ih), pad=365:172:(365-iw*min(365/iw\,172/ih))/2:(172-ih*min(365/iw\,172/ih))/2" out1.mp4
但是现在为了缩短处理时间,我想将这两个步骤合二为一。我已阅读https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs并发出以下命令
ffmpeg -i in.mp4 -filter:v "scale=iw*min(1170/iw\,300/ih):ih*min(1170/iw\,300/ih), pad=1170:300:(1170-iw*min(1170/iw\,300/ih))/2:(300-ih*min(1170/iw\,300/ih))/2" bigVideo.mp4 \ -filter:v "scale=iw*min(365/iw\,172/ih):ih*min(365/iw\,172/ih), pad=365:172:(365-iw*min(365/iw\,172/ih))/2:(172-ih*min(365/iw\,172/ih))/2" smallVideo.mp4
但它出现以下错误
[NULL @ 0xaee5440]无法为'找到合适的输出格式 - 筛选:V' -filter:v:参数无效
所以有人可以建议我如何解决它吗?
答案 0 :(得分:0)
我尝试使用以下脚本运行这两个命令:
#!/bin/bash
for cmd in "$@"; do {
echo "Process \"$cmd\" started";
$cmd & pid=$!
PID_LIST+=" $pid";
} done
trap "kill $PID_LIST" SIGINT
echo "Parallel processes have started";
wait $PID_LIST
echo
echo "All processes have completed";
您可以将其另存为filename.sh并生成可执行文件。之后你需要传递两个或多个命令作为参数,例如我运行:
./filename.sh "ffmpeg -i input.mp4 -s 720x480 output1.mp4" "ffmpeg -i input.mp4 -s 1170x480 output2.mp4"
你的命令对我来说有点复杂,所以我尝试使用并行脚本运行简单的命令。