[FFmpeg-user] How to reassemble raw packet data back into a new MP4

Oliver Fromme oliver at fromme.com
Sat Sep 21 15:40:26 EEST 2024


Alan Chen via ffmpeg-user wrote:
 > ffprobe -print_format json -show_packets -show_streams -show_entries
 > packet=pts,duration,size,codec_type,pos test.mp4 > test.mp4.info

You need to provide more information.
What are the contents of test.mp4?  What codecs?

 > I extract the raw data of the packet from the test.mp4 file, take the above
 > packet as a example, I extract the data at offset = 175 and size = 6419,
 > then save the packet into a new file, video_sample0.dat.
 > 
 > I write an app to write all the packets into different audio and video
 > files, i.e., audio_sample0.dat, audio_sample1.dat, ..., video_sample0.dat,
 > video_sample1.dat...
 > 
 > Then I use ffprobe with -show_data option to show the raw data of each
 > packet, then compare the output with my packet files and confirm they are
 > identical.
 > 
 > After that, I remove some useless packets. Then try to recreate a new MP4
 > file with the remaining packets.

As Ferdi Scholten explained, that won't work.
Apart from that, I suspect that you are confusing things.

MP4 is a container format, it's *much* more than just a sequence
of video packets.  It is defined in MPEG-4 part 14 (also known as
ISO/IEC 14496-14).

 > I take one packet file as a test:
 > 
 > ffmpeg -f m4v -i video_sample0.dat -c copy output.mp4

Are you sure that your file is actually a valid "m4v" stream?
I suspect it is not.  The error messages that you get from FFmpeg
confirm this.

In this context, m4v means a video stream according to MPEG-4
part 2 (ISO/IEC 14496-2), including DivX / Xvid.  It does *NOT*
include H.264 (AVC) or h.265 (HEVC), for example.

(Do not confuse it with Apple's MPEG-4 DRM video container format
that happens to use the .m4v file name extension, unfortunately,
but is unrelated to MPEG-4 part 2.)

 > So, how to reassemble the raw packet data back to a new MP4 file?

That's not possible in general, because your raw packets do not
contain sufficient information to create an MP4 file.

I suggest that you explain why you are actually doing all of that.
What is the purpose, what do you want to achieve actually, on a
higher level?  There's probable a *much* easier way than trying
to dissect the video on the packet level.

Best regards
 -- Oliver


More information about the ffmpeg-user mailing list