anthwlock / untrunc

Restore a truncated mp4/mov. Improved version of ponchio/untrunc
GNU General Public License v2.0
2k stars 191 forks source link

Missing Movie Header Atom #17

Closed d1ma5 closed 5 years ago

d1ma5 commented 5 years ago

Hello,

I have a truncated mp4 file that i produced using a home brewed powershell script that leverages ffmpeg to record a multicast stream. Script was not able to lay down the last atom moov packet and I now have a 7.3GB file that is not playable. I tried using the windows (x64) exe to read another working mp4 file that was created the same exact way but i keep getting "Missing movie header atom"

What am i doing wrong?

anthwlock commented 5 years ago

Are you sure the first argument is the healthy one? If so what is the output of untrunc -i ok.mp4 and untrunc -f ok.mp4? Please also provide the output of mp4dump.

dagelf commented 1 year ago

I recorded a live even with this:

fmpeg -i 'rtsp://192.168.1.2/?inst=1&enableaudio=1&audio_line=1' -map 0 -c:v libx264 -c:a aac stream.mp4

Computer froze a while after the event. Trying to play it I get "missing moov atom" and trying to repair it with untrunc I get "missing movie header atom".

Mp4dump gives:

[ftyp] size=8+24
  major_brand = isom
  minor_version = 200
  compatible_brand = isom
  compatible_brand = iso2
  compatible_brand = avc1
  compatible_brand = mp41
[free] size=8+0
[mdat] size=8+1327497216

Recording from the same camera, and closing normally, gives:


[aac @ 0x55ca2a716200] Too many bits 8832.000000 > 6144 per frame requested, clamping to max
[libx264 @ 0x55ca2a7131c0] using SAR=4072/3735
[libx264 @ 0x55ca2a7131c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55ca2a7131c0] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 0x55ca2a7131c0] 264 - core 163 r3060 5db6aa6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'stream.mp4':
  Metadata:
    title           : LIVE VIEW
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 704x576 [SAR 4797:4400 DAR 533:400], q=2-31, 25 fps, 12800 tbn
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 48 kb/s
    Metadata:
      encoder         : Lavc58.134.100 aac
frame=    6 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=5 droframe=   44 fps=0.0 q=0.0 size=       0kB time=00:00:01.53 bitrate=   0.2kbits/sframe=   56 fps= 52 q=28.0 size=       0kB time=00:00:02.04 bitrate=   0.2kbits/frame=   70 fps= 44 q=28.0 size=       0kB time=00:00:02.56 bitrate=   0.1kbits/frame=   82 fps= 39 q=28.0 size=       0kB time=00:00:03.07 bitrate=   0.1kbits/frame=   96 fps= 36 q=28.0 size=       0kB time=00:00:03.58 bitrate=   0.1kbits/frame=  108 fps= 34 q=28.0 size=       0kB time=00:00:04.09 bitrate=   0.1kbits/frame=  122 fps= 33 q=28.0 size=     256kB time=00:00:04.60 bitrate= 455.2kbits/frame=  134 fps= 32 q=28.0 size=     256kB time=00:00:05.12 bitrate= 409.7kbits/frame=  148 fps= 31 q=28.0 size=     256kB time=00:00:05.63 bitrate= 372.4kbits/frame=  160 fps= 31 q=28.0 size=     256kB time=00:00:06.15 bitrate= 340.7kbits/frame=  174frame=frame=  699 fps= 26 q=-1.0 Lsize=    2252kB time=00:00:28.04 bitrate= 657.8kbits/s dup=5 drop=0 speed=1.04x    frame=  264 fps= 28 q=28.0 sframe=  278 fps= 28 q=28.0 size=     768kB time=00:00:10.89 bitrate= 577.7kbits/s dup=5 drop=0 speed= 1.1x    op=0 speed=1.13x    
video:2106kB audio:133kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.590729%
[libx264 @ 0x55ca2a7131c0] frame I:5     Avg QP:15.86  size: 17806
[libx264 @ 0x55ca2a7131c0] frame P:183   Avg QP:20.49  size:  6800
[libx264 @ 0x55ca2a7131c0] frame B:511   Avg QP:22.69  size:  1609
[libx264 @ 0x55ca2a7131c0] consecutive B-frames:  2.3%  0.6%  0.4% 96.7%
[libx264 @ 0x55ca2a7131c0] mb I  I16..4: 47.1% 31.2% 21.6%
[libx264 @ 0x55ca2a7131c0] mb P  I16..4:  3.1%  6.3%  0.5%  P16..4: 46.0% 12.3%  5.7%  0.0%  0.0%    skip:26.1%
[libx264 @ 0x55ca2a7131c0] mb B  I16..4:  0.1%  0.0%  0.0%  B16..8: 34.5%  1.7%  0.3%  direct: 3.2%  skip:60.3%  L0:45.1% L1:52.8% BI: 2.1%
[libx264 @ 0x55ca2a7131c0] 8x8 transform intra:56.2% inter:65.4%
[libx264 @ 0x55ca2a7131c0] coded y,uvDC,uvAC intra: 49.8% 44.8% 1.8% inter: 12.0% 10.5% 0.0%
[libx264 @ 0x55ca2a7131c0] i16 v,h,dc,p: 24% 40% 11% 24%
[libx264 @ 0x55ca2a7131c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 30% 26%  3%  4%  3%  7%  2%  7%
[libx264 @ 0x55ca2a7131c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 37% 20%  4%  4%  3%  6%  3%  7%
[libx264 @ 0x55ca2a7131c0] i8c dc,h,v,p: 59% 30% 10%  2%
[libx264 @ 0x55ca2a7131c0] Weighted P-Frames: Y:4.9% UV:0.0%
[libx264 @ 0x55ca2a7131c0] ref P L0: 65.6% 11.3% 17.2%  5.7%  0.2%
[libx264 @ 0x55ca2a7131c0] ref B L0: 95.4%  4.1%  0.5%
[libx264 @ 0x55ca2a7131c0] ref B L1: 98.2%  1.8%
[libx264 @ 0x55ca2a7131c0] kb/s:616.78
[aac @ 0x55ca2a716200] Qavg: 61738.742
Exiting normally, received signal 2.

All the obvious non-movie-buff approaches so far have failed ie .playing with different players, trying to force settings with ffplay and ffmpeg. Any ideas? Will post here if I figure it out.

dagelf commented 1 year ago

mp4dump for the working file:

[ftyp] size=8+24
  major_brand = isom
  minor_version = 200
  compatible_brand = isom
  compatible_brand = iso2
  compatible_brand = avc1
  compatible_brand = mp41
[free] size=8+0
[mdat] size=8+2292422
[moov] size=8+13485
  [mvhd] size=12+96
    timescale = 1000
    duration = 28171
    duration(ms) = 28171
  [trak] size=8+10873
    [tkhd] size=12+80, flags=3
      enabled = 1
      id = 1
      duration = 27960
      width = 767.520020
      height = 576.000000
    [edts] size=8+28
      [elst] size=12+16
        entry_count = 1
        entry/segment duration = 27960
        entry/media time = 1024
        entry/media rate = 1
    [mdia] size=8+10737
      [mdhd] size=12+20
        timescale = 12800
        duration = 357888
        duration(ms) = 27960
        language = und
      [hdlr] size=12+33
        handler_type = vide
        handler_name = VideoHandler
      [minf] size=8+10652
        [vmhd] size=12+8, flags=1
          graphics_mode = 0
          op_color = 0000,0000,0000
        [dinf] size=8+28
          [dref] size=12+16
            [url ] size=12+0, flags=1
              location = [local to file]
        [stbl] size=8+10588
          [stsd] size=12+184
            entry_count = 1
            [avc1] size=8+172
              data_reference_index = 1
              width = 704
              height = 576
              compressor = 
              [avcC] size=8+50
                Configuration Version = 1
                Profile = High
                Profile Compatibility = 0
                Level = 30
                NALU Length Size = 4
                Sequence Parameter = [67 64 00 1e ac d9 40 b0 12 6f fc 3f a0 3a 5c 40 00 00 03 00 40 00 00 0c 83 c5 8b 65 80]
                Picture Parameter = [68 eb e3 cb 22 c0]
              [pasp] size=8+8
              [btrt] size=8+12
          [stts] size=12+12
            entry_count = 1
          [stss] size=12+24
            entry_count = 5
          [ctts] size=12+5540
            entry_count = 692
          [stsc] size=12+1060
            entry_count = 88
          [stsz] size=12+2804
            sample_size = 0
            sample_count = 699
          [stco] size=12+880
            entry_count = 219
  [trak] size=8+2357
    [tkhd] size=12+80, flags=3
      enabled = 1
      id = 2
      duration = 28171
      width = 0.000000
      height = 0.000000
    [edts] size=8+28
      [elst] size=12+16
        entry_count = 1
        entry/segment duration = 28171
        entry/media time = 1024
        entry/media rate = 1
    [mdia] size=8+2221
      [mdhd] size=12+20
        timescale = 8000
        duration = 225368
        duration(ms) = 28171
        language = und
      [hdlr] size=12+33
        handler_type = soun
        handler_name = SoundHandler
      [minf] size=8+2136
        [smhd] size=12+4
          balance = 0
        [dinf] size=8+28
          [dref] size=12+16
            [url ] size=12+0, flags=1
              location = [local to file]
        [stbl] size=8+2076
          [stsd] size=12+114
            entry_count = 1
            [mp4a] size=8+102
              data_reference_index = 1
              channel_count = 2
              sample_size = 16
              sample_rate = 8000
              [esds] size=12+42
                [ESDescriptor] size=5+37
                  es_id = 2
                  stream_priority = 0
                  [DecoderConfig] size=5+23
                    stream_type = 5
                    object_type = 64
                    up_stream = 0
                    buffer_size = 0
                    max_bitrate = 48000
                    avg_bitrate = 38471
                    DecoderSpecificInfo = 15 88 56 e5 00 
                  [Descriptor:06] size=5+1
              [btrt] size=8+12
          [stts] size=12+44
            entry_count = 5
          [stsc] size=12+28
            entry_count = 2
          [stsz] size=12+892
            sample_size = 0
            sample_count = 221
          [stco] size=12+884
            entry_count = 220
          [sgpd] size=12+14, version=1
            grouping_type = roll
            default_length = 2
            entry_count = 1
            entries:
              (       0) [ff ff]
          [sbgp] size=12+16
            grouping_type = roll
            entry_count = 1
  [udta] size=8+123
    [meta] size=12+111
      [hdlr] size=12+21
        handler_type = mdir
        handler_name = 
      [ilst] size=8+70
        [.nam] size=8+25
          [data] size=8+17
            type = 1
            lang = 0
            value = LIVE VIEW
        [.too] size=8+29
          [data] size=8+21
            type = 1
            lang = 0
            value = Lavf58.76.100
dagelf commented 1 year ago

The easiest solution to fix this was running this on wine: https://codecpack.co/download/recover-mp4.html