Search code examples
video-processingvideo-encoding

Which video encoding algorithm should I use for a video with just one static image and sound?


I'm doing video processing tasks and one of the problems I need to solve is choosing the appropriate encoding algorithm for a video that has just one static image throughout the entire video.

Currently I tried several algorithms, such as DivX and XviD, but they produce 3MB video for a 1 minute long video. The audio is 64kbit/s mp3, so the audio takes just 480KB. So the video is 2.5MB!

As the image in the video is not changing, it could be compressed really efficiently as there is no motion. The image size itself (it's a jpg) is just 50KB.

So ideally I'd expect this video to be about 550KB - 600KB and not 3MB.

Any ideas about how I could optimize the video so it's not that huge?

I hope this is the right stackexchange forum to ask this question.


Solution

  • Set the frames-per-second to be very low. Lower than 1fps if you can. Your goal would be to get as close to two keyframes (one at the start, and one at the end) as possible.

    Whether you can do this depends on the scheme/codec you are using, and also the encoder.

    Many codecs will have keyframe-related options. For example, here are some open-source encoders:

    lavc (libavcodec):

    keyint=<0-300> - maximum interval between keyframes in frames (default: 250 or one keyframe every ten seconds in a 25fps movie.

    This is the recommended default for MPEG-4). Most codecs require regular keyframes in order to limit the accumulation of mismatch error. Keyframes are also needed for seeking, as seeking is only possible to a keyframe - but keyframes need more space than other frames, so larger numbers here mean slightly smaller files but less precise seeking. 0 is equivalent to 1, which makes every frame a keyframe. Values >300 are not recommended as the quality might be bad depending upon decoder, encoder and luck. It is common for MPEG-1/2 to use values <=30.

    xvidenc:

    max_key_interval= - maximum interval between keyframes (default: 10*fps)

    Interestingly, this solution may reduce the ability to seek in the file, so you will want to test that.