ffmpeg混音以及音视频混合

来源:互联网 发布:mac u盘恢复 编辑:程序博客网 时间:2024/04/28 03:16

Duration = MAX(input a, v)

0. 前言

本文包括以下内容: 
(1)混音:多个音频混合 
采用amerge, amix对多个音频进行混音(而非拼接) 
(2)音视频混合——muxing 
(3)修改音频音量

1. Audio merge

1.1 amerge

-ac 2 speed up

ffmpeg -i test.mp4 -i test.mp3 -filter_complex "[0:a] [1:a]amerge=inputs=2[aout]" -map "[aout]" -ac 2 mix_amerge.aac
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

PS: Without ac speed will be half.

1.2 amix

speed = amerge + ac 2

ffmpeg -i test.aac -i test.mp3 -filter_complex amix=inputs=2:duration=first:dropout_transition=2  mix.aac
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

2. Simple A/V Muxer

-shortest : duration = MIN(inputs)

ffmpeg -i test.mp4 -i test.mp3 -vcodec copy -acodec aac -map 0:v:0 -map 1:a:0 -shortest mix_test.mp4
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

adjust volume

ffmpeg -i test.mp4 -i test.mp3 -vcodec copy -acodec aac -map 0:v:0 -map 1:a:0 -vol 60 mix_test.mp4
  • 1
  • 2
  • 1
  • 2

3. Complex A/V Merge (audio merge)

amerge : duration is shortest

ffmpeg -i test.mp4 -i test.mp3 -c:v copy -map 0:v:0 -filter_complex "[0:a][1:a]amerge=inputs=2[aout]" -map "[aout]" -ac 2  mix_amerge.mp4
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

amix : setup duration

ffmpeg -i test.mp4 -i test.mp3 -filter_complex "[0:a][1:a]amix=inputs=2:duration=first[aout]" -map "[aout]" -c:v copy -map 0:v:0 mix_amerge.mp4
  • 1
  • 1

4. Loop shorter iterm

concat shorter one

ffmpeg -i input_audio -f concat -i <(for i in {1..n}; do printf "file '%s'\n" input_video; done) -c:v copy -c:a copy -shortest output_video
  • 1
  • 1

5. Adjust Volume

audio:

ffmpeg -i test.aac -i test.mp3 -filter_complex "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.9[a0]; [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1]; [a0][a1]amerge=inputs=2[aout]" -map "[aout]" -ac 2 mix_v0.5.aac
  • 1
  • 1

video:

ffmpeg -i test.mp4 -i test.mp3 -filter_complex "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.9[a0]; [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1]; [a0][a1]amix=inputs=2:duration=first[aout]" -map "[aout]" -ac 2 -c:v copy -map 0:v:0 mix_amerge.mp4
  • 1
  • 1
1
0
 
 
0 0
原创粉丝点击