ponchio / untrunc

Restore a damaged (truncated) mp4, m4v, mov, 3gp video. Provided you have a similar not broken video.
GNU General Public License v2.0
1.63k stars 229 forks source link

unable to find correct codec -> premature end (~0.0009298%) #260

Open heph2 opened 1 year ago

heph2 commented 1 year ago

Hi! I'm trying to repair an mp4 video (saved as an RSV file from the camera, which is a sony alpha 7s III), but i got those issues:

untrunc -v 20230321_A.B.0323.MP4 badvideo.mp4                                                                           Fri Mar 24 22:01:11 2023
Info: version '' using ffmpeg '4.4.2'
Info: reading 20230321_A.B.0323.MP4
Info: parsing healthy moov atom ... 
Composition time offset atom found. Out of order samples possible.
ftyp_ = 'XAVC'
detected 'XAVC', deactivating 'g_strict_nal_frame_check'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x139811400] st: 0 edit list: 1 Missing key frame while searching for timestamp: 2000
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x139811400] st: 0 edit list 1 Cannot find an index entry before timestamp: 2000.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20230321_A.B.0323.MP4':
  Metadata:
    major_brand     : XAVC
    minor_version   : 17440767
    compatible_brands: XAVCmp42iso2nras
    creation_time   : 2023-03-21T17:01:10.000000Z
  Duration: 00:01:25.44, start: 0.000000, bitrate: 103697 kb/s
  Stream #0:0(und): Video: hevc (Rext) (hvc1 / 0x31637668), yuv422p10le(tv, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 97048 kb/s, 50 fps, 50 tbr, 50k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2023-03-21T17:01:10.000000Z
      handler_name    : Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : HEVC Coding
  Stream #0:1(und): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2023-03-21T17:01:10.000000Z
      handler_name    : Sound Media Handler
      vendor_id       : [0][0][0][0]
  Stream #0:2(und): Data: none (rtmd / 0x646D7472), 4505 kb/s (default)
    Metadata:
      creation_time   : 2023-03-21T17:01:10.000000Z
      handler_name    : Timed Metadata Media Handler
      timecode        : 04:15:03:18
assuming constant duration of 1000 for 'hvc1' (x4272)
assuming constant duration of 1 for 'twos' (x4101120)
assuming constant duration of 1000 for 'rtmd' (x4272)
Info: special track found (meta, 'Timed Metadata Media Handler')

Info: unknown track 'twos' found -> fallback to dynamic stats
created dummy track 'free'
removed dummy track 'free'
first_failed: 0 of 100
order: (2, 48) (0, 48) (1, 46080) 
isTrackOrderEnough: 1  (sz=3)

dynamic stats:
first_off_: 131072
first_off_rel_: 0
hvc1
chunk_distance_gcd_: 1
likely n_samples/chunk (p=1): 48 
likely sample_sizes (p=0): 
n_mutual_patterns: 0

twos
chunk_distance_gcd_: 1
likely n_samples/chunk (p=1): 46080 
likely sample_sizes (p=1): 4 
n_mutual_patterns: 0

rtmd
chunk_distance_gcd_: 1
likely n_samples/chunk (p=1): 48 
likely sample_sizes (p=1): 11264 
n_mutual_patterns: 0

Info: using dynamic stats, use '-is' to see them
calling findMdat on truncated file..
Warning: no mp4-structure found in: 'badvideo.mp4'
Info: using orig_mdat_start_ (=131056)
Info: reading mdat from truncated file ...
Info: using 64-bit offsets for the broken file
won't skip zeros at: 0 / 131064

(reading element from mdat)
Offset: 0 / 131064 : 00000000 00000000
trying chunkPredict first.. 
called getChunkPrediction(0 / 131064) ... 
chunk derived from track_order_:'rtmd' (11264 x48)

(reading element from mdat)
Offset: 540672 / 671736 : 7b406865 0fa8fc40
trying chunkPredict first.. 
called getChunkPrediction(540672 / 671736) ... 
Track codec: hvc1
Track codec: twos
Track codec: rtmd
Error: unable to find correct codec -> premature end (~0.0009298%)
       try '-s' to skip unknown sequences

mdat->file_end: 671736
Info: Found 48 packets ( hvc1: 0 hvc1-keyframes: 0 twos: 0 rtmd: 48 )
first_failed: 0 of 4272
order: (1, 5000) (1, 2000) (1, 0) (1, 1000) 
reduced origt_ctts_: 4272 -> 4
Info: Duration of hvc1:  (0 ms)
Info: Duration of twos:  (0 ms)
Info: Duration of rtmd: 960ms  (960 ms)
Info: pruned empty 'hvc1' track
Info: pruned empty 'twos' track
Info: saving badvideo.mp4_fixed-dyn.MP4

Using the -s flag, works but got only some seconds of the whole video.

ponchio commented 1 year ago

Hi, you are using a different fork, but the problem looks the same:

1) twos is a raw audio codec: there is no header to help guessing where the packet starts and how long it is.

2) rtmd is an unknown codec: I have no idea what it is, but sometimes it can be guessed using packet stats.

Sometimes I was able to manually recover a video, spotting some regularity in the video encoder (the packet has a regular sequence or length, etc.).

You can send me the videos @.***), and I will have a look at them, but the chances of recovering the video are not high...

Federico.

On Fri, Mar 24, 2023 at 11:09 PM heph2 @.***> wrote:

Hi! I'm trying to repair an mp4 video (saved as an RSV file from the camera, which is a sony alpha 7s III), but i got those issues:

untrunc -v 20230321_A.B.0323.MP4 badvideo.mp4 Fri Mar 24 22:01:11 2023 Info: version '' using ffmpeg '4.4.2' Info: reading 20230321A.B.0323.MP4 Info: parsing healthy moov atom ... Composition time offset atom found. Out of order samples possible. ftyp = 'XAVC' detected 'XAVC', deactivating 'g_strict_nal_frame_check' [mov,mp4,m4a,3gp,3g2,mj2 @ 0x139811400] st: 0 edit list: 1 Missing key frame while searching for timestamp: 2000 [mov,mp4,m4a,3gp,3g2,mj2 @ 0x139811400] st: 0 edit list 1 Cannot find an index entry before timestamp: 2000. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20230321_A.B.0323.MP4': Metadata: major_brand : XAVC minor_version : 17440767 compatible_brands: XAVCmp42iso2nras creation_time : 2023-03-21T17:01:10.000000Z Duration: 00:01:25.44, start: 0.000000, bitrate: 103697 kb/s Stream #0:0(und): Video: hevc (Rext) (hvc1 / 0x31637668), yuv422p10le(tv, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 97048 kb/s, 50 fps, 50 tbr, 50k tbn, 50 tbc (default) Metadata: creation_time : 2023-03-21T17:01:10.000000Z handler_name : Video Media Handler vendor_id : [0][0][0][0] encoder : HEVC Coding Stream #0:1(und): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels, s16, 1536 kb/s (default) Metadata: creation_time : 2023-03-21T17:01:10.000000Z handler_name : Sound Media Handler vendor_id : [0][0][0][0] Stream #0:2(und): Data: none (rtmd / 0x646D7472), 4505 kb/s (default) Metadata: creation_time : 2023-03-21T17:01:10.000000Z handler_name : Timed Metadata Media Handler timecode : 04:15:03:18 assuming constant duration of 1000 for 'hvc1' (x4272) assuming constant duration of 1 for 'twos' (x4101120) assuming constant duration of 1000 for 'rtmd' (x4272) Info: special track found (meta, 'Timed Metadata Media Handler')

Info: unknown track 'twos' found -> fallback to dynamic stats created dummy track 'free' removed dummy track 'free' first_failed: 0 of 100 order: (2, 48) (0, 48) (1, 46080) isTrackOrderEnough: 1 (sz=3)

dynamic stats: firstoff: 131072 first_offrel: 0 hvc1 chunk_distancegcd: 1 likely n_samples/chunk (p=1): 48 likely sample_sizes (p=0): n_mutual_patterns: 0

twos chunk_distancegcd: 1 likely n_samples/chunk (p=1): 46080 likely sample_sizes (p=1): 4 n_mutual_patterns: 0

rtmd chunk_distancegcd: 1 likely n_samples/chunk (p=1): 48 likely sample_sizes (p=1): 11264 n_mutual_patterns: 0

Info: using dynamic stats, use '-is' to see them calling findMdat on truncated file.. Warning: no mp4-structure found in: 'badvideo.mp4' Info: using orig_mdatstart (=131056) Info: reading mdat from truncated file ... Info: using 64-bit offsets for the broken file won't skip zeros at: 0 / 131064

(reading element from mdat) Offset: 0 / 131064 : 00000000 00000000 trying chunkPredict first.. called getChunkPrediction(0 / 131064) ... chunk derived from trackorder:'rtmd' (11264 x48)

(reading element from mdat) Offset: 540672 / 671736 : 7b406865 0fa8fc40 trying chunkPredict first.. called getChunkPrediction(540672 / 671736) ... Track codec: hvc1 Track codec: twos Track codec: rtmd Error: unable to find correct codec -> premature end (~0.0009298%) try '-s' to skip unknown sequences

mdat->file_end: 671736 Info: Found 48 packets ( hvc1: 0 hvc1-keyframes: 0 twos: 0 rtmd: 48 ) first_failed: 0 of 4272 order: (1, 5000) (1, 2000) (1, 0) (1, 1000) reduced origtctts: 4272 -> 4 Info: Duration of hvc1: (0 ms) Info: Duration of twos: (0 ms) Info: Duration of rtmd: 960ms (960 ms) Info: pruned empty 'hvc1' track Info: pruned empty 'twos' track Info: saving badvideo.mp4_fixed-dyn.MP4

Using the -s flag, works but got only some seconds of the whole video.

— Reply to this email directly, view it on GitHub https://github.com/ponchio/untrunc/issues/260, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUDV27VW3US5ZNHTFDYSYDW5YLRHANCNFSM6AAAAAAWHCTESE . You are receiving this because you are subscribed to this thread.Message ID: @.***>