Create time lapse video from images: Difference between revisions
mNo edit summary |
|||
| Line 26: | Line 26: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= | = Playback speed, Cropping and Music = | ||
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: | 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: | ||
| Line 50: | Line 40: | ||
setpts=(PTS-STARTPTS) * <music-length> / <video-length> | setpts=(PTS-STARTPTS) * <music-length> / <video-length> | ||
You can | You can add this option as a simple formula: | ||
setpts=(PTS-STARTPTS)*(1*60+30)/(1*60+40) | setpts=(PTS-STARTPTS)*(1*60+30)/(1*60+40) | ||
Note: my source is a set of pictures of size 1280x1024, by cropping this to 1280:800 I will have a 16:10 aspect ratio: | |||
Here is a complete example: | |||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
| Line 62: | Line 54: | ||
= Overview of the used options = | = Overview of the used options = | ||
Input | Input index-file 'files.txt': | ||
-f concat -safe 0 -i "files.txt" | -f concat -safe 0 -i "files.txt" | ||
| Line 70: | Line 62: | ||
-i "music.mp3" | -i "music.mp3" | ||
These options allow for this | These options allow for this index-file format: | ||
file '/full/path/to/file1.jpg' | file '/full/path/to/file1.jpg' | ||
| Line 88: | Line 80: | ||
-r 30 | -r 30 | ||
Output codec | Output codec: | ||
-vcodec libx264 | |||
'Constant Rate Factor' quality setting. 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. | |||
-crf 22 | |||
Sources: | Sources: | ||
Revision as of 20:41, 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"
Playback speed, Cropping and Music
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 by increasing the playback speed:
setpts=(PTS-STARTPTS) * <music-length> / <video-length>
You can add this option as a simple formula:
setpts=(PTS-STARTPTS)*(1*60+30)/(1*60+40)
Note: my source is a set of pictures of size 1280x1024, by cropping this to 1280:800 I will have a 16:10 aspect ratio:
Here is a complete example:
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"
Overview of the used options
Input index-file 'files.txt':
-f concat -safe 0 -i "files.txt"
Add music from mp3 file:
-i "music.mp3"
These options allow for this index-file format:
file '/full/path/to/file1.jpg'
file '/full/path/to/file2.jpg'
...
Video filter. Speedup video x2:
-filter:v "setpts=(PTS-STARTPTS) / 2"
Video filter. crop=<width>:<height>:<left>:<top>:
-filter:v "crop=1280:800:0:224"
Output framerate:
-r 30
Output codec:
-vcodec libx264
'Constant Rate Factor' quality setting. 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.
-crf 22
Sources: