Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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".

like image 834
Mike Avatar asked Sep 30 '17 23:09

Mike


People also ask

Can FFmpeg convert audio?

Just ensure that you have the right extensions and FFmpeg will do the conversion for you. In this case, FFmpeg with re-encode the video and provide it in an mp3 container. That's it and with these two simple commands, you should be able to transcode your audio from one codec to another (or switch containers).

What does C Copy do in FFmpeg?

Recent ffmpeg also has a flag to supply the end time with -to . -c copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.


1 Answers

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.

like image 83
Brad Avatar answered Sep 20 '22 06:09

Brad