This repo contains scripts used to compile Time-lapse movies using ffmpeg. The ffmpeg utility is controlled via the ffmpeg-python wrapper.
This package requires the
ffmpeg tool to be installed. Moreover, it
should be installed with the
graphviz should be installed to visually inspect the
graph from in to output. When using homebrew use:
brew install ffmpeg --with-freetype brew install graphviz
Then install this package:
pip install -e .
For near-universal compatibility the H.264 codec is used. The following section describe some of the choices for specific configuration options.
See the ffmpeg wiki for additional information: https://trac.ffmpeg.org/wiki/Encode/H.264
Constant Rate Factor
-crf 22 to set a constant rate factor, which means the overall
quality of the movie should be constant. So bitrate varies to ensure
this. Higher value is slower quality. The quality with 22 seems
reasonable. Check if it streams nicely to users on slower bandwidth..
otherwise a high crf (lower quality) might be needed.
-preset slower to improve the compression ratio for the selected
quality (crf), without taking too much time. The slower preset is still
fast enough for me.
-movflags +faststart to allow the movie to quickly start
playing, while it is still loading.
The codec defaults to YUV 444, which is not supported by Quicktime. So
-pix_fmt yuv420p to fix Quicktime support.
Select input frames
Use frames as input by giving a glob pattern which matches the desired
images. Usually these will be tiff images so use
-pattern_type glob -i "*.tiff".
When using image sequences as input the framerate of the desired output
should be given using
Commonly used filters:
- Deflicker https://ffmpeg.org/ffmpeg-filters.html#toc-deflicker
- Scale https://ffmpeg.org/ffmpeg-filters.html#scale
- Crop https://ffmpeg.org/ffmpeg-filters.html#crop
- Drawtext https://ffmpeg.org/ffmpeg-filters.html#drawtext-1
- Video sizes https://ffmpeg.org/ffmpeg-utils.html#video-size-syntax
- First deflicker the video to ensure it is equally deflickered for all outputs
- Then scale and crop the videos to fit the desired final resolutions
- Then add the watermark (which should not be deflickered)
Add scaling to ensure it fits in given dimensions. Negative values for width or height make the encoder figure out the size by itself, keeping the aspect ratio of the source. The integer of the negative value, i.e. 4 for -4, means that the size should be devisble by that value. TODO: does it just scale/squish the video or crop?:
-vf scale=1920:-2 -vf scale=960:540:aspect..
Using time-lapse and ffmpeg-python:
import ffmpeg from time_lapse import output NAME = 'test' PATTERN = '*.tiff' input = ( ffmpeg .input(PATTERN, pattern_type='glob', framerate=24) .filter_('deflicker', mode='pm', size=10) ) output.create_outputs(input, NAME, verbose=False)
verbose=True to create outputs the following ffmpeg-python
inspection methods will be performed.
Show the ffmpeg command options ffmpeg-python would use:
By using graphviz the graph from input to output can be shown using: