def get_media_info(self, media_file):
try:
ffprobe = shutil.which('ffprobe')
except Exception:
# python2
from distutils.spawn import find_executable
ffprobe = find_executable('ffprobe')
if ffprobe:
cmd = "ffprobe -v error -select_streams v -show_entries stream=width,height,avg_frame_rate,duration -of default=noprint_wrappers=1 -print_format json %s" % media_file
result = subprocess.check_output(cmd.split(' '), universal_newlines=True)
vjres = json.loads(result)['streams'][0]
if not vjres.get('duration'):
cmd = "ffprobe -v error -select_streams v -show_format_entry duration -of default=noprint_wrappers=1 -print_format json %s" % media_file
result = subprocess.check_output(cmd.split(' '), universal_newlines=True)
vjres['duration'] = json.loads(result)['format']['duration']
cmd = "ffprobe -v error -select_streams a -show_entries stream=sample_rate -of default=noprint_wrappers=1 -print_format json %s" % media_file
result = subprocess.check_output(cmd.split(' '), universal_newlines=True)
ajres = json.loads(result)['streams'][0]
vjres['sample_rate'] = ajres['sample_rate']
return vjres
else:
logger.error('ffprobe is required')
sys.exit()
评论列表
文章目录