不是所有的mp4文件都可以用video标签播放
kelvin 发布于 2021-08-23

HTML5中的video标签可以播放视频,支持.mp4,.ogg,.webm等格式。一开始以为只要是mp4的就可以播放,但是测试过程中发现有些mp4格式的文件无法播放,

使用Bento工具查看了文件信息

File:
  major brand:      isom
  minor version:    200
  compatible brand: isom
  compatible brand: iso2
  compatible brand: mp41
  fast start:       no

Movie:
  duration:   13920 (media timescale units)
  duration:   13920 (ms)
  time scale: 1000
  fragments:  no

Found 1 Tracks
Track 1:
  flags:        3 ENABLED IN-MOVIE
  id:           1
  type:         Video
  duration: 13920 ms
  language: und
  media:
    sample count: 348
    timescale:    12800
    duration:     178176 (media timescale units)
    duration:     13920 (ms)
    bitrate (computed): 4957.511 Kbps
  display width:  640.000000
  display height: 480.000000
  frame rate (computed): 25.000
  Sample Description 0
    Coding:       mp4v (MPEG-4 Video)
    Codec String: mp4v
    Stream Type: Visual
    Object Type: MPEG-4 Video
    Max Bitrate: 5000000
    Avg Bitrate: 4957510
    Buffer Size: 0
    Width:       640
    Height:      480
    Depth:       24

看了Codec为 mp4v (MPEG-4 Video),再对比下可以正常播放的一个mp4的文件信息,使用的是avc1 (H.264),像微信视频拍摄后的mp4文件信息就是下面这种

File:
  major brand:      mp42
  minor version:    0
  compatible brand: mp42
  compatible brand: isom
  fast start:       yes

Movie:
  duration:   328097 (media timescale units)
  duration:   3646 (ms)
  time scale: 90000
  fragments:  no

Found 2 Tracks
Track 1:
  flags:        1 ENABLED
  id:           1
  type:         Audio
  duration: 3645 ms
  language: und
  media:
    sample count: 157
    timescale:    44100
    duration:     160768 (media timescale units)
    duration:     3646 (ms)
    bitrate (computed): 64.450 Kbps
  Sample Description 0
    Coding:       mp4a (MPEG-4 Audio)
    Codec String: mp4a.40.2
    Stream Type: Audio
    Object Type: MPEG-4 Audio
    Max Bitrate: 66992
    Avg Bitrate: 64459
    Buffer Size: 254
    MPEG-4 Audio Object Type: 2 (AAC Low Complexity)
    MPEG-4 Audio Decoder Config:
      Sampling Frequency: 44100
      Channels: 1
    Sample Rate: 44100
    Sample Size: 16
    Channels:    2
Track 2:
  flags:        1 ENABLED
  id:           2
  type:         Video
  duration: 3576 ms
  language: und
  media:
    sample count: 72
    timescale:    90000
    duration:     321869 (media timescale units)
    duration:     3576 (ms)
    bitrate (computed): 1249.754 Kbps
  display width:  480.000000
  display height: 960.000000
  frame rate (computed): 20.132
  Sample Description 0
    Coding:       avc1 (H.264)
    Codec String: avc1.64001F
    AVC Profile:          100 (High)
    AVC Profile Compat:   0
    AVC Level:            31
    AVC NALU Length Size: 4
    AVC SPS: [6764001facd20781e6948283030368509a80]
    AVC PPS: [68ee06e0c0]
    Width:       480
    Height:      960
    Depth:       24
kelvin
关注 私信
文章
92
关注
0
粉丝
0