【发布时间】:2019-08-25 17:04:03
【问题描述】:
您好,我正在尝试使用 python 为 django 制作视频转换器,我分叉了 django-ffmpeg 模块,它几乎可以完成我想要的所有操作,除非转换失败时不会捕获错误。
基本上模块将ffmpeg命令传递给命令行界面以进行如下转换:
/usr/bin/ffmpeg -hide_banner -nostats -i %(input_file)s -target 电影-dvd %(output_file)
Module 使用这种方法将 ffmpeg 命令传递给 cli 并获取输出:
def _cli(self, cmd, without_output=False):
print 'cli'
if os.name == 'posix':
import commands
return commands.getoutput(cmd)
else:
import subprocess
if without_output:
DEVNULL = open(os.devnull, 'wb')
subprocess.Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
else:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return p.stdout.read()
但是例如,我上传了一个损坏的视频文件,它只返回打印在 cli 上的 ffmpeg 消息,但没有任何东西触发知道某事失败
这是转换失败时的 ffmpeg 示例输出:
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x237d500] 格式 mov,mp4,m4a,3gp,3g2,mj2 仅以 1 的低分检测,可能误检测! [mov,mp4,m4a,3gp,3g2,mj2 @ 0x237d500] moov atom not found /home/user/PycharmProjects/videotest/media/videos/orig/270f412927f3405aba041265725cdf6b.mp4: 处理输入时发现无效数据
我想知道是否有任何方法可以使它成为异常以及如何处理,以便我可以轻松处理。
我想到的唯一选择是在 cli 输出消息字符串中搜索:“处理输入时发现无效数据”,但我不确定这是否是最佳方法。任何人都可以帮助我并指导我。
【问题讨论】: