Create time lapse video from images: Difference between revisions

From WickyWiki
mNo edit summary
Line 46: Line 46:
== Add music, crop ==
== Add music, crop ==


The original video-length is the length when we create the video without 'setpts=~'. The images will be read as a steam of 25 pictures per second. For example:
The original video-length is the length when we create the video without 'setpts=~'. The images will be read as a stream of 25 pictures per second (input framerate=25). For example:


   2500 pictures -> 2500/25 = 100 seconds of video = 1:40 minutes
   2500 pictures -> 2500/25 = 100 seconds of video = 1:40 minutes

Revision as of 20:26, 21 March 2019


Create timelapse

Install ffmpeg:

sudo apt install ffmpeg

Create timelapse indexfile:

sourcedir=$HOME/Pictures/timelapse

find "${sourcedir}" -iname "*.jpg" -type f | sort | sed "s/\(.*\)/file '\1'/g"  > "${sourcedir}/../files.txt"

Create the video:

ffmpeg -f concat -safe 0 -i "${sourcedir}/../files.txt" -r 25 -vcodec libx264 -crf 22 "${sourcedir}/../out.mp4"

Tuning

Increase the playback speed

Increase the playback speed (x2), the resulting file will be smaller:

ffmpeg -f concat -safe 0 -i "${sourcedir}/../files.txt" -vf "setpts=(PTS-STARTPTS) / 2" -r 30 -vcodec libx264 -crf 22 "${sourcedir}/../out_fast.mp4"

Crop the picture

 crop=<width>:<height>:<left>:<top>
ffmpeg -f concat -safe 0 -i "${sourcedir}/../files.txt" -filter:v "crop=1280:800:0:224" -r 25 -vcodec libx264 -crf 22 "${sourcedir}/../out.mp4"

Add music, crop

The original video-length is the length when we create the video without 'setpts=~'. The images will be read as a stream of 25 pictures per second (input framerate=25). For example:

 2500 pictures -> 2500/25 = 100 seconds of video = 1:40 minutes

Lets say you have some music and want to speed-up the video to match the music length

 Music length 1:30 minutes

Then use the following video filter to shorten the video

 setpts=(PTS-STARTPTS) * <music-length> / <video-length>

You can input this as a simple formula:

 setpts=(PTS-STARTPTS)*(1*60+30)/(1*60+40)

Complete example including crop:

ffmpeg -f concat -safe 0 -i "${sourcedir}/../files.txt" -i "${sourcedir}/../music.mp3" -filter:v "setpts=(PTS-STARTPTS)*(1*60+30)/(1*60+40), crop=1280:800:0:224" -r 35 -vcodec libx264 -crf 22 "${sourcedir}/../out.mp4"

Options

Input indexfile 'files.txt':

 -f concat -safe 0 -i "files.txt"

These options allow for this indexfile format:

     file '/full/path/to/file1.jpg'
     file '/full/path/to/file2.jpg'
     ...

Video filter. Speedup video by (1 / 0.4):

 -vf "setpts=(PTS-STARTPTS)*0.4"

Output framerate:

 -r 30 

Output codec and quality setting 'Constant Rate Factor'. For x264, this means setting a value somewhere between 18 and 26 for this CRF. The default is 23, and higher values will give you worse quality.

 -vcodec libx264 -crf 22

Sources: