View Full Version : Trim and transcode with ffmpeg
Floatingshed
15th February 2021, 12:09
I wonder if someone who knows ffmpeg can help me out here please, I find the options rather confusing.
I have an mp3 audio file. I want to convert it to ogg using ffmpeg, but I want two output files (so two passes I guess).
I need the first 20 seconds of the audio and the last 20 seconds of the audio (in two separate ogg files).
Any ideas please?
Emulgator
15th February 2021, 14:54
https://forum.doom9.org/showthread.php?t=181616
If you ask jlw_4049 nicely, maybe he adds .ogg in a whizz.
https://forum.doom9.org/showthread.php?t=181206
Or ask ProWo.
tebasuna51
15th February 2021, 15:57
I don't know how select the last 20 sec. without know the full duration.
If the mp3 file have a duration of 165 sec. you can try:
ffmpeg -i input.mp3 -filter_complex "asplit [f][l]; [f] atrim=0:20 [ff]; [l] atrim=145:165 [ll]" -map "[ff]" -c:a libvorbis first20.ogg -map "[ll]" -c:a libvorbis last20.ogg
Floatingshed
15th February 2021, 16:53
Thanks, that works perfectly.
Now to figure out how to get the length of the mp3...
tebasuna51
15th February 2021, 22:03
Like mp3 can be VBR you need a tool than read the full mp3 (MediaInfo don't work always).
Maybe LeeAudBi (https://forum.doom9.org/showthread.php?p=1522330#post1522330)
But maybe that can be enough:
ffmpeg -report -i input.mp3
Richard1485
15th February 2021, 22:17
I have an mp3 audio file. I want to convert it to ogg using ffmpeg, but I want two output files (so two passes I guess).
I need the first 20 seconds of the audio and the last 20 seconds of the audio (in two separate ogg files).
Any ideas please?
If you have a version of SoX that is built with mp3 support, you should be able to go straight to ogg.
First 20s:
sox file.mp3 first20s.ogg trim 0 20
Last 20s:
sox file.mp3 last20s.ogg trim -20 -0
If you don't, convert the mp3 to wav first with ffmpeg...
ffmpeg -i file.mp3 file.wav
..and then run the conversions with SoX.
(To get SoX working with mp3 on Debian Buster, I had to run sudo apt install libsox-fmt-mp3. I don't know your OS.)
EDIT: Actually, for the second command especially, going to wav first is probably more robust, given the difficulty with knowing an mp3's duration. Editing an uncompressed file is usually preferable, despite the extra step, because it's more accurate.
First 20s:
sox file.wav first20s.ogg trim 0 20
Last 20s:
sox file.wav last20s.ogg trim -20 -0
It works for me.
Floatingshed
16th February 2021, 13:50
Interesting alternative, I'll check it out. Thanks.
richardpl
16th February 2021, 15:16
SoX is obsolete software.
manolito
16th February 2021, 20:01
SoX is obsolete software.
I would prefer if you could bring yourself to refraining from posting such destructive and arrogant statements.... :mad:
SoX may not be developed any longer, but it still does the things it does at a very high quality. Nobody can seriously state that ffmpeg can do everything with audio what SoX can do.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.