Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG set volume in amix

I've been trying to mix an audio mp3 with a video mp4 while retaining the mp4 audio. This is working with .

ffmpeg -y  -i video.mp4 -i audio.mp3
 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest[out]" 
 -map 0:v -map [out] output.mp4

I'm now trying to adjust the volumes of the sound files (video 0.5, audio 1) as part of the mix.

I've been trying things like

ffmpeg  -i 020c276b-face-4bb3-9169-e8969c1232ba.mp4 -i test.mp3 -filter_complex 
 "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1]; 
  [1:a]aformat=sample_fmts fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2]; 
  [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]"-map 1:v -map [out]
  -c:v copy -c:a aac -strict -2  output2.mp4`

And I get errors such as

[Parsed_aformat_2 @ 037f8620] Error parsing sample format: sample_fmts fltp. [AVFilterGraph @ 038be620] Error initializing filter 'aformat' with args 'sample _fmts fltp:sample_rates=44100:channel_layouts=stereo' Error initializing complex filters. Invalid argument

Does anyone know how to make the code I've code above that is working, also change the volume of the inputs?

Thanks

like image 746
beek Avatar asked Jun 23 '17 04:06

beek


1 Answers

If you want to use amix I would suggest using it like this:

ffmpeg -i video.mp4 -i audio.mp3 -filter_complex \
"[0:a]volume=0.8[a0]; \
[1:a]volume=0.8[a1]; \
[a0][a1]amix=inputs=2[a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -shortest output.mp4 ;

For the amerge method:

ffmpeg -i video.mp4 -i audio.mp3 -filter_complex \
"[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a0]; \
[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a1]; \
[a0][a1]amerge,pan=stereo|c0<c0+c2|c1<c1+c3 [a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -strict -2 -shortest output.mp4 ;

Something to keep in mind per comments from Mulvya:

amerge terminates with the shortest input (always) and amix terminates with the longest input, by default. So the former will always truncate when streams are of different length.

-y flag omitted for testing purposes.

like image 101
l'L'l Avatar answered Sep 22 '22 10:09

l'L'l