Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-19T19:11:43.473Z
Answers.Text: Have you looked into H.265 (aka x265)?  I've never encoded with it, but the results look very promising.  Animated video compresses about 50% more than H.264 (results will vary of course).  The quality is sill phenomenal.  Playback support will probably be worse, since its a newer codec.
Answers.UserDisplayName: Doug.McFarlane
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-27T18:00:43.807Z
Answers.Text: I am having good results with `.flv` and codec `On2 VP6` in Adobe Media Encoder. Roughly 200 Mb for 40 minutes of 640x480 1fs slideshow
Answers.UserDisplayName: Rho Phi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-05T00:40:26.027Z
Answers.Text: Probably not relevant anymore but what about the PNG-based formats APNG and MNG? And what about WebP?
Answers.UserDisplayName: Christian
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-05T02:15:30.947Z
Answers.Text: I haven't really looked into any more it since then. If I remember correctly, I considered MNG, but it never really got off the ground. I hadn't heard about APNG. And I didn't know that WebP supports lossless animation.
Answers.UserDisplayName: A. Donda
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-05T02:16:51.703Z
Answers.Text: @Christian, this http://littlesvr.ca/apng/gif_apng_webp5.html might interest you. If you happen to look into this further, I'd welcome an alternative answer!
Answers.UserDisplayName: A. Donda
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-19T15:39:28.437Z
Answers.LastActivityDate: 2015-08-19T15:45:26.223Z
Answers.LastEditDate: 2020-06-17T09:53:03.607Z
Answers.UserDisplayName: A. Donda
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-22T10:20:58.900Z
Answers.LastActivityDate: 2021-12-01T10:38:30.740Z
Answers.LastEditDate: 2021-12-01T10:38:30.740Z
Answers.UserDisplayName: Dmitry Grigoryev
Body: <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.sstatic.net/SkRS3.png" rel="noreferrer"><img src="https://i.sstatic.net/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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-19T05:37:45.920Z
Comments.Text: Will need some details: what ffmpeg command did you use to generate the bad looking video? What is the target bitrate or file size you're aiming for? Do you need a codec whose decoder can be freely distributed or is a commercial solution Ok?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-19T15:16:38.613Z
Comments.Text: @Mulvya, thanks for your comment. bad looking video: I tried H.264/mp4, and increasing the bitrate only helped when the compressed video got almost as large as the original file. file size: my uncompressed video has a size of 25 GB, which cannot e.g. conveniently transferred via internet. As size below 500 MB would be nice. Decoder: Optimally it would be something that can be freely distributed, e.g. something that VLC supports. – Apart from the problem I'm facing right now, I'd be interested in some general pointers in how to deal with this kind of material.
Comments.UserDisplayName: A. Donda
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-19T15:16:43.167Z
Comments.Text: I made some progress myself and will post a tentative answer soon. I'd be very interested in comments on how to improve upon that.
Comments.UserDisplayName: A. Donda
Tags: <ffmpeg><video><codec><compression><windows>
Title: Video codec for simple animation?
UserDisplayName: A. Donda
ThreadText: # Video codec for simple animation?
  
  (Asked by: username_0 on 2015-08-17)
  
  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:
  
  [![enter image description here](https://i.sstatic.net/SkRS3.png)](https://i.sstatic.net/SkRS3.png)
  
  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.
  
  **Tags:** ffmpeg, video, codec, compression, windows
  
  > **Comments:**
  > **username_1**: Will need some details: what ffmpeg command did you use to generate the bad looking video? What is the target bitrate or file size you're aiming for? Do you need a codec whose decoder can be freely distributed or is a commercial solution Ok?  
  > **username_0**: @Mulvya, thanks for your comment. bad looking video: I tried H.264/mp4, and increasing the bitrate only helped when the compressed video got almost as large as the original file. file size: my uncompressed video has a size of 25 GB, which cannot e.g. conveniently transferred via internet. As size below 500 MB would be nice. Decoder: Optimally it would be something that can be freely distributed, e.g. something that VLC supports. – Apart from the problem I'm facing right now, I'd be interested in some general pointers in how to deal with this kind of material.  
  > **username_0**: I made some progress myself and will post a tentative answer soon. I'd be very interested in comments on how to improve upon that.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2015-08-19. Score: 4
  
  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.
  
  > **Comments:**
  > **username_2**: Have you looked into H.265 (aka x265)?  I've never encoded with it, but the results look very promising.  Animated video compresses about 50% more than H.264 (results will vary of course).  The quality is sill phenomenal.  Playback support will probably be worse, since its a newer codec.  
  > **username_3**: I am having good results with `.flv` and codec `On2 VP6` in Adobe Media Encoder. Roughly 200 Mb for 40 minutes of 640x480 1fs slideshow  
  > **username_4**: Probably not relevant anymore but what about the PNG-based formats APNG and MNG? And what about WebP?  
  > **username_0**: I haven't really looked into any more it since then. If I remember correctly, I considered MNG, but it never really got off the ground. I hadn't heard about APNG. And I didn't know that WebP supports lossless animation.  
  > **username_0**: @username_4, this http://littlesvr.ca/apng/gif_apng_webp5.html might interest you. If you happen to look into this further, I'd welcome an alternative answer!  
  
  ---
  
  ### Answer by username_5 on 2020-05-22. Score: 1
  
  If you're OK with formats requiring proprietary encoders, I suggest you check out [RealVideo](https://en.wikipedia.org/wiki/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](https://en.wikipedia.org/wiki/QuickTime_Animation).
  
  Surprisingly, although there appears to be [modern research](https://video.stackexchange.com/a/22310/17849) 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.
  
  
  ---
  
  