ffmpeg to cut beginning and fade in audio
Asked Answered
S

2

6

I've got a bunch of spoken word mp3 files, which all have the same intro talking and music, and then the real content begins. So it goes roughly like this:

00:00 Standard intro spoken word
00:20 Standard intro music
00:35 The content

The timings are not always the same (can vary by 5 secs). So I'd to cut the first 25 seconds and then fade in the next five seconds. And then output the file in the same mp3 format. Is this possible with ffmpeg?

Skullcap answered 14/2, 2022 at 15:20 Comment(0)
D
13

This command should work for you:

ffmpeg -ss 25 -i input.mp3 -af "afade=type=in:start_time=0:duration=5" -c:a libmp3lame output.mp3

-ss 25 will start the input after the first 25 seconds.

afade filter will fade in the audio from the specified start time for the next 5 seconds.

Daune answered 14/2, 2022 at 15:46 Comment(3)
When using ffplay the start_time must be same as -ss. E.G. ffplay "03 Lorelei.m4a" -ss 25 -af "afade=type=in:start_time=25:duration=5"Untwine
@Camille Goudeseune I've just tested your edit and the output is wrong - the sound starts at 25th second with 25 seconds of silence...Daune
@Untwine I've tested this command with ffplay and the parameters seem to work differently here indeed - thanks for the note. But I'm not sure if it should be added to the answer as ffplay is normally used just for temporary play, not to do the cut the question asked.Daune
C
1

I was just looking how to trim the audio in a video and just figured this out:

ffmpeg -i input.mp4 -ss 10 -to 20 -i input.mp4 -map 0:v -map 1:a -c copy -copyts output.mp4

We use -i input.mp4 twice (for video/audio) and select with -map 0:v and -map 1:a.
Then we can put -ss 10 -to 20 before our audio input to trim it.
Then we need -copyts so the audio input begins at the same timestamp.
And we use -c copy to not re-encode so it's faster.

Use -c:v copy if you want to re-encode, since the video doesn't need re-encoding, only the audio.

Hope this helps anyone.

Cathexis answered 31/7 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.