• 如何判断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
    
    • 1
    • 2
    • 3

    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
    
    • 1
    • 2
    • 3

    参考: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)
    
    • 1
    • 2
    • 3
    • 4

    结果:
    分析 “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"
                ]
            }
        ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    可以参考 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)
    $
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
  • 相关阅读:
    【信号处理】基于蚁群优化随机共振检测附matlab代码
    测试工程师如何做到初级测试管理(个人思考)?
    【愚公系列】2022年09月 微信小程序-WebGL纹理材质的使用
    代码+视频,R语言如何从可信区间推断P值
    HTML5期末考核大作业网站——卫生与健康HTML+CSS+JavaScript
    【视觉基础篇】14 # 如何使用片元着色器进行几何造型?
    Web前端大作业:基于bootstrap响应式页面,家具装修公司网站
    【树莓派触摸屏等学习笔记】
    Java学习笔记——序列化
    【论文阅读】社交网络传播最大化问题-04
  • 原文地址:https://blog.csdn.net/ternence_hsu/article/details/127760595