python - How to programmatically tell if a video file is audio-only -
take next 2 video files, each 2 minutes long:
1) sound only: https://s3-us-west-1.amazonaws.com/premiere-avails/out__04d05853-c7a6-4a22-8be9-04feb38032f5__wb-aperfectmurder-cas-hd-16x9ff-fix.mov
2) sound , video: https://s3-us-west-1.amazonaws.com/premiere-avails/out__04f259dc-14ad-44ae-98b5-745c4a6ba9de__style_ruby_209.mov
how write command tell me if video file has video track? 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
just utilize ffmpeg, in output can see streams , can utilize regex find video stream , status 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
python ffmpeg
No comments:
Post a Comment