Creating a sample video with ffmpeg

Posted About 1 year ago. Visible to the public.

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)

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.

Martin Schaflitzl
Last edit
About 1 year ago
Martin Schaflitzl
Source code in this card is licensed under the MIT License.
Posted by Martin Schaflitzl to makandra dev (2023-03-15 14:54)