FFMPEG mux 视频和音频(来自另一个视频) - 映射问题 [英] FFMPEG mux video and audio (from another video) - mapping issue
问题描述
我想将一个视频的音频放到另一个没有音频的视频中(在一个命令中):
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
我猜-map"是正确的方法,但我对它感到困惑.
I guess "-map" is the correct way to do it but I got confused with it.
你能建议如何解决吗?
推荐答案
输入概览
input_0.mp4
具有所需的视频流,input_1.mp4
具有所需的音频流:
Overview of inputs
input_0.mp4
has the desired video stream and input_1.mp4
has the desired audio stream:
在 ffmpeg
中,流看起来像这样:
In ffmpeg
the streams look like this:
$ ffmpeg -i input_0.mp4 -i input_1.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input_0.mp4':
Duration: 00:01:48.50, start: 0.000000, bitrate: 4144 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 4014 kb/s, SAR 115:87 DAR 1840:783, 23.98 fps, 23.98 tbr, 16k tbn, 47.95 tbc (default)
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 124 kb/s (default)
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'input_1.mp4':
Duration: 00:00:30.05, start: 0.000000, bitrate: 1754 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 1687 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 55 kb/s (default)
身份证号码
ffmpeg
指的是带有索引号的输入文件和流.格式为input_file_id:input_stream_id
.由于 ffmpeg
从 0 开始计数,流 1:1
指的是来自 input_1.mp4
的音频.
ID numbers
ffmpeg
refers to input files and streams with index numbers. The format is input_file_id:input_stream_id
. Since ffmpeg
starts counting from 0, stream 1:1
refers to the audio from input_1.mp4
.
这可以通过流说明符来增强.例如,您可以告诉 ffmpeg
您想要来自第一个输入 (0:v:0
) 的第一个视频流,以及来自第二个输入 (0:v:0
) 的第一个音频流1:a:0
).我更喜欢这种方法,因为它更有效.此外,它不太容易发生意外映射,因为 1:1
可以引用任何类型的流,而 2:v:3
只引用第四个视频流第三个输入文件.
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 because 1:1
can refer to any type of stream, while 2:v:3
only refers to the fourth video stream of the third input file.
-map
选项指示 ffmpeg
你想要什么流.从 input_0.mp4
复制视频和从 input_1.mp4
复制音频:
The -map
option instructs ffmpeg
what streams you want. To copy the video from input_0.mp4
and audio from input_1.mp4
:
$ ffmpeg -i input_0.mp4 -i input_1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4
下一个例子将做同样的事情:
This next example will do the same thing:
$ ffmpeg -i input_0.mp4 -i input_1.mp4 -c copy -map 0:v:0 -map 1:a:0 -shortest out.mp4
-map 0:v:0
可以翻译为:从第一个输入(0
),选择视频流类型(v
),第一个视频流 (0
)-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
可以翻译为:从第二个输入(1
),选择音频流类型(a
),第一个音频流 (0
)-map 1:a:0
can be translated as: from the second input (1
), select audio stream type (a
), first audio stream (0
)使用
-c copy
流将被流复制,没有重新编码,所以不会有质量损失.如果要重新编码,请参阅FFmpeg Wiki:H.264 编码指南.
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.
-shortest
选项将使输出持续时间与最短输入流的持续时间相匹配.The
-shortest
option will cause the output duration to match the duration of the shortest input stream.请参阅
-map
选项文档了解更多信息.See the
-map
option documentation for more info.这篇关于FFMPEG mux 视频和音频(来自另一个视频) - 映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!