Export each minute of MP3 into separate WAV - audio

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.

Related

filesize is not growing as expected

I am trying to record a stream here on my machine to study ffmpeg library,
but with(out) success.
I have a file watcher to clean up bugged streams, that cleanup each 3 minutes files that have been not changed less then 3 minutes.
The real problem is, if I use the command below:
/usr/bin/ffmpeg -i http://sysrad.net:10090/ -y test.mp3
this command doesn't have any kind of codec or audio transformation, so my target file (test.mp3) become 256k quickly, but, if I use this command below:
/usr/bin/ffmpeg -i http://sysrad.net:10090/ -y -b:a 8k -ac 1 -ar 11025 test.mp3
My target file (test.mp3) keep 0k until the record has 256k, I am not sure if this is an Unix problem or ffmpeg problem.
Other information, if I run in loop:
while true; do wc -l teste.mp3; sleep 0.5; done;
test.mp3 file keeps 0 rows, until has 256k size...
I have no idea how to workaround that, to get the real time file size for each 1k that ffmpeg get from stream with those codecs, does you guys have any idea how can I handle that?
Thanks!!!!

How do you replace audio at a given timestamp with ffmpeg?

I am trying to use the ffmpeg library to take two FLAC files and replace the audio in File A with the audio in File B at a given timestamp.
For example if File B was to be played at 00:02 and was a second long, playing the output it would be (00:00-0:01) File A Audio -> (00:02-0:03) File B Audio -> (00:04-...) File A Audio
To do this, I have tried the following
ffmpeg -y -i original.flac -i replacement.flac -acodec copy -ss 2 -to 3 -write_xing 0 result.flac
But this only produces the original audio between the specified timestamps.
Is there any way to achieve this within ffmpeg?
The typical method to do this would be the concat demuxer, but there are issues with FLAC extraction with duration header in the output, so you can use
ffmpeg -y -i original.flac -i replacement.flac \
-filter_complex "[0]atrim=0:2[Apre];[0]atrim=5,asetpts=PTS-STARTPTS[Apost];\
[Apre][1][Apost]concat=n=3:v=0:a=1" out.flac
Where 2 is the insertion point in seconds, and 5 is the insertion point + B's duration.

FFMPEG merging audio and video to get resulting video

I need to merge audio and video using ffmpeg so that, it should result in a video with the same duration as of audio.
I have tried 2 commands for that requirement in my linux terminal. Both the commands work for a few of the input videos; but for some other input_videos, they produce output same as the input video, the audio doesn't get merged.
The commands, I have tried are -
ffmpeg -i wonders.mp4 -i Carefull.mp3 -c copy testvid.mp4
and
ffmpeg -i wonders.mp4 -i Carefull.mp3 -strict -2 testvid.mp4
and
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -strict
experimental output.mp4
and these are my input videos -
samplevid.mp4
https://vid.me/z44E
duration - 28 seconds
size - 1.1 MB
status - working
And
wonders.mp4
https://vid.me/gyyB
duration - 97 seconds
size - 96 MB
status - not working
I have observed that the large size (more than 2MB) of the input video is probably the issue.
But, still I want the fix.

Mute specified sections of an audio file using ffmpeg

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

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