免责声明: 本文档可能包含第三方产品信息,该信息仅供参考。阿里云对第三方产品的性能、可靠性以及操作可能带来的潜在影响,不做任何暗示或其他形式的承诺。

 

问题描述

上传到OSS的视频有的可以在线播放,有的只有声音没有画面。

 

问题原因

可能和浏览器兼容有关。

 

解决方案

使用AnalysisVideos工具可以帮助您分析哪些浏览器支持在线播放,并查找播放异常的原因。使用此工具前需要安装ffprobe3库,安装命令如下。根据返回的结果使用兼容该视频的浏览器进行在线播放。

pip install ffprobe3

 

AnalysisVideos工具的使用方法

执行如下命令,进行检查。如有异常情况,请参考报错信息。
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

 

更多信息

AnalysisVideos.py脚本文件源码如下。

#!/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')

 

适用于

  • 对象存储 OSS