45

I am using ffmpeg for audio conversion. I am using this command:

ffmpeg -i file.mp3 file.wav

This works fine. However I only want to my output file to contain maximum 1 minute of audio. How can I do that using ffmpeg?

Jaggu
  • 6,298
  • 16
  • 58
  • 96

3 Answers3

81

Use the following command:

ffmpeg -ss 0 -t 30 -i file.mp3 file.wav
  • -ss 0 - Start at 0 seconds
  • -t 30 - Capture 30 seconds (from 0, so 0:00 - 0:30). If you want 1 minute of audio, use -t 60.
  • file.mp3 - Input file
  • file.wav - output file
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • 14
    `-t` is actually an output option. The format should be `ffmpeg -ss 0 -i file.mp3 -t 30 file.wav` – Drew Chapin Sep 04 '13 at 23:24
  • 3
    Is there a way to do this without re-encoding? I wrote `ffmpeg -ss 0 -i in.m4a -t 240 out.m4a` and got 128kbps output from 253kbps input. EDIT: I found it, just add `-acodec copy`. – H.v.M. Apr 03 '16 at 19:12
20

This command also works perfect. I cropped my music from 0 seconds to 30 seconds. Here test.mp3 is input file and temp.mp3 is output file.

-ss: Indicates the starting point.

-to: Indicates where to stop.

-y : force output file to overwrite.

ffmpeg -i test.mp3 -ss 00:00:00 -to 00:00:30 -c copy -y temp.mp3
Rahul Chauhan
  • 1,424
  • 14
  • 13
7

Use the -t parameter:

-t duration
Restrict the transcoded/captured video sequence to the duration specified in seconds. "hh:mm:ss[.xxx]" syntax is also supported.

Mat
  • 202,337
  • 40
  • 393
  • 406