Reputation: 571
How can I limit the video duration for a given video? For example, if we are uploading one video that should not exceed more than 5 minutes, I need a command in FFMPEG.
Upvotes: 46
Views: 126716
Reputation: 4711
Just to elaborate a bit further for more detailed use and examples.
As Specified in the FFMpeg Docs
-t duration
(input/output)
ffmpeg
-t 5
-i input.mp3 testAsInput.mp3
ffmpeg -i input.mp3
-t 5
testAsOutput.mp3
-to position
(input/output)
to
instead of t
duration
or position
must be a time duration specification, as specified in the ffmpeg-utils(1) manual.
[-][HH:]MM:SS[.m...]
or [-]S+[.m...][s|ms|us]
-to
and -t
are mutually exclusive and -t has priority.
Note: -f pulse -i 1
is my system audio , -f pulse -i 2
is my micrphone input
Lets imagine I want to record both my microphone and speakers at the same time indefinetly.(until I force a stop with Ctrl+C)
ffmpeg \
-f pulse -i 1 \
-f pulse -i 2 \
-filter_complex "amix=inputs=2" \
testmix.mp3
ffmpeg \
-t 5 -f pulse -i 1 \
-f pulse -i 2 \
-filter_complex "amix=inputs=2:duration=longest" \
testmix.mp3
Note: :duration=longest
amix option is the default anyway, so not really needed to specify explicitly
ffmpeg \
-t 5 -f pulse -i 1 \
-t 10 -f pulse -i 2 \
-filter_complex "amix=inputs=2:duration=longest" \
testmix.mp3
ffmpeg \
-t 5 -f pulse -i 1 \
-f pulse -i 2 \
-filter_complex "amix=inputs=2:duration=longest" \
-t 10 testmix.mp3
Note: With regards to start position
searching/seeking this answer with a bit of investigation I did, may also be of interest.
Upvotes: 15
Reputation: 2228
An example;
ffmpeg -f lavfi -i color=s=1920x1080 -loop 1 -i "input.png" -filter_complex "[1:v]scale=1920:-2[fg]; [0:v][fg]overlay=y=-'t*h*0.02'[v]" -map "[v]" -t 00:00:03 output.mp4
This sets the max time to 3 seconds. Note that the -t has to be just before the output file, if you set it at the start of this command, i.e. ffmpeg -t ....
it will NOT work.
Upvotes: 5
Reputation: 4493
Use the -t option to specify a time limit:
`-t duration'
Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported.
http://www.ffmpeg.org/ffmpeg.html
Upvotes: 70