如何以编程方式判断视频文件是否仅限音频

时间:2014-10-18 21:06:41

标签: python ffmpeg

拍摄以下两个视频文件,每个两分钟:

1)仅音频:https://s3-us-west-1.amazonaws.com/premiere-avails/out__04d05853-c7a6-4a22-8be9-04feb38032f5__WB-APERFECTMURDER-CAS-HD-16X9FF-FIX.mov

2)音频和视频:https://s3-us-west-1.amazonaws.com/premiere-avails/out__04f259dc-14ad-44ae-98b5-745c4a6ba9de__STYLE_RUBY_209.mov

如何编写命令告诉我视频文件是否有视频轨道?例如:

cmd = shlex.split('ffprobe -i %s' % video_path)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = p.communicate()[1]
if 'something' in ouput: # ?
    audio_only = True
else:
    audio_only = False

1 个答案:

答案 0 :(得分:0)

只需使用ffmpeg,在输出中你可以看到所有的流,而不是你可以使用正则表达式来查找视频流和条件。

import re 
videostream=re.compile( r"Stream #\d*\:\d*\s*Video")
cmd = shlex.split('ffmpeg -i %s' % video_path) 
p = subprocess.Popen(cmd,     stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
output = p.communicate()[1] 
if not videostream.match(output): # !
    audio_only = True 
else: audio_only = False