Smallest Possible Video File in H.264 Format I am writing some unit-tests for a software that does some work with videos.  To do so, I need a programmatically generated video file that is both small and legitimate in that it is actually a sensible video from the point of view of a codec. 

An idea that came to mind was to produce a video of a single frame of a solid color. I have tried that in Apple Motion. However, the file still ended up being about 8KBs. That is not so big, but I am wondering if one can do better.

Do you have any advice on how? I would be happy with MP4 container.

To give you an example of what I may be after, here is a list of HEX codes that produces a small but valid .PNG image:

png_hex = ['\x89', 'P', 'N', 'G', '\r', '\n', '\x1a', '\n', '\x00',
           '\x00', '\x00', '\r', 'I', 'H', 'D', 'R', '\x00',
           '\x00', '\x00', '\x01', '\x00', '\x00', '\x00', '\x01',
           '\x08', '\x02', '\x00', '\x00', '\x00', '\x90',
           'w', 'S', '\xde', '\x00', '\x00', '\x00', '\x06', 'b', 'K',
           'G', 'D', '\x00', '\x00', '\x00', '\x00',
           '\x00', '\x00', '\xf9', 'C', '\xbb', '\x7f', '\x00', '\x00',
           '\x00', '\t', 'p', 'H', 'Y', 's', '\x00',
           '\x00', '\x0e', '\xc3', '\x00', '\x00', '\x0e', '\xc3',
           '\x01', '\xc7', 'o', '\xa8', 'd', '\x00', '\x00',
           '\x00', '\x07', 't', 'I', 'M', 'E', '\x07', '\xe0', '\x05',
           '\r', '\x08', '%', '/', '\xad', '+', 'Z',
           '\x89', '\x00', '\x00', '\x00', '\x0c', 'I', 'D', 'A', 'T',
           '\x08', '\xd7', 'c', '\xf8', '\xff', '\xff',
           '?', '\x00', '\x05', '\xfe', '\x02', '\xfe', '\xdc', '\xcc',
           'Y', '\xe7', '\x00', '\x00', '\x00', '\x00',
           'I', 'E', 'N', 'D', '\xae', 'B', '`', '\x82']
A one frame H264 stream would have to consist of an intra-coded frame, so there is a size floor in effect.

This ffmpeg command produces a 1.7 kiB file

ffmpeg -f lavfi -i color=blue:s=1280x720 -vframes 1 out.mp4


You can save ~200 bytes by lowering the resolution.