[FFmpeg-user] How to reassemble raw packet data back into a new MP4 file?
Gia Ferrari
g at giferrari.net
Sun Sep 22 10:37:19 EEST 2024
On 9/22/24 09:22, Alan Chen via ffmpeg-user <ffmpeg-user at ffmpeg.org> wrote:
> Hi, Vincent,
>
> Thank you for your suggestion.
>
> Let me explain the real case: I have many MP4 files which lost some data in
> the tail,
> which make them not playable. I analyze these files manually and find the
> ftyp and
> moov boxes and their child boxes are all OK. But part of the data in mdat
> box are
> lost, which corresponding to some packet data only, which is <= 5% of the
> total
> packets.
>
> I try to use the following command:
>
> ffmpeg -i old.mp4 -c copy new.mp4
>
> but always get the following result:
>
> ffmpeg version 7.0.2 Copyright (c) 2000-2024 the FFmpeg developers
> built with gcc 14.1.0 (Rev3, Built by MSYS2 project)
> configuration: --enable-shared
> libavutil 59. 8.100 / 59. 8.100
> libavcodec 61. 3.100 / 61. 3.100
> libavformat 61. 1.100 / 61. 1.100
> libavdevice 61. 1.100 / 61. 1.100
> libavfilter 10. 1.100 / 10. 1.100
> libswscale 8. 1.100 / 8. 1.100
> libswresample 5. 1.100 / 5. 1.100
> [mov,mp4,m4a,3gp,3g2,mj2 @ 00158b00] stream 1, contradictionary STSC and
> STCO
> [mov,mp4,m4a,3gp,3g2,mj2 @ 00158b00] error reading header
> [in#0 @ 00158840] Error opening input: Invalid data found when processing
> input
> Error opening input file old.mp4.
> Error opening input files: Invalid data found when processing input
>
> So I wrote a Test app to parse all the data in the old.mp4 and read all the
> boxes(except for mdat box), and
> get all the existing packets. Now I want to reassemble them back into a
> valid MP4 file.
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
>
Howdy, in a similar situation I successfully used untrunc https://github.com/anthwlock/untrunc
You will need a working reference file from the camera or software that generated the files that ended up truncated. We use it to fix recordings from our race car's video telemetry, which sometimes end up truncated due to the car kill switch being pressed (by rule everything needs to be instantly powered off). We then use ffmpeg to further process the videos.
Good luck.
--
Gia Ferrari (she/her)
https://giferrari.net
More information about the ffmpeg-user
mailing list