Create timelapse videos using gstreamer tools

Timelapse videos can easily be created using gstreamer. This tutorial will show various options, explain and demonstrate how to do timelapse videos with gstreamer CLI tools. A basic knowledge of gstreamer is assumed.

We will capture images at some set interval, these images are then later combined into a video file. Command lines are split into multiple lines, enter them as one line only.

Note: This tutorial is still work in progress and we will be adding more examples in the future.

Gstreamer elements we will be using

We will be using the following gstreamer tools and elements, their purpose will be explained after the list.

  • v4l2src
  • videorate
  • jpegdec
  • multifilesrc
  • timeoverlay
  • clockoverlay
  • queue
  • autovideosink

Pipeline elements

  • v4l2src is the video source element we will be using in these examples. The image source could be something else too, for example a live rtsp/hls feed from a network video camera or even just another video file.
  • multifilesrc is a file source element for reading individual frames from multiple numbered files, for example frame_0000.jpg to frame_9999.jpg
  • jpegdec is the jpg file decoder and will decode the jpeg compresses images into a raw image format usable by other elements
  • timeoverley adds a time stamp to frames
  • clockoverlay adds the current date/time to frames
  • queue is used to separate parts of the pipeline to their own threads
  • autovideosink will use the most appropriate video display method for your system

Timelapse capture examples

Timelapse capture, 1 second interval

This command will capture video frame into multiple picture files, every 1 second.

gst-launch-1.0 v4l2src device=/dev/video0 ! queue ! videorate ! video/x-raw,framerate=1/1 ! jpegenc ! multifilesink location="./frame%06d.jpg"

Timelapse capture, 1 second interval, live video view

This command will capture video frame into multiple picture files, every 1 second. It will also show a realtime video in a window with full framerate.

gst-launch-1.0 v4l2src device=/dev/video0 ! tee name=t ! queue ! autovideosink t. ! queue ! videorate ! video/x-raw,framerate=1/1 ! jpegenc ! multifilesink location="./frame%06d.jpg"

With timestamp and clock overlays, with live view

gst-launch-1.0 v4l2src device=/dev/video0 ! timeoverlay halignment=right valignment=bottom ! clockoverlay halignment=left valignment=bottom time-format="%Y/%m/%d %H:%M:%S" ! tee name=t ! queue ! autovideosink t. ! queue ! videorate ! video/x-raw,framerate=1/1 ! jpegenc ! multifilesink location="./frame%06d.jpg"

Change capture interval

Adjust the framerate setting in the command lines, for example to capture every 10 seconds, use "framerate=1/10"

Creating timelapse video from images

These exmaple will show how to create a timelapse video from captured image frames. The example assumes that the image files are named in the format "frame000000.jpg" and start from index 0, the default for multifilesrc.

Create OGG Theora video

This will create an OGG Theora encoded video, with the framerate of 30 frames per second

gst-launch-1.0 multifilesrc location="frame%06d.jpg" caps="image/jpeg,framerate=30/1" ! jpegdec ! theoraenc ! oggmux ! filesink location="out.ogg"

Create H.264 video files

AVI Container

This will create a H.264 encoded video file in a AVI container.

gst-launch-1.0 multifilesrc location="frame%06d.jpg" caps="image/jpeg,framerate=30/1" ! jpegdec ! x264enc ! avimux ! filesink location="out.avi"

Matroska container

gst-launch-1.0 multifilesrc location="frame%06d.jpg" caps="image/jpeg,framerate=30/1" ! jpegdec ! x264enc ! matroskamux ! filesink location="out.mkv"

Anonymize faces in the video

You might need to anonymize people in the resulting video. Luckily gstreamer comes with element that can be used for this purpose, faceblur. It will slow down the encoding process considerably but might do the trick, it is not very reliable.

gst-launch-1.0 multifilesrc location="frame%06d.jpg" caps="image/jpeg,framerate=30/1" ! jpegdec ! videoconvert ! videorate ! faceblur ! videoconvert ! theoraenc ! oggmux ! filesink location="out_faceblur.ogg"

Create video using ffmpeg

The following command will create a h264 mp4 video with the framerate of 30 frames per second from the images captured using any of the above methods. Resolution of the resulting video will be the same as for the image files.

ffmpeg -framerate 30 -i frame%06d.jpg out.mp4

If you would like to change the output resolution, add a video scale filter:

ffmpeg -framerate 30 -i frame%06d.jpg -vf scale=800:480 out_scaled.mp4

Example timelapse video

Frames where captured using a Raspberry Pi Zero, Raspberry Pi Camera v1 in ZeroView setup.
Images where captured every 5 seconds under a duration of about 2 hours using raspistill in Full-HD size. The images where then made into a video, 30 fps, cropped a bit from top and bottom, using gstreamer, with the following pipeline:

gst-launch-1.0 multifilesrc location="frame_%05d.jpg" caps="image/jpeg,framerate=30/1" ! queue ! jpegdec ! videoconvert ! queue ! videocrop top=40 bottom=312 ! timeoverlay halignment=right valignment=bottom ! videoconvert ! queue ! x264enc pass=5 ! queue ! matroskamux ! progressreport ! queue ! filesink location="out.mkv"