Mute specified sections of an audio file using ffmpeg - audio

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?

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.

Thanks to #aergistal , it worked for me:
command line:
ffmpeg -i input.mp4 -af "volume=enable='between(t,1,2)':volume=0" output.mp4
nodejs fluent ffmpeg:
ffmpeg('input.mp4').audioFilters("volume=0:enable='between(t,1,2)'").output('output.mp4')

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

Related

How to add audio to video file at a specific time using ffmpeg

I have an avi and a wav file. Let's suppose the video file is one hour long, and the audio file 30 minutes long and it's associated with the last 30 minutes of the video file.
Is there a way to create a new video file with the video and audio combined but audio starting after the first 30 minutes of the video?
You can simply append a silent audio to the beginning of the audio file using aevalsrc filter. To create a 30 sec of silent audio,
aevalsrc=0:d=30
To do this you can use filter_complex with map options. Following is the FFmpeg command I'm suggesting.
ffmpeg -i input_video -i input_audio -filter_complex "
aevalsrc=0:d=30[s1];
[s1][1:a]concat=n=2:v=0:a=1[aout]" -c:v copy -map 0:v -map [aout] output_video
Else you can try amerge and adelay where doc itself has a clear explanation.
Hope this helps you!

FFMpeg - Segment audio to chunks

I have tried this example in order to segment a given video file using ffmpeg into an m3u8 file and smaller chunks (.ts files). This actually worked great. Is it possible to do practically the same thing with audio input?
This was my most promising approach so far (capturing live audio on Windows OS):
ffmpeg -f dshow -i audio="<name of input device>" -acodec libmp3lame -ab 64000 | segmenter - 10 stream stream.m3u8 http://<IP_OF_SERVER>/stream/stream/ 5 1
But this returns this error:
At least one output file must be specified.
Could not open input file, make sure it is an mpegts file: -1
I really would not know how to convert the live audio stream to an mpegts file.
Could anyone please give me a hint?
Thanks a lot

Split a video file into separate video and audio files using a single ffmpeg call?

Background: I would like to use MLT melt to render a project, but I'd like that render to result with separate audio and video files. I'd intend to use melt's "consumer" avformat which uses ffmpeg's libraries, so I'm formulating this question as for ffmpeg.
According to Useful FFmpeg Commands For Converting Audio & Video Files (labnol.org), the following is possible:
ffmpeg -i video.mp4 -t 00:00:50 -c copy small-1.mp4 -ss 00:00:50 -codec copy small-2.mp4
... which slices the "merged" audio+video files into two separate "chunk" files, which are also audio+video files, in a single call; that's not what I need.
Then, ffmpeg Documentation (ffmpeg.org), mentions this:
ffmpeg -i INPUT -map_channel 0.0.0 OUTPUT_CH0 -map_channel 0.0.1 OUTPUT_CH1
... which splits the entire duration of the content of two channels of a stereo audio file, into two mono files; that's more like what I need, except I want to split an A+V file into a stereo audio file, and a video file.
So I tried this with elephantsdream_teaser.ogv:
ffmpeg -i /tmp/elephantsdream_teaser.ogv \
-map 0.0 -vcodec copy ele.ogv -map 0.1 -acodec copy ele.ogg
... but this fails with "Number of stream maps must match number of output streams" (even if zero-size ele.ogv and ele.ogg are created).
So my question is - is something like this possible with ffmpeg, and if it is, how can I do it?
Your command works, but you need to specify mapping with columns instead of dots as so:
ffmpeg -i /tmp/elephantsdream_teaser.ogv -map 0:0 -vcodec copy ele.ogv -map 0:1 -acodec copy ele.ogg
You might want to test with a more recent build of ffmpeg. Mine gave correct errors for your command:
[ogg # 00000000043f8480] Invalid stream specifier: .0.
Last message repeated 3 times
Stream map '0.0' matches no streams.

Export each minute of MP3 into separate WAV

This is definitely a strange question but I'm looking for a way to split an mp3 mix of 60 minutes into 60 separate 1 minute long wav files to use with an audio fingerprinting API like Echonest.
Is this possible in a single ffmpeg command or would I have to run multiple iterations of ffmpeg with a the following values:
-ss is the startpoint in seconds.
-t is the duration in seconds.
You can use the segment muxer in ffmpeg:
ffmpeg -i input.mp3 -codec copy -map 0 -f segment -segment_time 60 output%03d.mp3
For a 4 minute input this results in:
$ ls -m1 output*.mp3
output000.mp3
output001.mp3
output002.mp3
output003.mp3
Since -codec copy enables stream copy mode re-encoding will be avoided. See the segment documentation for more information and examples.

Add audio (with an offset) to video with FFMPEG

I have a 10 minute video and a 50 minute audio mp3.
The video starts at 500 seconds into the audio.
Using FFMPEG, how can I add the the audio to the video but specify a 500 seconds audio offset (So that they sync up)?
EDIT:
Down the bottom of this page it suggests how to specify an offset.
$ ffmpeg -i video_source -itsoffet delay -i audio_source -map 0:x -map 1:y .......
However, when I apply this, it still starts the audio from the start.
We are 8 years later, and the -itsoffset does work.
Exactly as in your linked page:
ffmpeg -i input_1 -itsoffset 00:00:03 -i input_2
Note that you place the -itsoffset switch before the input you want to delay, in this case input_2 will be delayed.
So in your case that the video starts later, you would add -itsoffset 00:08:20 before the video input.
I couldn't get audio to offset properly either, and some searching suggests that -itsoffset is currently broken.
You could try and get/compile an old version of ffmpeg before it broke (which doesn't sound like much fun).
Alternately, you could pad your audio with the necessary silence using something like sox and then combine:
sox -null silence.mp3 trim 0 500 # use -r to adjust sample-rate if necessary
sox silence.mp3 input.mp3 padded_input.mp3
ffmpeg -i in.avi -i padded_input.mp3 out.avi

Resources