mux mp4 on-the-fly as H.264 NALs and AAC encoded frames come in buffers

679 views
Skip to first unread message

Eddie

unread,
Oct 16, 2015, 6:42:49 PM10/16/15
to mp4parser-discussion
Hi,

I am wondering if mp4parser can take input from buffers instead of from files. I have a source that generates encoded video (H.264 elementary stream) and encoded audio (AAC). I know the video frame boundaries and can parse SPS, PPS, etc. Is there a way I can use mp4parser to create mp4 file on-the-fly? I can submit timestamps for encoded content which will be monotonically increasing and based on the same clock for both tracks. 

Please help.

Best regards,
Eddie


Sebastian Annies

unread,
Oct 17, 2015, 4:10:14 AM10/17/15
to mp4parser-...@googlegroups.com
Hi Eddy, 

this is a functionality I'm currently building in the branch 2.x. You request comes at the right time to still influence what's happening. I'm very interested in your use case. At the moment my primary use case are: 
* Replacement of mediamuxer on Android. For example:
  - insert GPS speed&loc in a subtitle track
  - add custom metadata without having to rewrite the file
* Receive Streaming protocols - emit MP4 based formats such as MPEG-DASH. You might want to have a look at my RTP2DASH project as it showcases receiving of frames and muxing on the fly.

At the moment I have implemented the functionality to generate fragmented MP4s - unfortunately they are not yet 'seekable' - I'll have to dig into that perhaps even by looking at VLC code
Next steps will be to create classic MP4 files (fast-start and non-fast-start)

I'm really interested in getting this functionality done - let's have a skype call so that I understand your needs better. Be my 'pilot customer'.

Best Regards,
Sebastian

----------------------
skype: sebastian.annies


--
You received this message because you are subscribed to the Google Groups "mp4parser-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eddie

unread,
Oct 19, 2015, 3:02:11 PM10/19/15
to mp4parser-discussion
Hi Sebastian,

I am able to build mp4 on-the-fly using Android MediaMuxer API. Currently, 1 audio and 1 video track suffice for me. 

Interestingly, Android MediaMuxer prints this
 "I MPEG4Writer: The mp4 file will not be streamable."

So, I am guessing the file is not a "fast start", it will have to be downloaded fully before it can start playing. Am I right? Another interesting thing is, the file plays perfectly in most players under the sun on multiple OSes, VLC on Win, Mac, Linux, Totem player, Win Media Player, etc. However, it has some issue playing on QuickTime on Mac. Audio track works great even on QuickTime. If I take the same elementary video stream and mux it using ffmpeg then it plays fine on QuickTime. If I take only the elementary video stream and mux it using MediaMuxer, issue is seen with QuickTime. 

Don't get me wrong, none of these are show stoppers for me. I was just curious to find out what is possible with mp4parser . . . Thanks a lot for answering. I will send you a Skype request. Will be happy to beta / alpha test for you even if I go with Android MediaMuxer . . . 

Mit herzlichen Gruessen,
Eddie 
To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discussion+unsub...@googlegroups.com.

Sebastian Annies

unread,
Oct 20, 2015, 6:34:20 AM10/20/15
to mp4parser-...@googlegroups.com
The file is no fast start and cannot be read/downloaded while it's being created. The table of contents is written as the last element.  Additionally a length field in the beginning of the file needs to written. So the process is something like this:

writing data, writing data, writing data,
writing table of contents,
seek to beginning,
write length of data

The box order will be [ftyp, mdat, moov] (moov ~ table of contents, mdat ~ data)
A fast start MP4 is [ftyp, moov, mdat] - this is a bit harder to write as you won't know the final size of moov until you received all samples.

When I got my version 2 done you'll have more control over what's written and I'll support fragmented MP4s which consist of many self contained fragments similar to a standard MP4. These files can be read/download/streamed while they are being created as there is no need to seek to the beginning as one of the last steps. 

Best Regards,
Sebastian







To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discus...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mp4parser-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discus...@googlegroups.com.

Mondain

unread,
Oct 20, 2015, 7:23:02 AM10/20/15
to mp4parser-...@googlegroups.com
Sebastian, to do a fast start output, you could post process and move the moov to the beginning and adjust as needed or you could write two files in parallel and combine them at the end of the stream generation. One file for mdat and the other alongside for ftyp, toc / moov. 

Best Regards,
Paul

Sebastian Annies

unread,
Oct 20, 2015, 9:39:58 AM10/20/15
to mp4parser-...@googlegroups.com
Hi Paul,
I'm talking about the way the MediaMuxer is doing it at the moment. 
Using two files is possible and I'll implement that for on the fly creation of MP4s in version 2 of the mp4parser but this approach has its drawbacks: You need to write all data twice! This limits your throughput. Especially on devices with limited IO capabilities (low cost phones, cheap SD cards) AND you need twice the amount of free disk space as you can only delete the data file when you've copied all data into final MP4 (optimizations are possible).

The current file based implementation - the DefaultMp4Writer - always creates fast start capable files but it only works if the source video is available as a file as it relies on random access in the source file. 

Grüße,
Sebastian


Maxim Solodovnik

unread,
Mar 27, 2017, 4:02:17 AM3/27/17
to mp4parser-discussion
It seems 2.x branch haven't been released for a while
Is there any roadmap?
To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discussion+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mp4parser-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discussion+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mp4parser-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discussion+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mp4parser-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mp4parser-discussion+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages