Search code examples
androidwavmp4mediamuxermediaextractor

get audio from one mp4 and use it in resampled (smaller) mp4 in android


I have found a solution for resampling an .mp4 video taken with the camera on the device to make it smaller (resizing by resolution, bitrate, and framerate). The problem is, it doesn't carry the audio over.

I have looked at several different options for trying to get the audio out of my source (large) mp4 and push it into my smaller mp4 and I can't not seem to get any of these procedures to work correctly.

I've tried the following: 1) extracting the PCM audio from the source using: How do I extractor audio to mp3 from mp4 using java in Android? 2) converting the PCM to M4A and then adding the M4A to the smaller MP4 using: https://github.com/tqnst/MP4ParserMergeAudioVideo/blob/master/Mp4ParserSample-master/src/jp/classmethod/sample/mp4parser/MainActivity.java

that's the method I got closest with but the audio was really slow and didn't match up at all with the video in the smaller mp4.

I also tried a "direct copy" from one mp4 to the other with a variation of this: Concatenate multiple mp4 audio files using android´s MediaMuxer

that made my smaller mp4 actually larger (in file size) than my source mp4 and it didn't actually move the sound over.

The android documentation for MediaMuxer is pretty terrible and I can't make heads or tails of what I need to do to get this to work. It seems like it should be a pretty trivial task....

any suggestions or advice would be greatly appreciated.

TIA


Solution

  • I ended up just using ffmpeg with this solution:

    https://github.com/WritingMinds/ffmpeg-android-java