I have recorded a video using VLC stream. At the end of the record, I clicked the stop button and closed the player within a few seconds. now the video is not playable I have used this feature before and it worked well.
Due to the player's quick close, I assume the video is not working now. I check the codec details and it's missing. workable videos have H264 - MPEG-4 VAC.
is there any way to fix this? I have attached details of the playable video and the current video.a video taken from the same way and the current video
OS - Windows 11
I have tried to convert the video to avi format using vlc but it doesn't start the converting. I have tried to update the player but it is the latest version.
First check if the following tool will display your first frame...
(only works with a VLC recordings @ 720p)
Tool: Preview of first frame from corrupted MP4
If yes, then your MP4 is structured as following (showing first 64 bytes):
where:
The left side is your bytes (written as Hex characters).
The right side is the decoded UTF-8 text (where possible to decode).
The hex digits
6D 64 61 74
are the beginning of your file's MDAT (Media Data) section. The previous -4 bytes are00 00 00 00
because VLC does not yet know how large the recording is (until you finish, then it updates that placeholder 0 size into the real number).The next line has
06
(which is the SEI data) and where the previous -4 bytes are giving a size of (hex)00 00 02 B0
(or in decimal digits: size of 688 bytes).You can test:
console.log( "Size is... " + 0x000002B0 ); //gives 688
Javascript console always prints out as decimal format, to input a hex value just prefix the hex with
0x
(and no spaces between the hex digits).SEI itself is not a video frame just some extra data that is useful to the MP4 decoder. To reduce playback problems, just include it in your Output followed next by adding the first keyframe.
Always use a hex editor to double-check when working with file bytes
From research you will learn that an MP4 file is divided into two main sections. There is
moov
which holds the metadata (required for decoder setup and also for the byte positions of each frame, etc). The other section ismdat
and this section holds the raw audio/video bytes.A corrupted VLC recording (into MP4) only has the
mdat
section.An MP4's
mdat
section has this chunk structure:Repair as MP4 (hardest)
To repair you can use an existing MP4 to know the required "atoms" and copy them over into a new (repaired) set of bytes. You need to edit a section called the Sample Table (find
stbl
in the file) and update those details (which frames are keyframes? Which byte positions? Which timestamps for frames? etc).More info: MP4 Atom parsing - How To Configure Time
Repair as H.264 (easiest)
The easiest fix is to try to extract the H.264 frames manually from the MP4 and then later use FFmpeg (or VLC) to combine these video frames with your previously extracted audio (from using the repair software).
To extract video frames, you need to cycle through the chunks (called NAL units) inside the MP4.
Your first NALU (of type SEI) is at a position (also called offset) of 44. From that byte position you can step backwards by four bytes, and then from that new position you can now get the length of NALU by reading those 4 bytes (as one 32-bit unsigned integer, it is unsigned because we don't expect to see any minus symbol, only getting back a positive number).
I will throw in some utility functions to get you started:
To read a 4-byte value from a position in Array:
To write a 4-byte value into a position in Array:
The process (in pseudo-code):
(or same in decimal format: 6, 101, 65, 66, 67).
array.slice()
to copy/extract Input byte values into a new Output arrayIn your Output array (per frame)...
00 00 00 01
(creates an H264 start code for new data).Finally save output file as
test.h264
and try to play in a media player.Next use FFmpeg or VLC to combine the H264 video file with the extracted MP3 data.