I am using FFmpegKit
to add audio to a video file. But it has a problem.
I am recording video using camera2api
.
- If I add raw music resource mp3 after writing it to a file it works.
- If I do voice recording and add it to the video it also works.
- But when I add voice and then music it shows success but the video only has voice recording, not music.
Here is ffmpeg
command:
StringBuilder command = new StringBuilder()
.append("-y") // overWrite
.append(" -i ").append(video) // video
.append(" -i ").append(audio) // audio
.append(" -c:v ").append("copy")
.append(" -c:a ").append("copy")
.append(" -shortest ") // shortest from both
.append(" -f ").append("mp4 ")
.append(tempFile.getAbsolutePath());
I am recording voice using MediaRecorder
:
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC)
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
mediaRecorder.setAudioEncodingBitRate(96000);
mediaRecorder.setAudioSamplingRate(96000);
mediaRecorder.setAudioChannels(2) // stereo