是否有可能在 ffmpeg 命令中引发错误?

is it possible to raise error in ffmpeg commands?

我正在尝试创建平移效果,但是对于某些图像它给出了一个错误 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 命令中出现任何错误,那么在 except 中的命令应该 运行.

我已经在answers贴出解决方法了

我的问题的解决方案是-

    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)