且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-12 17:35:28

只使用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