Can not find NAL unit header for .mp4 files (H264 coded)? - h.264

I have been using Hex file viewer to parse few mp4 files and I know they r coded with H264 not MPEG4 .
I do not seem to find the NAL header (0x000001 or 0x00000001) except at very far places from the start of the file , like half or almost at the end ?
Any ideas?

The extra data can be extracted from the avcC box.
The rest is answered by this post. Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream

Related

Record rtmp stream to multi flv files

I'm currently write rtmp server to receive rtmp stream, then record to multi flv file, segment base on time.
Example: 1 minute -> 1 flv file, 2m -> 2 flv file...
Problem: only the first flv file is playable, from the second onwards, they are not playable, maybe they miss some metadata of the codec (h264).
How can I resolve that problem?
Yes, there is a header, as well as sequence headers depending on the codec used. The segments must also be split on keyframes. The FLV formate is well documented here https://www.adobe.com/content/dam/acom/en/devnet/flv/video_file_format_spec_v10.pdf

Create mp3 from binary file

I have got one midi file, converted it into binary
Know i want to make a mp3 using that binary how can i do it.
i am using php as my scripting language
here is my code using which i am converting midi to binary
$filename = "flute.mid";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
for ($i = 0; $i < strlen($contents); $i++) {
$binary = sprintf("%08d", base_convert(ord($contents[$i]), 10, 2));
echo $binary;
}
fclose($handle);
Besides the conversion to ASCII-encoded binary which is useless and would only make the things much more complicated (I don't know any program that can read this format), MIDI contains events (musical notes, instruments, etc.), whereas MP3 files contain compressed sampled sound. To convert MIDI to MP3 you therefore need to use a synthesizer to generate sampled sound from the MIDI source, and then to compress the sampled audio data into MP3 format.
To synthesize MIDI to audio you can look for example at something like Timidity++ (http://timidity.sourceforge.net/). To compress the audio to MP3 you can use for example LAME (http://lame.sourceforge.net/). Both programs can be found as installable packages on many Linux distributions (on Ubuntu, package names are timidity and lame; both are in the Universe package repository).
See first thing you are converting MIDI into Binary. Second thing you are trying to convert it directly to mp3.
This thing is not possible in this way. Mp3 is Encoded Compressed format it can't be created in such a way. Even sometime try to open a mp3 in Notepad & then without making any change Save As it with new name by putting .mp3 at the end. The file with mp3 extension having same data as original will be created but it will not played by player.
So my point is that you have to research an encoding method to convert MIDI in mp3.

Reconstructing fragmented H.264 stream

I have H.264 stream stored as a file. I am trying to create a MPEG4 file by adding this stream to MDAT BOX. I have created other headers required by MPEG-4 standards. But I am unable to read the MPEG-4 file.
I parsed the H.264 stream and I see that there are multiple I-frames in the file. It seems to me that this is fragmented H.264 stream.
Is there any way in which this fragmented H.264 stream can be combined into a single I-frame?
I have gone through the link Problem to Decode H264 video over RTP with ffmpeg (libavcodec).
I implemented what was mentioned in the link but i am still unable to run the MPEG-4 thus created.
With the above technique, I get the fragmentType = 5. I get the following nalTypes (8, 2, 1, 0, 0, ...). I get the startBit as specified and for the other fragments, I get the 00 (for StartBit|endBit). I do not get the endBit.
When i try using FFMPEG to reconvert the MPEG-4 file that was created, i get the following error: "header damaged". It looks like the reconstruction of IDR frames is not working properly.
Please let me know if the method that I am following has any issues.
The H.264 stream file is around 100KB. When this file is converted to MP4 using FFMPEG, I get around 38KB. Does it mean that FFMPEG is re-encoding the file once again inorder to recreate the MP4 file?
With the above technique that was mentioned in the link, the MP4 that I have created is around 100KB itself.
Please let me know what I am doing that is wrong.
Thanks in advance.
It sounds like you'd like to wrap an H.264 elementary stream in a mp4 container so that you can play it back.
A tool like mp4box (http://gpac.wp.mines-telecom.fr/mp4box/) will enable you to wrap you elementary stream into a mp4 file. For example:
mp4box -add MySourcFile.h264 MyDestFile.mp4

Open source H.264 decoder in C++

I am using live555 for receiving network camera video via RTSP, which data is H264 encoded. Is there any open source software for decoding the received packets and parse it into different video frames?
Best regards,
Dídac Pérez
Yes, ffmpeg can decode the data. Infact you can use ffmpeg directly recieve the data, transcode /transform it to your desired form and send it out again or dump it into a file if you wish. If you want to use live555 for recieving it and ffmpeg for decoding simply write output of live555 to a pipe and feed it to ffmpeg to do the decoding.
I'm confused by your question. live 555 is built on top of ffmpeg, so it has all access to the decoders built into ffmpeg.

What is the meaning of "Only raw PCM 16 bits mono files with the same frequency as the current voice are supported by the audio tag."?

When trying to use the HTML5 <audio> tag, I get this error:
Only raw PCM 16 bits mono files with the same frequency as the current
voice are supported by the audio tag.
What does this mean?
I understand that Only raw PCM 16 bits mono files with the same frequency as the current voice are supported by the HTML 5 <audio> tag. Your file is in the wrong format - resample it to a single (mono) channel at, say, 44.1KHz (standard), encoded as 16 bit PCM, and it should play fine.
is it a wave file? If not you need a put the pcm in to wav file
PCM is the audio format in wav containers. I also think it can be AIFF in wav files but mostly WAV files contain PCM.
So if the file you are trying to play is not a wav file it might be complaining about that.
Just the extension is wav does not also mean that it is a wav file. The file needs to have wav headers and other stuff that wav would have.