Following this question I decided to use ffmpeg to crop MP3s. On another question I found this way of doing it:
ffmpeg -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3
The problem is that I don't want to crop the first 30 seconds, I want to crop from x to x+n, like from 30s to 100s. How would I go and do this?
I'm reading the man for ffmpeg but this is not really straightforward, especially since I just discovered about ffmpeg and I'm not familiar with audio/video editing softwares, so any pointers would be appreciated.
FFmpeg is a great tool for quickly changing an AV file's format or quality, extracting audio, creating GIFs, and more.
Take a look at the -t and -ss arguments. They should do what you want.
-t duration
Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported.
-ss position'
Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported.
For example, ffmpeg -ss 30 -t 70 -i inputfile.mp3 -acodec copy outputfile.mp3
should do the trick for the range you mentioned (30s-100s).
To expand a bit on Michael Madsens' Answer:
I've found either of the following satisfactory for trimming my audio files:
ffmpeg -ss
<start position>-t
<duration> -i inputfile -c:a copy outputfile
ffmpeg -ss
<start position>-i inputfile -t
<duration> -c:a copy outputfile
Note: -acodec
is an alias for codec:a
which can be specified also as c:a
As specified in the Main Options FFMPEG Documentation
-t duration (input/output)
-ss position (input/output)
duration
and position
follow the Time Duration Syntax :
[-][HH:]MM:SS[.m...]
or [-]S+[.m...][s|ms|us]
Side Note: An answer on How to detect intervals of silence with FFMPEG may also be of interest.
Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved.
I did a couple Tests on the following file:
Input #0, mp3, from 'test16s.mp3': Duration: 00:00:16.20, start: 0.025057, bitrate: 128 kb/s Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
Aligned the outputs in Audacity in comparison to the original and got the following:
ffmpeg -ss 3 -t 5 -i test16s.mp3 -c:a copy out.mp3
ffmpeg -ss 3 -i test16s.mp3 -t 5 -c:a copy out.mp3
ffmpeg -i test16s.mp3 -ss 3 -t 5 -c:a copy out.mp3
ffmpeg -t 5 -i test16s.mp3 -ss 3 -c:a copy out.mp3
In an attempt to get to see the seek jump I found interesting results using :
ffmpeg -ss
<secs> -i test16s.mp3 -t 5 -c:a copy out.mp3
ffmpeg -ss
<secs> -t 5 -i test16s.mp3 -c:a copy out.mp3
Concluding that with a Stream Copy, appears as if the minimal seek resolution in my specific file ,(Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s), was:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With