2

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

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

2) Audio and video: https://s3-us-west-1.amazonaws.com/premiere-avails/out__04f259dc-14ad-44ae-98b5-745c4a6ba9de__STYLE_RUBY_209.mov

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
David542
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

0

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
Kipi
  • 165
  • 2
  • 10