0

I am trying to merge a video and an audio using ffmpeg. What I want is to keep mix audio from both files i.e. from video as well as from audio file. I am currently trying with the below command.

-i, /storage/emulated/0/2.mp4, -i, /storage/emulated/0/1.mp3, -c, copy,
-map, 0:v:0, -map, 1:a:0, -shortest, /storage/emulated/0/1543574231129.mp4

The problem with the above command is that it removes the audio of the video file and only keep the audio of the audio file supplied. I tried with a different command too but in that case audio from the audio file was not present in the video.

How can I mix the audio tracks in the output file ?

EDIT:

I tried with the command suggested in the comments like this below.

[-i, /storage/emulated/0/2.mp4, -i, /storage/emulated/0/1.mp3, -filter_complex, [0:a:0][1:a:0]amix[outa], -map, [0:v:0], -map, ["outa"], /storage/emulated/0/1543907405323.mp4]

But now this gives the below error

Output with label '0:v:0' does not exist in any defined filter graph, or was already used elsewhere.

Vivek Mishra
  • 37
  • 1
  • 12
  • See linked question on how to use the `amix` filter in a complex filter command. `ffmpeg -i -i -filter_complex "[0:a:0][1:a:0]amix[outa]" -map "[0:v:0]" -map ["outa"] ` – slhck Nov 30 '18 at 15:03
  • https://superuser.com/questions/1004164/how-do-i-use-ffmpeg-to-mix-an-audio-video-file-with-an-audio-file-with-an-offset – slhck Nov 30 '18 at 15:03
  • @slhck it gives error saying unable to find suitable output format for filter_complex – Vivek Mishra Dec 03 '18 at 08:56
  • Please edit your question and show exactly what you have tried. And please do not show the Java code you are using, but the actual command that gets executed on the system. – slhck Dec 03 '18 at 20:01
  • @slhck I tried again today and now it is giving a different error. I have updated that in question – Vivek Mishra Dec 04 '18 at 07:09
  • Oh, sorry, it should be `-map 0:v:0` without brackets. – slhck Dec 04 '18 at 08:08
  • @slhck the command worked but I can't hear audio from either video or audio file. It plays some static noise. Also how to add the shortest argument in the above command – Vivek Mishra Dec 04 '18 at 08:32

0 Answers0