上传到OSS的视频有的可以在线播放,有的只有声音没有画面。使用AnalysisVideos工具可以帮助您分析哪些浏览器支持在线播放,并查找播放异常的原因。
说明 使用AnalysisVideos工具前需要安装ffprobe3库。安装命令为如下。
sudo pip install ffprobe3
使用方法
正常结果:
sudo python AnalysisVideos.py test.mp4
[INFO:] Stream: 1
[INFO:] Frame Rate:30.0
[INFO:] Frame Size:(854, 480)
[INFO:] Duration:116.5
[INFO:] Frames:3495
[INFO:] Is video: True
[INFO:] video encode:h264
[CheckResult:]Chrom can playing video
[INFO:] Stream: 2
[INFO:] Duration:116.561
[INFO:] Frames:5465
[INFO:] Is audio: True
[INFO:] audio encode:aac
[CheckResult:]Chrom and FireFox can playing audio
异常情况:请参考报错信息。
源码
#!/usr/bin/env python
#-*- coding:utf8 -*-
#Author: hanli
#Update: 2018-09-24
from __future__ import print_function
import os
import sys
import subprocess
from ffprobe3 import FFProbe
from ffprobe3.exceptions import FFProbeError
class MainFun():
'''
color
'''
def __init__(self):
self.left = '\033[1;31;40m'
self.gren = '\033[1;32;40m'
self.right = '\033[0m'
self.videos = sys.argv[1]
def CheckModule(self):
try:
from ffprobe3 import FFProbe
from ffprobe3.exceptions import FFProbeError
except:
self.ConsoleLog("Not install ffprobe3, please do 'pip install ffprobe3'","warn")
return True
'''
checkvideo valid
'''
def CheckVideo(self):
try:
media = FFProbe(self.videos)
for index, stream in enumerate(media.streams, 1):
self.ConsoleLog('\tStream: {0}'.format(index))
try:
if stream.is_video():
frame_rate = stream.frames() / stream.duration_seconds()
self.ConsoleLog('\t\tFrame Rate:{0}'.format(frame_rate))
self.ConsoleLog('\t\tFrame Size:{0}'.format(stream.frame_size()))
self.ConsoleLog('\t\tDuration:{0}'.format(stream.duration_seconds()))
self.ConsoleLog('\t\tFrames:{0}'.format(stream.frames()))
if stream.is_video():
self.ConsoleLog('\t\tIs video: True')
self.ConsoleLog('\t\tvideo encode:{0}'.format(stream.codec()))
self.CheckResult(stream.codec(),"video")
if stream.is_audio():
self.ConsoleLog('\t\tIs audio: True')
self.ConsoleLog('\t\taudio encode:{0}'.format(stream.codec()))
self.CheckResult(stream.codec(),"audio")
except FFProbeError as e:
self.ConsoleLog(e,"warn")
except Exception as e:
self.ConsoleLog(e,"warn")
return True
except Exception as e:
self.ConsoleLog(e,"warn")
'''
check result
'''
def CheckResult(self,codec,types=None):
if types == 'video':
if codec.lower() in ['h264','h265','h263','vp9','vp8','theora']:
self.ConsoleLog("Chrom can playing video","result")
elif codec.lower() in ['h264','theora']:
self.ConsoleLog("FireFox and Safari can playing video","result")
else:
self.ConsoleLog("Chrom and FireFox not Support video encode type {0}".format(codec),"exec")
if types == 'audio':
if codec.lower() in ['vorbis','wmv','aac','mp3']:
self.ConsoleLog("Chrom and FireFox can playing audio","result")
else:
self.ConsoleLog("Chrom FireFox and Safari not Support audio encode type {0}".format(codec),"exec")
'''
output log
'''
def ConsoleLog(self,level,tag=None):
if tag == "warn":
sys.exit("{0}[ERROR:]{1}{2}".format(self.left,self.right,level))
elif tag == "result":
print("{0}[CheckResult:]{1}{2}".format(self.gren,self.right,level))
if tag == "exce":
print("{0}[ERROR:]{1}{2}".format(self.left,self.right,level))
else:
print("[INFO:]{2}".format(self.gren,self.right,level))
'''
Main input
'''
if __name__ == '__main__':
if MainFun().CheckModule():
if MainFun().CheckVideo() == None:
sys.exit('\033[1;31;40m[ERROR:]\033[0mInput file is not video file')