Ffmpeg mixing audio only for n number of videos using offset with an altered duration - audio

I want to mix audio stream of n amount of video files with ffmpeg, with certain parameters such as:
Duration: I want to specify how long each audio is going to play for each output. For example if I specify ffmpeg -i -d:5 first.mp4 -i second.mp4 it should play the audio from first.mp4 for 5 seconds (I don't know if -d:5 is a real tag it's just an example I've made ).
Starting point: I want to specify when a given file is going start on the output, I probably need to use -itsoffset 5 but I don't know if it's the right one in terms of interacting with other commands, in on itself it works fine. For example: ffmpeg -i -isoffset 5 first.mp -i second.mp4 causes the second.mp4 to start immediately, and first.mp4 to start after 5 seconds.
Segmentation: This is the tricky one, I want to specify at which point the input's audio should start. It's like the -ss flag but the problem is it's not working together with -itsoffset. For example when I say ffmpeg -i -ss 5 first.mp4 -i second.mp4 both files should start immediately on the output, but first.mp4 should start on it's 5 seconds. So the 5th second of first.mp4 is heard at the 1st second of the output.
This is what I'm trying to achieve, my problem is that I don't know how to implement 'duration' and -ss is not working together with -itsoffset.
At the end I should have something similar to this:
ffmpeg -y -d 5 -itsoffset 3.5 -i first.mp4 -d 10 -ss 10 -itsoffset 5.3 -i 3 -vn -copyts -async 1 -filter_complex amix=inputs=2 out.mp
Which should result in an audio that sounds like this: The first 3.5 seconds are empty, no audio is heard. Then first.mp4 is heard from it's beginning for 5 seconds. When the outputs timestamp reaches 5.3, the 10th seconds of second.mp4 is heard (while first.mp4 is still playing, it's supposed to play until 8.5, so I should hear both files at the same time.) for 10 seconds.
I can't find an example of this and some sources are out-of date.

Try something like this:
ffmpeg -t 5 -ss 0 -i first.mp4 \
-t 10 -ss 10 -i second.mp4 \
-filter_complex \
[0:a]adelay=3500:all=1[c1];\
[1:a]adelay=5300:all=1[c2];\
[c1][c2]amix=inputs=2[aout] \
-map [aout] out.mp3

Related

Using ffmpeg to cut audio from/to position

I need to cut parts from an audio file from position to position. When I tried this command
ffmpeg -ss 132 -t 139 -i original.mp3 new.mp3
it started at the second 132, and added the next 139 seconds to the new file.
What I need is from second 132 to second 139.
And when I tried
ffmpeg -ss 132 -to 139 -i original.mp3 new.mp3
it gives me an error:
Unrecognized option 'to'
Failed to set value '139' for option 'to'
(I don't want to tell how many seconds to take, just from/to).
--
I have ffmpeg version 0.8.20-6:0.8.20-0+deb7u1 (built on Jan 19 2017 11:13:36 with gcc 4.7.2). And when I try to update it (apt-get install ffmpeg), it tells me "ffmpeg is already the newest version".
With FFmpeg the ordering of parameters is significant. All of the parameters that come directly before an input will apply to that input. The same is true for an output... the parameters directly before it apply to the output.
Consider this command line:
ffmpeg -ss 132 -i input.mp3 output.mp3
-ss is the parameter to seek, so FFmpeg will seek the input file to 132 seconds in and treat that effectively at 00:00:00. The rest of your FFmpeg commands relative to the output don't know or care where that input came from or how it was seeked. Therefore, when you use -to or -t, the times or lengths given need to be relative to the input. That is, if you want seconds 132 through 139, you want to seek the input to 132 (-ss 132 -i input.mp3), and then run the output for 7 seconds (-t 7 output.mp3 or -to 00:00:07 output.mp3).
You can read more about this, as well as details about frame-accurate or not (for re-encoding or not) on the documentation: https://trac.ffmpeg.org/wiki/Seeking
As for -to not being there...
As I shown above, I have the latest version of the software.
You absolutely positively do not remotely have the latest version of FFmpeg. You might have the latest build of whatever branch whatever package manager has, and it may have been built this year, but if you check the download page, the latest release as of this writing is 3.3.4. https://www.ffmpeg.org/download.html
You can either deal with your package manager and dependency hell, or depending on your licensing restrictions, snag a recent static build: https://www.johnvansickle.com/ffmpeg/
Finally, consider -acodec copy to ensure you're not hurting the quality of your audio further by transcoding, since you're keeping the same format.
This works for me
ffmpeg -ss 60 -i input-audio.aac -t 15 -c copy output.aac
-ss 60 means, "start from second 60"
-t 15 audio output length in seconds.. in this case, 15 seconds..
ffmpeg -i "original.mp3" -ss 60 -to 70 "new.mp3"
This works for me.
-ss is an input option, while -t and -to are output options. So you need to do this:
ffmpeg -ss 60 -i 'les nuits 128k.m4a' -to 70 -c copy out.m4a
To Trim Audio file using FFmpeg
startDuration = 00:00:00,
endDuration = 00:00:10
audioPath = audio.mp3,
mp3Output = outputFile.mp3
cmd = "-ss $startDuration -i $audioPath -c copy -t $endDuration $mp3Output"
for Mac:
brew install ffmpeg
ffmpeg -ss start_second -to end_second -i input.mp3 output.mp3

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

ffmpeg - slideshow from set of images ignoring first image

I can create slideshow with below command
ffmpeg -y -f image2 -r 1/15 -i image%d.jpeg -y -r 45 video.mp4
Video is created successfully ,, but its ignoring the 1st image..
for example in current folder i have
image1.jpeg
image2.jpeg
image3.jpeg
but slide show is created with image2.jpeg and image3.jpeg only..(i.e 30 second video with 2 image is created..but i expected 45 second video with 3 images displaying 15 sec per image)
What's wrong with your command is the -r 45 as an output option. You're telling ffmpeg to produce a video with 45 fps output rate. You probably don't want that.
Use the fps filter to set the framerate:
ffmpeg -r 1/15 -i img%d.jpeg -vf fps=25 output.mp4
If you use
ffmpeg -r 1/15 -i img%d.jpeg output.mp4
you will get a video with ~0.07 fps, and three frames, meaning a roughly 45 second long video (3 / 0.07). This gives the expected result, but it might not be playable in all players.
Note:
-y is not needed twice. Only supply it once before -i.
-f image2 is not needed.
Using -r as an output option to force another frame rate skips the first frame immediately in some players. I consider this a bug, which is now reported in this ticket .

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