Do VLC or FFmpeg (or AVconv) have any feature to force the duration of a video to a certain number of seconds?
Let's say I have a... 5 minutes .mp4 video (without audio). Is there a way to have any of the aforementioned tools "expanding" the video to a longer duration? The video comes from a Power Point slideshow, but it's too short (running too fast, to say so). The idea would be automatically inserting frames so it reaches an specified duration. It looks like something pretty doable (erm... for a total newbie in video encoding/transcoding as I am): A 5 minutes video, at 30fps means I have 9000 frames... To make it be 10 times longer, get the first "real" frame, copy it ten times, then get the second "real" frame, copy it ten times... and so on.
I'm using Ubuntu 12.04, but I can install/compile any required software, if needed. So far, I have VLC, AVConv and FFmpeg (FFmpeg in an specific folder, so it won't conflict with AVConv)
Thank you in advance.
Use the setpts video filter in ffmpeg
. Simple examples:
setpts=PTS*2
or setpts=PTS/0.5
setpts=PTS/2
or setpts=PTS*0.5
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/10" output.mp4
For audio use the atempo, rubberband, or asetrate audio filters.
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=PTS/10[v];[0:a]atempo=10[a]" -map "[v]" -map "[a]" output.mp4
In this example audio.wav
duration is 30 seconds and video.mp4
is 90 seconds.
Get the duration of the audio and video files:
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 audio.wav
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.mp4
Use the setpts video filter to adjust the duration of the video to match the audio duration.
ffmpeg -i video.mp4 -i audio.wav -filter_complex "[0:v]setpts=PTS*30/90[v]" -map "[v]" -map 1:a -shortest output.mp4
In this example the input is 120 seconds. Desired output is 30 seconds:
Get the duration of the input file:
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
Use setpts and atempo (or rubberband) filters:
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/(120/30);atempo=120/30" output.mp4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With