There are cases (like academic purposes) that is does make sense to encode a single frame video.
There is an existing image format named HEIF that based on HEVC (H.265) codec, but for H.264, you must encode a video file.
You may use FFmpeg command line tool for creating a single frame video file:
ffmpeg -i input.png -vcodec libx264 -qp 40 -pix_fmt yuv420p single_frame.mp4
(Assuming your input image is input.png
).
The -qp 40
argument applies constant quantization 40.
qp (qp)
Set constant quantization rate control method parameter
See: libx264 documentation
Note:
Since it's a single frame, the frame type is going to be an I-Frame
.
In case you prefer elementary H.264 stream (without MP4 container), you may use:
ffmpeg -i input.png -vcodec libx264 -qp 40 -pix_fmt yuv420p single_frame.264
There are Python bindings for FFmpeg, like ffmpeg-python.
You may use it, for encoding a NumPy array that represents a raw video frame.
You may also use a pipe to FFmpeg sub-process as the following sample.
You can find source code for H.264 encoder in GitHub (here for example).
As far a I know, the sources are implemented in C.
Without looking at the sources, I don't think you are going to consider them as "well-structured".