I would like to place the audio from a video to another video without an audio (in one command):
ffmpeg.exe -i video1_noAudio.mov -i video2_wAudio.mov -vcodec copy -acodec copy video1_audioFromVideo2.mov
I guess "-map" is the correct way to do it but I got confused with it.
Can you suggest how to resolve it?
I have a new command for merging audio to video
Overview of inputs
input_0.mp4
has the desired video stream andinput_1.mp4
has the desired audio stream:In
ffmpeg
the streams look like this:ID numbers
ffmpeg
refers to input files and streams with index numbers. The format isinput_file_id:input_stream_id
. Sinceffmpeg
starts counting from 0, stream1:1
refers to the audio frominput_1.mp4
.Stream specifiers
This can be enhanced with stream specifiers. For example, you can tell
ffmpeg
that you want the first video stream from the first input (0:v:0
), and the first audio stream from the second input (1:a:0
). I prefer this method because it's more efficient. Also, it is less prone to accidental mapping because1:1
can refer to any type of stream, while2:v:3
only refers to the fourth video stream of the third input file.Examples
The
-map
option instructsffmpeg
what streams you want. To copy the video frominput_0.mp4
and audio frominput_1.mp4
:This next example will do the same thing:
-map 0:v:0
can be translated as: from the first input (0
), select video stream type (v
), first video stream (0
)-map 1:a:0
can be translated as: from the second input (1
), select audio stream type (a
), first audio stream (0
)Additional Notes
With
-c copy
the streams will be stream copied, not re-encoded, so there will be no quality loss. If you want to re-encode, see FFmpeg Wiki: H.264 Encoding Guide.The
-shortest
option will cause the output duration to match the duration of the shortest input stream.See the
-map
option documentation for more info.