user11462: I am generating an animation in Matlab, composed of simple diagrams. The images are characterized by fine structures, strong contrasts and mostly discrete colors, e.g. there are few-pixels wide black lines, dots or small patches of uniform color, few-pixels high antialiased text, etc. Here's a screen shot of a typical frame:

What changes from frame to frame are the colored patches on the left, the time ("t = "), and the position of the black dot in the right panel.
Using a standard video codec on this which was designed for full-frame moving photographic imagery generates strong artefacts even with weak compression. Without compression however, the video file becomes unmanageably huge.
My question: Is there a video codec that is optimized for this kind of material? If possible, it would be optimal if an encoder is included in ffmpeg, and if there is a decoder (codec implementation) available for Windows.

user17849: If you're OK with formats requiring proprietary encoders, I suggest you check out RealVideo. I haven't been using this format for a while, but I remember 10 years ago I could compress DVD cartoons into < 500 MB RMVB files with very little quality loss, while XviD files of similar bitrate were extremely blocky.
Another codec which sounds suitable at least theoretically is QuickTime RLE.
Surprisingly, although there appears to be modern research on cartoon-like video codecs, none of the efforts got past the "proof of concept" stage.
I suppose your MATLAB animation will be similar to cartoons: few colors used, sharp borders between colors, only a small part of the frame actively changing, etc.

user11462: I read up a bit and made some experiments with lossless codecs, getting decent results. I'd be interested in comments on this, especially if there are lossless or lossy alternatives that I overlooked.
I tried the following codecs / formats in ffmpeg:

Lossless Motion JPEG2000 / AVI
ffmpeg -i test.avi -vcodec jpeg2000 -strict -2 -pred 1 test_jpeg2000.avi
compression ratio 19.59%

Lossless VP9 / WebM
ffmpeg -i test.avi -vcodec vp9 -lossless 1 test_vp9.webm
compression ratio 0.52%

HuffYUV / AVI
ffmpeg -i test.avi -vcodec huffyuv test_huffyuv.avi
compression ratio 37.42%

Lossless H.264 / MP4
ffmpeg -i test.avi -vcodec h264 -qp 0 -preset veryslow test_h264.mp4
compression ratio 0.53%


Since HuffYUV did not perform well, I excluded it from further tests.
I then tested playback support on Linux and Windows, trying mplayer, xine, vlc, chrome, and firefox on Linux (Debian testing) and vlc, windows media player, chrome, and firefox on Windows (8.1). I included browsers because WebM is specifically designed for web video. Results:

Lossless Motion JPEG2000 / AVI
plays on Linux with mplayer

Lossless VP9 / WebM
plays on Linux with vlc and chrome and on Windows with chrome and firefox

Lossless H.264 / MP4
plays on Linux with mplayer, vlc, and chrome, and on Windows with vlc and chrome


That a video "plays" means it is supported by the player out of the box, and playback is correct. I found several cases where the video was "supported" but playback was buggy.
Though Lossless VP9 has the best compression ratio (by a tiny margin), for the time being I decided to use Lossless H.264 because it has better playback support.

11462: <p>I am generating an animation in Matlab, composed of simple diagrams. The images are characterized by fine structures, strong contrasts and mostly discrete colors, e.g. there are few-pixels wide black lines, dots or small patches of uniform color, few-pixels high antialiased text, etc. Here's a screen shot of a typical frame:</p>

<p><a href="https://i.stack.imgur.com/SkRS3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SkRS3.png" alt="enter image description here"></a></p>

<p>What changes from frame to frame are the colored patches on the left, the time ("t = "), and the position of the black dot in the right panel.</p>

<p>Using a standard video codec on this which was designed for full-frame moving photographic imagery generates strong artefacts even with weak compression. Without compression however, the video file becomes unmanageably huge.</p>

<p>My question: <em>Is there a video codec that is optimized for this kind of material?</em> If possible, it would be optimal if an encoder is included in ffmpeg, and if there is a decoder (codec implementation) available for Windows.</p>
 17849: <p>If you're OK with formats requiring proprietary encoders, I suggest you check out <a href="https://en.wikipedia.org/wiki/RealVideo" rel="nofollow noreferrer">RealVideo</a>. I haven't been using this format for a while, but I remember 10 years ago I could compress DVD cartoons into &lt; 500 MB RMVB files with very little quality loss, while XviD files of similar bitrate were extremely blocky.</p>
<p>Another codec which sounds suitable at least theoretically is <a href="https://en.wikipedia.org/wiki/QuickTime_Animation" rel="nofollow noreferrer">QuickTime RLE</a>.</p>
<p>Surprisingly, although there appears to be <a href="https://video.stackexchange.com/a/22310/17849">modern research</a> on cartoon-like video codecs, none of the efforts got past the &quot;proof of concept&quot; stage.</p>
<p>I suppose your MATLAB animation will be similar to cartoons: few colors used, sharp borders between colors, only a small part of the frame actively changing, etc.</p>
 11462: <p>I read up a bit and made some experiments with lossless codecs, getting decent results. I'd be interested in comments on this, especially if there are lossless or lossy alternatives that I overlooked.</p>
<p>I tried the following codecs / formats in ffmpeg:</p>
<ul>
<li><p>Lossless Motion JPEG2000 / AVI</p>
<p><code>ffmpeg -i test.avi -vcodec jpeg2000 -strict -2 -pred 1 test_jpeg2000.avi</code></p>
<p>compression ratio 19.59%</p>
</li>
<li><p>Lossless VP9 / WebM</p>
<p><code>ffmpeg -i test.avi -vcodec vp9 -lossless 1 test_vp9.webm</code></p>
<p>compression ratio 0.52%</p>
</li>
<li><p>HuffYUV / AVI</p>
<p><code>ffmpeg -i test.avi -vcodec huffyuv test_huffyuv.avi</code></p>
<p>compression ratio 37.42%</p>
</li>
<li><p>Lossless H.264 / MP4</p>
<p><code>ffmpeg -i test.avi -vcodec h264 -qp 0 -preset veryslow test_h264.mp4</code></p>
<p>compression ratio 0.53%</p>
</li>
</ul>
<p>Since HuffYUV did not perform well, I excluded it from further tests.</p>
<p>I then tested playback support on Linux and Windows, trying mplayer, xine, vlc, chrome, and firefox on Linux (Debian testing) and vlc, windows media player, chrome, and firefox on Windows (8.1). I included browsers because WebM is specifically designed for web video. Results:</p>
<ul>
<li><p>Lossless Motion JPEG2000 / AVI</p>
<p>plays on Linux with mplayer</p>
</li>
<li><p>Lossless VP9 / WebM</p>
<p>plays on Linux with vlc and chrome and on Windows with chrome and firefox</p>
</li>
<li><p>Lossless H.264 / MP4</p>
<p>plays on Linux with mplayer, vlc, and chrome, and on Windows with vlc and chrome</p>
</li>
</ul>
<p>That a video &quot;plays&quot; means it is supported by the player out of the box, and playback is correct. I found several cases where the video was &quot;supported&quot; but playback was buggy.</p>
<p>Though Lossless VP9 has the best compression ratio (by a tiny margin), for the time being I decided to use Lossless H.264 because it has better playback support.</p>
