beek
beek

Reputation: 3750

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

Upvotes: 7

Views: 8144

Answers (2)

l&#39;L&#39;l
l&#39;L&#39;l

Reputation: 47169

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.

Upvotes: 10

beek
beek

Reputation: 3750

This answer worked https://superuser.com/questions/715254/the-following-filters-could-not-choose-their-formats-parsed-amerge-5-consider-i

> ffmpeg -i audio.mp3 -i  video.mp4 -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 -shortest output.mp4

Tho it did throw a few errors that didn't seem to stop it

frame= 93 fps=0.0 q=-1.0 size= 642kB time=00:00:03.78 bitra frame= 224 fps=224 q=-1.0 size= 1595kB time=00:00:09.28 bitra Error while decoding stream #1:1: Error number -12 occurred Last message repeated 158 times frame= 274 fps=182 q=-1.0 size= 2382kB time=00:00:11.35 bitra Error while decoding stream #1:1: Error number -12 occurred

Upvotes: 2

Related Questions