如何使用FFMPEG添加一个新的音频(非混合)到视频? [英] How to add a new audio (not mixing) into a video using ffmpeg?
问题描述
我以前像这样的命令:
的ffmpeg -i video.avi -i audio.mp3 -v codeC codeC -a codeC codeC output_video.avi -newaudio
在添加新音轨视频的最新版本(不混合)。
但我更新FFmpeg的到最新版本(的ffmpeg版本的git-2012-06-16-809d71d ),现在在这个版本参数 -newaudio
不起作用。
使用请告诉我我怎么可以添加新的音频到我的视频(不能混合)的ffmpeg
。
添加音频视频:流复制
的ffmpeg -i video.avi -i audio.mp3 - codeC副本-shortest output.avi
- 省略
-map
选项将使用默认的流选择。如果你的视频输入无音频这样的工作。 - 本例使用
- codeC副本
来流副本(重新编码没有,质量是preserved,这是快) 。 - 的
-shortest
选项将使output.avi
相同持续时间最短的输入。
音频添加到视频:重新连接code
如果您的输出不喜欢原来的格式,或者如果你想改变的格式,您可以指定连接codeRS:
的ffmpeg -i video.avi -i audio.mp3 -c:v libx264 -c:一个libvorbis -shortest output.mkv
手动选择特定的数据流
有时默认流选择不会给你你想要的结果。在这个例子中 video.mp4
具有视频和音频和 audio.m4a
只有音频。使用 -map
来选择 video.mp4
视频和音频 audio.m4a
:
的ffmpeg -i video.mp4 -i audio.m4a -map 0:v -map 1:-C副本-shortest output.mp4
-
0 -Map:v
- 从输入0
(第一次输入,这是video.mp4
)选择v
IDEO流(S)。 -
-map 1:
- 从输入1
(第二个输入,这是audio.m4a
)选择A
UDIO流(S)。
混合/结合两个音频输入到一个
以视频从 video.webm
,并使用 amerge过滤器到音频,从结合 video.webm
和 audio.oga
:
的ffmpeg -i video.webm -i audio.oga -filter_complex \\
[0:A] [1:] amerge =输入= 2 [A]\\
-map 0:v -map[1]-c:V复制-c:一个libvorbis -ac 2 -shortest out.webm
生成静音音频
您可以使用 anullsrc过滤做一个沉默的音频流。该过滤器允许您选择所需的渠道布局(单声道,立体声,5.1等),采样率。
的ffmpeg -i video.mp4 -f lavfi -i anullsrc = channel_layout =立体声:SAMPLE_RATE = 44100 \\
-c:V复制-shortest output.mp4
另请参见
I used a command like:
ffmpeg -i video.avi -i audio.mp3 -vcodec codec -acodec codec output_video.avi -newaudio
in latest version for adding new audio track to video (not mix).
But I updated the ffmpeg to the newest version (ffmpeg version git-2012-06-16-809d71d) and now in this version the parameter -newaudio
doesn't work.
Tell me please how I can add new audio to my video (not mix) using ffmpeg
.
Add audio to video: stream copy
ffmpeg -i video.avi -i audio.mp3 -codec copy -shortest output.avi
- Omitting the
-map
option will use the default stream selection. This will work if your video input has no audio. - This example uses
-codec copy
to stream copy (no re-encoding; quality is preserved and it is fast). - The
-shortest
option will makeoutput.avi
the same duration as the shortest input.
Add audio to video: re-encode
If your output doesn't like the original formats, or if you want to change formats you can specify the encoders:
ffmpeg -i video.avi -i audio.mp3 -c:v libx264 -c:a libvorbis -shortest output.mkv
To manually choose specific streams
Sometimes the default stream selection won't give you the result you want. In this example video.mp4
has video and audio, and audio.m4a
only has audio. Use -map
to choose video from video.mp4
and audio from audio.m4a
:
ffmpeg -i video.mp4 -i audio.m4a -map 0:v -map 1:a -c copy -shortest output.mp4
-map 0:v
– From input0
(the first input, which isvideo.mp4
) choose thev
ideo stream(s).-map 1:a
– From input1
(the second input, which isaudio.m4a
) choose thea
udio stream(s).
Mixing/combining two audio inputs into one
Take video from video.webm
, and use the amerge filter to combine the audio from video.webm
and audio.oga
:
ffmpeg -i video.webm -i audio.oga -filter_complex \
"[0:a][1:a]amerge=inputs=2[a]" \
-map 0:v -map "[a]" -c:v copy -c:a libvorbis -ac 2 -shortest out.webm
Generate silent audio
You can use the anullsrc filter to make a silent audio stream. The filter allows you to choose the desired channel layout (mono, stereo, 5.1, etc) and the sample rate.
ffmpeg -i video.mp4 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \
-c:v copy -shortest output.mp4
Also see
- Combine two audio streams into one
- FFmpeg Wiki: Audio Channel Manipulation
- FFmpeg mux video and audio from another video
这篇关于如何使用FFMPEG添加一个新的音频(非混合)到视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!