<p>A one frame H264 stream would have to consist of an intra-coded frame, so there is a size floor in effect.</p>

<p>This ffmpeg command produces a 1.7 kiB file</p>

<pre><code>ffmpeg -f lavfi -i color=blue:s=1280x720 -vframes 1 out.mp4
</code></pre>

<p>You can save ~200 bytes by lowering the resolution.</p>

CC BY-SA 4.0
2019-11-12T17:21:36.067Z
Out of interest, why blue?
stib
CC BY-SA 4.0
2019-11-12T17:52:13.957Z
No reason in particular.
Gyan
CC BY-SA 4.0
2019-11-12T23:46:16.013Z
I tested it and found that if you use white instead you save 6 bytes.
stib
CC BY-SA 4.0
2019-11-13T00:07:46.370Z
There's a lot of plain text in the header, e.g. there's a copyright notice and a URL `H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html`. I tried just yeeting it out with a text editor but the resultant file wouldn't play. I'd say you could optimise it a bit more by studying the mp4 file format more than I have time to do: http://xhelmboyx.tripod.com/formats/mp4-layout.txt
stib
CC BY-SA 4.0
2019-11-13T05:33:18.793Z
That's not MP4 data, but SEI unit inserted by the x264 encoder. Yeah, that could be filtered out. I wasn't trying to absolutely optimize the size.
Gyan
CC BY-SA 4.0
2019-11-07T06:01:22.310Z
2019-11-07T06:01:22.310Z
Gyan
<p>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. </p>

<p>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.</p>

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

<p>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:</p>

<pre><code>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']
</code></pre>

CC BY-SA 4.0
2019-11-12T17:20:48.433Z
This almost sounds like a job for code golf. https://codegolf.stackexchange.com/
stib
CC BY-SA 4.0
2019-11-12T21:34:20.467Z
I am familiar with code golf and even played some. How do you reckon this is a good fit? :-)
MadPhysicist
CC BY-SA 4.0
2019-11-12T23:43:28.113Z
Well if you consider writing a h.264 file could be considered writing code—it's a piece of code that gets rendered to produce an image, juts like a piece of html gets rendered to produce a web page. Maybe a stretch, and I don't know how many golfers would be familiar with the intricacies of h.264, but it's trying to produce the smallest valid piece of code.
stib
<video><codec><mp4><h.264>
Smallest Possible Video File in H.264 Format
MadPhysicist
# Smallest Possible Video File in H.264 Format

(Asked by: username_0 on 2019-11-07)

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']

**Tags:** video, codec, mp4, h.264

> **Comments:**
> **username_1**: This almost sounds like a job for code golf. https://codegolf.stackexchange.com/  
> **username_0**: I am familiar with code golf and even played some. How do you reckon this is a good fit? :-)  
> **username_1**: Well if you consider writing a h.264 file could be considered writing code—it's a piece of code that gets rendered to produce an image, juts like a piece of html gets rendered to produce a web page. Maybe a stretch, and I don't know how many golfers would be familiar with the intricacies of h.264, but it's trying to produce the smallest valid piece of code.  

---

## 1 answers

### Answer by username_2 on 2019-11-07. Score: 5 | Accepted answer

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.

> **Comments:**
> **username_1**: Out of interest, why blue?  
> **username_2**: No reason in particular.  
> **username_1**: I tested it and found that if you use white instead you save 6 bytes.  
> **username_1**: There's a lot of plain text in the header, e.g. there's a copyright notice and a URL `H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html`. I tried just yeeting it out with a text editor but the resultant file wouldn't play. I'd say you could optimise it a bit more by studying the mp4 file format more than I have time to do: http://xhelmboyx.tripod.com/formats/mp4-layout.txt  
> **username_2**: That's not MP4 data, but SEI unit inserted by the x264 encoder. Yeah, that could be filtered out. I wasn't trying to absolutely optimize the size.  

---

