Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add audio to video in android

Tags:

android

I want to develop an android application which can record a video (mp4), then I have some audio files (mp3) in my resources folder, and I want to add it to the end of the video. So the final effect will be like first the video is played and at the end of video the added audio will be heard. how can I do it?

like image 408
NMNM Avatar asked Jul 31 '12 03:07

NMNM


People also ask

How do I add audio to my Android?

Open your Android Studio and create a new project. Create a new folder named "raw" in your Android project's "res" folder and place your audio file inside the "raw" folder. You can see the audio is now successfully added into your Android Studio project by viewing the "raw" subfolder under "res" folder.


2 Answers

Combing to files with different audio codecs is not easily possible. I would do the following:

  • convert the MP3 files to the same format as the video (most likely AAC in an MP4 container)
  • Now you can use mp4parser's AppendExample to append the recorded video with the pre-recorded sound
  • The result will be one MP4 file containing the video first and the sound.

Full disclosure: I am the maintainer of mp4parser.

like image 200
Sebastian Annies Avatar answered Oct 17 '22 10:10

Sebastian Annies


After api version 18 android MediaCodec apis supports to access the low level api. MediaMuxer muxing the elementary streams.

https://developer.android.com/reference/android/media/MediaMuxer.html

like image 39
rKrishna Avatar answered Oct 17 '22 08:10

rKrishna