Read more

Creating a sample video with ffmpeg

Martin Schaflitzl
March 15, 2023Software engineer at makandra GmbH

If you need a sample video with certain properties for a test you can create one using ffmpeg.
You might want a very low bitrate file to speed up processing in your test. (e.g. you only care about the length, then you can create a video with a very low resolution and framerate)

Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show snapshot

Create a 21s video with 1fps and 10x10 resolution:
ffmpeg -t 21 -s 10x10 -r 1 -f rawvideo -pix_fmt rgb24 -i /dev/zero sample_21_seconds.mp4

Option Explanation
-t 21 set the length to 21s
-s 10x10 set the resolution the 10 by 10 pixel
-r 1 set the framerate to 1 frame pre second
-i /dev/zero Source for the pixel data, /dev/zero creates an all black video, if you want some random noise use /dev/random

To verify the properties of the video use ffprobe

$ ffprobe sample_21_seconds.mp4 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample_21_seconds.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:21.00, start: 0.000000, bitrate: 0 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 10x10, 0 kb/s, 1 fps, 1 tbr, 16384 tbn, 2 tbc (default)
      handler_name    : VideoHandler
$ ls -sh sample_21_seconds.mp4 
4,0K sample_21_seconds.mp4

The result is a very small video file, but still with a length of 21 seconds.

Posted by Martin Schaflitzl to makandra dev (2023-03-15 15:54)