Log in

View Full Version : muxing h.264 and aac in MP4


malikcis
6th December 2013, 15:11
Hi,

Is there a way (library, framework, source code etc...) to multiplex H.264 and AAC in a MP4 file format on a frame by frame and audio chunk by audio chunk basis?
There are tons of libraries but they are all file based.
Thanks,

malikcis

Guest
6th December 2013, 15:35
on a frame by frame and audio chunk by audio chunk basis Please explain what this means.

LoRd_MuldeR
6th December 2013, 16:08
What about those?
* https://github.com/silverfilain/L-SMASH
* http://sourceforge.net/projects/gpac/

For usage example, see here:
http://git.videolan.org/?p=x264.git;a=blob;f=output/mp4_lsmash.c

malikcis
6th December 2013, 16:16
Please explain what this means.

The basic idea is to mux an audio/video stream as follows:

initialize_mp4_muxer("file.mp4");
initialize_hw_framegrabber();

while(1)
{
get_h264_frame(pVidBuffer);
get_aac_audio_chunk(pAudChunk);
mp4_mux(pVidBuffer, pAudChunk);
}
close_all_resources();

LoRd_MuldeR
6th December 2013, 16:33
Did you check out the above links? :confused:

malikcis
6th December 2013, 16:54
Did you check out the above links? :confused:

LoRd_MuldeR,

Ok I see. however write_frame() from mp4_lsmash.c only shows how to mux h.264 frame but not AAC audio.


Malikcis

LoRd_MuldeR
7th December 2013, 13:57
LoRd_MuldeR,

Ok I see. however write_frame() from mp4_lsmash.c only shows how to mux h.264 frame but not AAC audio.

Indeed, the write_frame() method in x264 does not write AAC audio, because x264 doesn't mess with audio. But the code should give you the idea how to do it ;)

Obviously, you would need to setup two tracks rather than a single one (cf. set_param() method) and then append the audio and video samples to the audio and video track, respectively (cf. write_frame() method).

VFR maniac
7th December 2013, 21:50
LoRd_MuldeR,

Ok I see. however write_frame() from mp4_lsmash.c only shows how to mux h.264 frame but not AAC audio.


Malikcis

Official x264's repo omits some features for convenience.
About muxing both audio and video, x264_L-SMASH may be helpful, though it's somewhat old.
https://github.com/silverfilain/x264_L-SMASH/blob/lsmash/output/mp4.c

x264_L-SMASH writes audio frames for each write_frame().
The code is asymmetry.
L-SMASH muxes chunk by chunk internally from input frames unless exceeding max_async_tolerance.
You can append video frames and audio frames in arbitrary timing as L-SMASH muxer app does.
http://repo.or.cz/w/L-SMASH.git/blob/HEAD:/muxer.c#l976

If you want to interleave each video frame and each audio chunk, set duration of video frame to max_chunk_duration.

malikcis
9th December 2013, 18:23
Official x264's repo omits some features for convenience.
About muxing both audio and video, x264_L-SMASH may be helpful, though it's somewhat old.
https://github.com/silverfilain/x264_L-SMASH/blob/lsmash/output/mp4.c

x264_L-SMASH writes audio frames for each write_frame().
The code is asymmetry.
L-SMASH muxes chunk by chunk internally from input frames unless exceeding max_async_tolerance.
You can append video frames and audio frames in arbitrary timing as L-SMASH muxer app does.
http://repo.or.cz/w/L-SMASH.git/blob/HEAD:/muxer.c#l976

If you want to interleave each video frame and each audio chunk, set duration of video frame to max_chunk_duration.


Thank you,
This indeed seems to be a possible way.
The hard part (implementation) remains though...