如何以编程方式确定视频文件是否仅音频

问题描述:

获取以下两个视频文件,每两分钟一次:

Take the following two video files, each two minutes long:

1)仅音频: 2)音频和视频:我如何编写命令来告诉我视频文件中是否有视频轨道?例如:

How would I write a command to tell me if the video file has a video track? For example:

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

只使用ffmpeg,在输出中您可以看到所有流,然后可以使用正则表达式查找视频流并对其进行调节.

Just use ffmpeg, in the output you can see all the streams and than you can use regex to find video stream and condition on it.

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