This section contains notes on creating timelapse video's using ffmpeg and a video source like a webcam.
Examples
An example timelapse of a 3D print taken with an Insta360 One R camera in webcam mode and ffmpeg
This the multi-page printable view of this section.Click here to print.
This section contains notes on creating timelapse video's using ffmpeg and a video source like a webcam.
An example timelapse of a 3D print taken with an Insta360 One R camera in webcam mode and ffmpeg
Here we have a WebCam (Insta360 One-R with 4K camera mod) presenting itself as /dev/video1 on a Raspberry PI
To capture images every 10 seconds we can use:
1ffmpeg -f v4l2 -i /dev/video1 -r 1/10 out%08d.jpg
Here -i /dev/video1
is the camera's device,
-r 1/10
is the capturing framerate, 1 in every 10 seconds
and out%08d.jpeg
is the filename for each frame generated.
Parameter | Description |
---|---|
-f v4l2 | Tell ffmpeg we are reading from v4l2 (Video For Linux 2) |
-i /dev/video1 | The V4L2 device of the camera to capture from |
-r 1/10 | The frame rate |
out%08d.jpg | The frame filename to write. |
Here the frame rate is the capture rate in frames per second. So 1/10 means that we capture a single frame once every 10 seconds.
For the frame filename pattern, %08d will be replaced by the frame number, in this case 8 digits with leading 0's.
To create an mp4 from these frames:
1ffmpeg -r 30 -start_number 1 -i out%08d.jpeg -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
Note there are two -r
parameters for the frame rate.
The first one is the source frame rate.
The second one is the output frame rate of the final video.
Parameter | Description | Notes |
---|---|---|
-r 30 | The source frame rate. | This can be either lower than, equal or greater to the output rate |
-start_number 1 | The start frame number. | This is optional and will default to 1 if omitted. |
-i out%08d.jpeg | The source frame filename format | This should match that used to create the frames |
-c:v libx264 | Video encoding format | |
-r 30 | Output frame rate | |
-pix_fmt yuv420p | Output video frame format |
For the source frame rate, do not confuse this with the capture frame rate. Instead, set it to how fast you want the source frames to be read in at when creating the video.
For example: When generating a 30fps video, and you want each frame image to be exactly one frame from the source then set it to 30 here and for the output frame rate.
If you want the output to be 30 fps but the input at just 10fps (so one source frame is 3 in the output) then set the input to 10 and the output as 30.
Setting the source to a value larger than the input will cause frames to be dropped from the source.