regarding muxing .mp4 video only file + .aac file to create .mp4 file

2,065 views
Skip to first unread message

satish MR

unread,
Jan 4, 2013, 10:43:02 AM1/4/13
to mp4parser-...@googlegroups.com
Hi,
  I was trying to use latest isoviewer-2.0-RC-18.jar library in my demo android app and achieve below use-case,
Stream1 : Video (.h264 baseline) in .mp4 file (no Audio present in it)
Stream2 : Audio (.acc LC, with adts format) in .aac file.

I want to mux Stream1 & Stream2 and finally create .mp4. 
Is that usecase is achievable currently? 


Meanwhile I tried to mux a .h264 & .aac streams to form .mp4 file. but ended up with below error:

--------
E/AndroidRuntime(18600): Caused by: java.lang.RuntimeException: java.io.IOException
E/AndroidRuntime(18600): at com.googlecode.mp4parser.android.Mp4ParserPerformance.onCreate(Mp4ParserPerformance.java:111)
E/AndroidRuntime(18600): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(18600): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime(18600): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
E/AndroidRuntime(18600): ... 11 more
E/AndroidRuntime(18600): Caused by: java.io.IOException
E/AndroidRuntime(18600): at java.io.InputStream.reset(InputStream.java:218)
E/AndroidRuntime(18600): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl$ReaderWrapper.reset(H264TrackImpl.java:556)
E/AndroidRuntime(18600): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.readSamples(H264TrackImpl.java:245)
E/AndroidRuntime(18600): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.parse(H264TrackImpl.java:87)
E/AndroidRuntime(18600): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.<init>(H264TrackImpl.java:76)
E/AndroidRuntime(18600): at com.googlecode.mp4parser.android.Mp4ParserPerformance.onCreate(Mp4ParserPerformance.java:88)
E/AndroidRuntime(18600): ... 14 more
------------------------------------
 

satish MR

unread,
Jan 4, 2013, 10:58:28 AM1/4/13
to mp4parser-...@googlegroups.com

Sebastian Annies

unread,
Jan 4, 2013, 1:55:40 PM1/4/13
to mp4parser-...@googlegroups.com

Without having looked into the files I can say one thing: Don’t use isoviewer jars as they are an application, use the isoparser jars from the maven repositories as they are the library.

satish MR

unread,
Jan 4, 2013, 9:29:42 PM1/4/13
to mp4parser-...@googlegroups.com
Thanks for your reply. 

I tried using "isoparser-1.0-RC-15" from http://mvnrepository.com/artifact/com.googlecode.mp4parser/isoparser  But this library also behaving same.
I have extracted .h264 file from corresponding .mp4 file using YAMB.exe tool. 

Sebastian Annies

unread,
Jan 5, 2013, 6:30:08 AM1/5/13
to mp4parser-...@googlegroups.com

Hi,

 

I could have seen this one on the first glance (but I didn’t … )

 

The H264TrackImpl requires the InputStream to support mark & reset. The plain FileInputStream doesn’t support it. Please wrap the raw H264 FileInputStream in a BufferedInputStream and everything will work just fine.

 

H264TrackImpl h264Track = new H264TrackImpl(new BufferedInputStream(new FileInputStream("m.h264")));

 

Mark&reset is just required due to a sloppy implementation. I’ll probably change it in the next releases but wrapping a FileInputStream in a BufferedInputStream doesn’t hurt ;)

 

Best Regards,

Sebastian

satish MR

unread,
Jan 6, 2013, 7:02:58 AM1/6/13
to mp4parser-...@googlegroups.com
Hi,

Thanks a lot for the help.
I could move forward with that. But Still I felt I am missing something.

Case 1: For below streams I got,

E/AndroidRuntime( 6988): Caused by: java.lang.RuntimeException: too many PopLocalFrame calls
E/AndroidRuntime( 6988): at libcore.io.Posix.writev(Native Method)
E/AndroidRuntime( 6988): at libcore.io.BlockGuardOs.writev(BlockGuardOs.java:196)
E/AndroidRuntime( 6988): at java.nio.IoVec.doTransfer(IoVec.java:81)
E/AndroidRuntime( 6988): at java.nio.FileChannelImpl.transferIoVec(FileChannelImpl.java:327)
E/AndroidRuntime( 6988): at java.nio.FileChannelImpl.write(FileChannelImpl.java:505)
E/AndroidRuntime( 6988): at java.nio.channels.FileChannel.write(FileChannel.java:716)
E/AndroidRuntime( 6988): at com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder$InterleaveChunkMdat.getBox(DefaultMp4Builder.java:475)
E/AndroidRuntime( 6988): at com.coremedia.iso.IsoFile.getBox(IsoFile.java:182)
E/AndroidRuntime( 6988): at com.googlecode.mp4parser.android.Mp4ParserPerformance.onCreate(Mp4ParserPerformance.java:99)
E/AndroidRuntime( 6988): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 6988): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime( 6988): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)

Case 2: for these 2 streams,

Error was,
E/AndroidRuntime( 7091): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 7091): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.readSamples(H264TrackImpl.java:283)
E/AndroidRuntime( 7091): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.parse(H264TrackImpl.java:87)
E/AndroidRuntime( 7091): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.<init>(H264TrackImpl.java:76)
E/AndroidRuntime( 7091): at com.googlecode.mp4parser.android.Mp4ParserPerformance.onCreate(Mp4ParserPerformance.java:90)
E/AndroidRuntime( 7091): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 7091): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime( 7091): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)

I used aspectjrt-1.6.6.jar also to avoid class not found exception.

Thanks again for your followup.

Sebastian Annies

unread,
Jan 6, 2013, 7:31:33 AM1/6/13
to mp4parser-...@googlegroups.com

What you see is some bullshit android internal restriction on how many ByteBuffers you can write at once (I never traced the error to its root, I’d need to go to Android C sources for that). I think you use RC-15, please try RC-18 from  this repository: https://oss.sonatype.org/content/repositories/comgooglecodemp4parser-137/  in RC-18 it should be fixed.

satish MR

unread,
Jan 6, 2013, 8:07:14 AM1/6/13
to mp4parser-...@googlegroups.com
Hi,

Thats awesome. It worked like anything.
Moov atom is placed at beginning of the created .mp4 file. Thats really useful. Great work.

Meanwhile I faced beloe problem for these files.

E/AndroidRuntime(11763): Caused by: java.lang.NullPointerException
E/AndroidRuntime(11763): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.readSamples(H264TrackImpl.java:283)
E/AndroidRuntime(11763): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.parse(H264TrackImpl.java:87)
E/AndroidRuntime(11763): at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.<init>(H264TrackImpl.java:76)
E/AndroidRuntime(11763): at com.googlecode.mp4parser.android.Mp4ParserPerformance.onCreate(Mp4ParserPerformance.java:80)
E/AndroidRuntime(11763): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(11763): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime(11763): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)

Sebastian Annies

unread,
Jan 29, 2013, 12:50:57 AM1/29/13
to mp4parser-...@googlegroups.com
Hi, 

I fixed the issue you are seeing. But I ran into a new issue: The video file you sent me has seemingly no fixed framerate. It has a variable framerate. This is typical for a low cost phone's h264-encoder. This is not yet supported and is not likely to be implemented by me. One would need to decode PTS/DTS for every frame to get the number of milliseconds each frame needs to be displayed and to construct the correct "time to sample"-box. 

Best Regards,
Sebastian

Sebastian Annies

unread,
Jan 29, 2013, 12:51:36 AM1/29/13
to mp4parser-...@googlegroups.com
BTW.: It is fixed in the trunk and it hasn't been released yet. You will need to build the trunk.

satish MR

unread,
Jan 29, 2013, 12:58:43 AM1/29/13
to mp4parser-...@googlegroups.com
Great. Thanks a lot. Please intimate once the build is ready.
I will go through the code and try to contribute for variable framerate elementary streams.

Guillaume Lachaud

unread,
Apr 30, 2013, 8:53:02 AM4/30/13
to mp4parser-...@googlegroups.com
Hi !

I think I am trying to achieve the exact same thing. I have used MediaCodec API in Android to produce raw h264 file and raw AAC file. Now I am trying to mux them altogether. Unfortunately, using the trunk version, I am facing an exception :

04-30 14:45:42.785: W/System.err(31755): java.io.IOException: Expected Start Word 0xfff
04-30 14:45:42.795: W/System.err(31755): at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.readADTSHeader(AACTrackImpl.java:290)
04-30 14:45:42.795: W/System.err(31755): at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.readSamples(AACTrackImpl.java:322)

It seems that my aac file is missing headers. Do any of you have tried to use the muxer with files created with MediaCodec API ? How can I add the correct headers to my file ?

Thanks

Lionel Carminati

unread,
Apr 30, 2013, 9:34:40 AM4/30/13
to mp4parser-...@googlegroups.com
are you sure your raw AAC audio file remains on ADTS header ? LATM ? LOAS ?

Is mp4parser support LATM headers in both mode explicit and implicit ?

lC


2013/4/30 Guillaume Lachaud <guillaum...@backelite.com>

--
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/groups/opt_out.
 
 

Guillaume Lachaud

unread,
Apr 30, 2013, 10:20:50 AM4/30/13
to mp4parser-...@googlegroups.com
I don't think it has any header at all. The MediaCodec API just returns raw AAC frames from the encoder, it seems to be up to me to encapsulate this in a ADTS frame but I am looking for a tool to do so.


2013/4/30 Lionel Carminati <lionel.c...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "mp4parser-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mp4parser-discussion/a9RbWVs5Kgs/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mp4parser-discus...@googlegroups.com.

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



--






Guillaume LACHAUD
Backelite - Développeur Android

7, rue de Bucarest - 75008 PARIS - FRANCE


                         

.

Lionel Carminati

unread,
Apr 30, 2013, 11:23:02 AM4/30/13
to mp4parser-...@googlegroups.com
what do u mean "no header at all" ?? How can you mux raw AAC file into MP4 without any information about frequency, channel number, bit depth, etc ?

try to open your file with mediainfo and have a look to general/format tab


regards


2013/4/30 Guillaume Lachaud <guillaum...@backelite.com>

Guillaume Lachaud

unread,
May 2, 2013, 4:09:22 AM5/2/13
to mp4parser-...@googlegroups.com
That's indeed the problem. I know it won't be possible and was wondering whether mp4parser would be able to add these headers. 

The problem is that the undocumented MediaCodec API just returns raw AAC frames so I don't have any headers. I am considering using FFMPEG to encapsulates these frames unless I find a better tool.

MediaInfo just displays the file size


2013/4/30 Lionel Carminati <lionel.c...@gmail.com>

satish MR

unread,
May 2, 2013, 6:30:09 AM5/2/13
to mp4parser-...@googlegroups.com

Hey generate your own adts headers and prepend it to each raw aac frame. Its easy. Its working for me

Guillaume Lachaud

unread,
May 2, 2013, 10:01:20 AM5/2/13
to mp4parser-...@googlegroups.com
Hi !

I am now generating my own adts headers using these specifications : 


The file is now playable but it doesn't sound good, it seems to play too fast. I am not sure how to implement Buffer fullness in the adts header (O).

Here is what mplayer says about my aac file :


aac @ 0x101818a00] Reserved bit set.

[aac @ 0x101818a00] Input buffer exhausted before END element found

[aac @ 0x101818a00] channel element 0.1 is not allocated

[aac @ 0x101818a00] Input buffer exhausted before END element found

[aac @ 0x101818a00] channel element 0.14 is not allocated

[aac @ 0x101818a00] Input buffer exhausted before END element found

Lionel Carminati

unread,
May 2, 2013, 11:26:02 AM5/2/13
to mp4parser-...@googlegroups.com
send me ur aac file i will check it with interra vega TSA (audio/video analyser)

don't forget to specify audio characteristic you want to apply

regards

lC


2013/5/2 Guillaume Lachaud <guillaum...@backelite.com>

--

Guillaume Lachaud

unread,
May 2, 2013, 12:48:44 PM5/2/13
to mp4parser-...@googlegroups.com
It might not be related to buffer fullness after all.

"Also the standard ISO IEC 13818-7 and ISO IEC 14496-3 are not clear about what a decoder can do with the buffer fullness. The open source faad decoder ignores it. The open source faac always set it to VBR (all ones) even if it has been configured to do constant bitrate."


2013/5/2 Lionel Carminati <lionel.c...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "mp4parser-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mp4parser-discussion/a9RbWVs5Kgs/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mp4parser-discus...@googlegroups.com.

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

Sebastian Annies

unread,
May 2, 2013, 4:31:31 PM5/2/13
to mp4parser-...@googlegroups.com

Can you send a raw AAC that plays to fast when muxed into MP4? I’ll have a look.

 

Von: mp4parser-...@googlegroups.com [mailto:mp4parser-...@googlegroups.com] Im Auftrag von Guillaume Lachaud
Gesendet: Donnerstag, 2. Mai 2013 18:49
An: mp4parser-...@googlegroups.com
Betreff: Re: regarding muxing .mp4 video only file + .aac file to create .mp4 file

 

It might not be related to buffer fullness after all.

Guillaume Lachaud

unread,
May 3, 2013, 2:51:57 AM5/3/13
to mp4parser-...@googlegroups.com
Please find attached a sample. It should last 10 seconds.

It plays fine in mplayer at good speed now but I am still unable to mux it.

05-03 08:46:09.750: W/System.err(4547): java.io.IOException: Expected Start Word 0xfff
05-03 08:46:09.755: W/System.err(4547): at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.readADTSHeader(AACTrackImpl.java:291)

The first iteration is good, with 0xfff but it seems that second header is not and then throws an exception.



2013/5/2 Sebastian Annies <sebastia...@gmail.com>
outputTest.aac

Guillaume Lachaud

unread,
May 3, 2013, 3:21:06 AM5/3/13
to mp4parser-...@googlegroups.com
Well, I have found something weird.

If I write the bit length of the frame in headers, mplayer will play the file fine but not vlc.
If I write the byte length of the frame in the header, mplayer won't play it correctly but vlc will, after muxing it (using Subler on Mac)

From what I can see in AACTrackImpl.readSamples, this size should be in bytes. But still I am having the issue of my previous message with mp4parser. Muxing is perfect when using Subler.


2013/5/3 Guillaume Lachaud <guillaum...@backelite.com>

Bill Gockeler

unread,
May 13, 2013, 12:17:21 PM5/13/13
to mp4parser-...@googlegroups.com
Satish,

I am trying to do the same thin you are and came across this post looking for some direction on how to generate the ADTS headers. You said you are doing this and have it working. Can you provided some information as to how you do this? Thanks
Bill

Cody Nutt

unread,
Apr 10, 2016, 2:54:48 PM4/10/16
to mp4parser-discussion, guillaum...@backelite.com
Old thread but I ran across this same error message, "expected-start-word-0xfff", today and this was the only good thread that came up about it and I wanted to post what I found. I was originally/mistakenly saving and reading my aac files from the cachedir, I switched to saving/reading from the filesdir and my "expected-start-word-0xfff" error went away. Haven't looked into it much deeper yet though but thought it might help someone in the future


2013/5/2 Sebastian Annies <sebastia...@gmail.com>

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/groups/opt_out.
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "mp4parser-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mp4parser-discussion/a9RbWVs5Kgs/unsubscribe?hl=en.

To unsubscribe from this group and all its topics, send an email to mp4parser-discussion+unsub...@googlegroups.com.


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



 

--

 



 

 

Guillaume LACHAUD

Backelite - Développeur Android

7, rue de Bucarest - 75008 PARIS - FRANCE

 

                         

.

 

--
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/groups/opt_out.
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "mp4parser-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mp4parser-discussion/a9RbWVs5Kgs/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mp4parser-discussion+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages