35

I have a JSON file containing regions that I want to mute in a given audio file. How can I process the audio file to mute the file between the listed sections?

3
  • you could cut out the pieces and piece them back together... Commented Mar 23, 2015 at 19:58
  • I thought about that but it seems a very messy thing to do: as it requires chopping out the parts with audio I want in, then generating bits of silence, then concatenating, and hoping it doesn't end up with clicks where the merges are. Below solution works perfectly! Commented Mar 24, 2015 at 12:28
  • there is a "select" filter I wonder if it can work for audio... Commented Mar 24, 2015 at 15:09

2 Answers 2

64

The following command will mute two sections: between 5-10s and 15-20s:

ffmpeg -i video.mp4 -af "volume=enable='between(t,5,10)':volume=0, volume=enable='between(t,15,20)':volume=0" ...

Description:

-af is the audio filter. It works by specifying multiple volume filters that are enabled/disabled at the specified time. volume=enable='between(t,5,10)':volume=0 means use a volume filter that gets enabled between 5 and 10 seconds and sets the volume to 0.

Sign up to request clarification or add additional context in comments.

7 Comments

That works perfectly, thankyou! Could you explain how it works?
-af is the audio filter. It works by specifying multiple volume filters that are enabled/disabled at the specified time. volume=enable='between(t,5,10)':volume=0 means use a volume filter that gets enabled between 5 and 10 seconds and sets the volume to 0.
What are the min and max value can i give here at volume=0 ?
If you want it to run more quickly, add -vcodec copy to the command, it will make it so the video is not re-encoded (which is fine if you only need to edit the audio). e.g.: ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='between(t,5,10)':volume=0, volume=enable='between(t,15,20)':volume=0" out.mp4
Note that the 'between' input is an expression that resolves to a number. So to silence between 26:40 and 26:42, you'd do 'between(t,26*60+40,26*60+42)'. It also supports floating point numbers (.e.g, 'between(t,26*60+40+0.5,26*60+42)' ).
|
2

I came across this post because I was trying to see how to lower sections of audio in a video.

For example, I want the volume between 34 to 35 minutes, 37 to 40 minutes, 0.1 times of the input volume. Below works for me and hope it works for others who are after the same task:

C:\ffmpeg-4.4-full_build\bin>ffmpeg -i in_video.mp4 -filter:a "volume=enable='between(t,34*60,35*60)':volume=0.1, volume=enable='between(t,37*60,40*60)':volume=0.1" -vcodec copy out_video.mp4

Note the time in between needs to be seconds.

Refer to the link below for more info about the audio volume filter (-filter:a). https://trac.ffmpeg.org/wiki/AudioVolume

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.