To set the duration of a media file, we can use the -t option which value is a time in seconds or in a format HH:MM:SS.milliseconds. For example to set a 3 minutes duration for the music.mp3 file, we can use the command
ffmpeg -i music.mp3 -t 180 music_3_minutes.mp3
Setting with number of frames
In certain cases it may be useful to set the duration of recording by specifying the number of frames with available options
- audio: -aframes number or -frames:a number
- data: -dframes number or -frames:d number
- video: -vframes number or -frames:v number
The number of frames is equal to the duration in seconds multiplied by the frame rate. For instance, to set the duration of a video.avi file with a 25 fps frame rate to 10 minutes (600 seconds), we can use the command:
ffmpeg -i video.avi -vframes 15000 video_10_minutes.avi