Target to synthesize the sounds in the MP3 into the MP4.
Third-party libraries in use: Mp4parser,
Muxing Audio/video
The API and the process is Straight-forward:
-
You wrap the raw format file into a appropriate track object.
h264trackimpl H 264Track = new h264trackimpl (new Span class= "Pl-smi" >filedatasourceimpl ( "Video.h264 aactrackimpl aactrack = new Aactrackimpl (new filedatasourceimpl ( aac
These track object is then added to a Movie object
Movie ();addtrack (H264track); movie. Addtrack (aactrack) ;
The Movie object is a fed into a mp4builder to create the container.
Defaultmp4builder (). Build (movie);
Write the container to an appropriate sink.
FileOutputStream (File ("Output.mp4")). Getchannel (); Mp4file. Writecontainer (FC); FC. Close ();
Requires. h264 files and AAC files as "input" and output to MP4 format.
Test: Use Mediarecorder to generate a file with a suffix of. H264. The test can be played on the phone side. Use the above method to synthesize with an AAC file. Error:
Java.lang.NullPointerException:Attempt to read from field ' int com.googlecode.mp4parser.h264.model.PictureParameterSet.seq_parameter_set_id ' on a null object reference
New H264trackimpl (new Filedatasourceimpl ("/storage/emulated/0/dcim/testcamera/vid_2016.h264")); // Error Line
Construction failed. Google has no effect on this issue.
View Mp4parser's Issues:
Combine a music.m4a on a video.mp4 overwrite my video audio
Mp4parser's author replies:
"Basically want to merge," audio tracks to one. Players won ' t play with audio tracks at the same time. This is a with case, which requires decoding, then merging and encoding to one audio track again. The Mp4parser cannot do. I guess you'll need to use ffmpeg or the Mediacodec API. "
In a word, mp4parser can't do it.
Synthesis of MP4 and MP3