0

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
mortalis
  • 2,060
  • 24
  • 34
Rohaitas Tanoli
  • 624
  • 4
  • 16
  • Maybe it's because you specify only 1 audio input. Each input needs to be specified separately with an `-i` argument. Test it on a PC first to make sure you have 1 video and 2 audio streams in the final file. Not sure how you add audio recording to the video (from a buffer or you record it to a file and then use its path in the ffmpeg command)... – mortalis Aug 18 '23 at 17:11

0 Answers0