有可能在ffmpeg命令中引发错误吗



我正在尝试创建平移效果,但对于一些图像,它给出了一个错误Conversion failed!,当该错误发生时,我希望在异常情况下运行命令。

代码在下面-

try:
cmd = "ffmpeg -y -loop 1 -i " + combined_url + " -ss 0 -t 3 " + " -filter_complex" + " '[0:v]scale=w=-2:h=3*720,crop=w=3*1280/1.4:h=3*720/1.4:y=(in_h-out_h)-t*(in_h-out_h)/5:x=t*(in_w-out_w)/5,scale=w=1280:h=720' " + " -c:v h264 -crf 18 -preset veryfast " + vid_out
os.system(cmd)
except:
con_img = os.path.join(BASE_DIR, "media/images/" + filename + "." + image_url.split(".")[-1])
cmd1 = "ffmpeg -i " + combined_url + " -vf scale=1280:720 " + con_img
os.system(cmd1)
cmd = "ffmpeg -y -loop 1 -i " + combined_url + " -ss 0 -t 3 " + " -filter_complex" + " '[0:v]scale=w=-2:h=3*720,crop=w=3*1280/1.4:h=3*720/1.4:y=(in_h-out_h)-t*(in_h-out_h)/5:x=t*(in_w-out_w)/5,scale=w=1280:h=720' " + " -c:v h264 -crf 18 -preset veryfast " + vid_out
os.system(cmd)

所以,我想如果try命令中出现任何错误,那么除应该运行外的命令。

我已经发布了答案中的解决方案。

我的问题的解决方案是-

try:
cmd = "ffmpeg -y -loop 1 -i " + files4 + " -ss 0 -t 3 " + " -filter_complex" + " '[0:v]scale=w=-2:h=3*720, crop=w=3*1280/{}:h=3*720/{}:y=(in_h-out_h)-t*(in_h-out_h)/5:x=(in_w-out_w)-t*(in_w-out_w)/5, scale=w=1280:h=720' ".format(1.4,1.4) + " -c:v h264 -crf 18 -preset veryfast " + files5
if os.system(cmd)!=0:
raise UserWarning
except UserWarning:
files7 = "path"
cmd1 = "ffmpeg -i " + files4 + " -vf scale=1280:720 " + files7
os.system(cmd1)
cmd = "ffmpeg -y -loop 1 -i " + files7 + " -ss 0 -t 3 " + " -filter_complex" + " '[0:v]scale=w=-2:h=3*720,crop=w=3*1280/1.4:h=3*720/1.4:y=(in_h-out_h)-t*(in_h-out_h)/5:x=t*(in_w-out_w)/5,scale=w=1280:h=720' " + " -c:v h264 -crf 18 -preset veryfast " + files5
os.system(cmd)

最新更新