Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a video's duration in FFMPEG?

Tags:

ffmpeg

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.

like image 602
user872387 Avatar asked Aug 01 '11 09:08

user872387


People also ask

How do I set the duration of a FFmpeg video?

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

How can I get video duration in PHP using FFmpeg?

Show activity on this post. $videoFile = 'addicted. mp4'; $duration = $ffprobe ->streams($videoFile) ->videos() ->first() ->get('duration'); echo $duration; Why I can't receive video information? @VipulJethva you probably need absolute path to the video file.


2 Answers

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

like image 56
marto Avatar answered Oct 03 '22 07:10

marto


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.

like image 31
Roel Van de Paar Avatar answered Oct 03 '22 05:10

Roel Van de Paar