如何以编程方式确定视频文件是否仅音频 [英] How to programmatically tell if a video file is audio-only
本文介绍了如何以编程方式确定视频文件是否仅音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取以下两个视频文件,每两分钟一次:
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
这篇关于如何以编程方式确定视频文件是否仅音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文