Time-Lapse Image Conversion using FFmpeg
This article aims to provide a detailed guide on converting time-lapse images to the Rec.709 color space using FFmpeg.
Understanding Rec.709
Rec.709 is a standard for high-definition television (HDTV) that defines the color space and gamma characteristics for the Y'CbCr and RGB color spaces used in HDTV. It is essential to convert images to this color space when working with HDTV content.
Converting Images to Rec.709 using FFmpeg
FFmpeg is a powerful tool for handling multimedia files. To convert images to the Rec.709 color space, you can use the ffmpeg command with the -pix_fmt yuv420p option, which sets the output pixel format to the Rec.709-compatible Y'CbCr 4:2:0 format.
Example
Let's say you have a series of JPEG images in the current directory, and you want to convert them to the Rec.709 color space:
ffmpeg -framerate 25 -i image%04d.jpg -pix_fmt yuv420p converted_image%04d.yuv
In this example, -framerate 25 sets the frame rate to 25 frames per second, which is the standard frame rate for HDTV. -i image%04d.jpg specifies the input image file pattern, where %04d is a placeholder for the image number, padded with zeros to ensure four digits. The output files will be named converted_image%04d.yuv.
Adjusting Gamma
By default, FFmpeg assumes a gamma of 2.2 for Rec.709 content. If your images have a different gamma, you can adjust it using the -gamma option. For example, to set the gamma to 2.4, use:
ffmpeg -framerate 25 -i image%04d.jpg -pix_fmt yuv420p -gamma 2.4 converted_image%04d.yuv
Code Example
Here's a code example of converting images using FFmpeg in a Bash script:
#!/bin/bash
# Set frame rate and input/output file patterns
framerate=25
input_pattern="image%04d.jpg"
output_pattern="converted_image%04d.yuv"
# Loop through images and convert each one
for i in $(seq 0 $(ls -1 $input_pattern | wc -1)); do
ffmpeg -framerate $framerate -i $input_pattern $i -pix_fmt yuv420p $output_pattern $i
done