5种方式判断mp4的moov的位置

1. 目标

判断mp4视频中 moov box 的位置,在数据流的前面还是后面

2. 配置验证视频

sample.mp4
ffmpeg -i sample.mp4 -c copy -movflags faststart sample_faststart.mp4

3. 通过ffmpeg来分析判断

sample.mp4

# ffmpeg -v trace -i sample.mp4 2>&1 | grep -e type:\'mdat\' -e type:\'moov\'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x59e1b80] type:'mdat' parent:'root' sz: 231297797 48 231901466
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x59e1b80] type:'moov' parent:'root' sz: 603629 231297845 231901466

sample_faststart.mp4

# ffmpeg -v trace -i sample_faststart.mp4 2>&1 | grep -e type:\'mdat\' -e type:\'moov\'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x54d3b80] type:'moov' parent:'root' sz: 603629 40 231901466
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x54d3b80] type:'mdat' parent:'root' sz: 231297797 603677 231901466

参考:https://stackoverflow.com/questions/56963790/how-to-tell-if-faststart-for-video-is-set-using-ffmpeg-or-ffprobe (支持Windows分析)

4. 通过 python3 的 pymediainfo 模块分析

注意:不支持python10
参考:https://pypi.org/project/pymediainfo/
代码:

from pymediainfo import MediaInfo
media_info = MediaInfo.parse('sample_faststart.mp4')
data = media_info.to_json()
print(data)

结果:
分析 “isstreamable”: “Yes”, 字段即可

{
    "tracks": [
        {
            "track_type": "General",
            "count": "331",
            "count_of_stream_of_this_kind": "1",
            "kind_of_stream": "General",
            "other_kind_of_stream": [
                "General"
            ],
            "stream_identifier": "0",
            "count_of_video_streams": "1",
            "count_of_audio_streams": "1",
            "video_format_list": "AVC",
            "video_format_withhint_list": "AVC",
            "codecs_video": "AVC",
            "audio_format_list": "AAC LC",
            "audio_format_withhint_list": "AAC LC",
            "audio_codecs": "AAC LC",
            "complete_name": "sample_faststart.mp4",
            "file_name_extension": "sample_faststart.mp4",
            "file_name": "sample_faststart",
            "file_extension": "mp4",
            "format": "MPEG-4",
            "other_format": [
                "MPEG-4"
            ],
            "format_extensions_usually_used": "braw mov mp4 m4v m4a m4b m4p m4r 3ga 3gpa 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma ismt f4a f4b f4v",
            "commercial_name": "MPEG-4",
            "format_profile": "Base Media",
            "internet_media_type": "video/mp4",
            "codec_id": "isom",
            "codec_id_url": "http://www.apple.com/quicktime/download/standalone.html",
            "codecid_compatible": "isom/iso2/avc1/mp41",
            "file_size": 521597,
            "duration": 12026,
            "overall_bit_rate": 346980,
            "frame_rate": "0.919",
            "other_frame_rate": [
                "0.919 FPS"
            ],
            "frame_count": "11",
            "stream_size": 3793,
            "proportion_of_this_stream": "0.00727",
            "headersize": "3785",
            "datasize": "517812",
            "footersize": "0",
            "isstreamable": "Yes",
            "file_last_modification_date": "UTC 2022-11-08 14:30:43",
            "file_last_modification_date__local": "2022-11-08 22:30:43",
            "writing_application": "Lavf58.29.100",
            "other_writing_application": [
                "Lavf58.29.100"
            ]
        }
    ]
}

可以参考 https://www.freesion.com/article/68961237864/

5. 通过 AtomicParsley 分析

https://atomicparsley.sourceforge.net/ 多年未维护,可以到github上找最新的模块做验证
测试示例:执行 AtomicParsley input.mp4 -T
参考:https://superuser.com/questions/559372/using-ffmpeg-to-locate-moov-atom

6. 通过 qtfaststart 分析

参考:https://superuser.com/questions/559372/using-ffmpeg-to-locate-moov-atom

$ qtfaststart -l bad.mp4
ftyp (32 bytes)
free (8 bytes)
mdat (559619 bytes)
moov (52916 bytes)
$ qtfaststart -l good.mp4
ftyp (32 bytes)
moov (52916 bytes)
mdat (559619 bytes)
$

7. 通过 mp4info 分析

安装:https://github.com/axiomatic-systems/Bento4
macos安装:https://formulae.brew.sh/formula/bento4 brew install bento4

参考:https://superuser.com/questions/559372/using-ffmpeg-to-locate-moov-atom

$ mp4info infile.m4a
File:
  major brand:      isom
  minor version:    200
  compatible brand: isom
  compatible brand: iso2
  compatible brand: mp41
  fast start:       no

$ mp4info outfile.m4a
File:
  major brand:      isom
  minor version:    200
  compatible brand: isom
  compatible brand: iso2
  compatible brand: mp41
  fast start:       yes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值