Answers.Body: <p>I'm not aware of anyone working on this.</p>
  
  <p>Is this the library you're referring to - <a href="https://pngquant.org/lib/" rel="nofollow noreferrer">https://pngquant.org/lib/</a>?</p>
  
  <p>This appears to generate a palette and then perform the usual PNG encoding upon the palettized image. If so, this can already be reproduced in FFmpeg.</p>
  
  <pre><code>ffmpeg -i image -filter_complex palettegen[pal];[0][pal]paletteuse,format=pal8 out.png
  </code></pre>
  
  <p>See docs for <a href="https://ffmpeg.org/ffmpeg-filters.html#paletteuse" rel="nofollow noreferrer">paletteuse</a> for dithering options.</p>
  
  <hr>
  
  <p>If the specific algorithm were to be added to FFmpeg, it would be as a libav filter, not as changes to the PNG encoder. Although given existing functionality, most acceptable way forward is to improve the palettegen/use filters if their quality isn't acceptable.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-28T06:00:18.833Z
Answers.Text: Thanks for explaining this. Yes that is the site for libpngquant. I’ll compare ffmpeg palletegen with libpngquant and see if it works better.
Answers.UserDisplayName: user984896
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-28T23:57:53.037Z
Answers.Text: It works, but PSNR is very bad. command to test: ```ffmpeg -y -i 1.png -filter_complex "palettegen=reserve_transparent=1[pal];[0][pal]paletteuse=dither=bayer" 3.png 2>&1 | tail -2 ; ffmpeg -y -i 3.png -i 1.png -filter_complex "psnr" -f null /dev/null 2>&1 | tail -1; ls -lh {1,3}.png; open {1,3}.png```
Answers.UserDisplayName: user984896
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-27T19:43:28.623Z
Answers.LastActivityDate: 2018-06-27T19:43:28.623Z
Answers.UserDisplayName: Gyan
Body: <p>The png codec in ffmpeg can result large pngs in certain cases. I know pngs are supposed to be non-lossy but there are libraries such as libpngquant that difference between the pixel and the value predicted by the average filter. </p>
  
  <p>Ffmpeg doesn't seem to support these libraries. It will be great if it could. Does anyone know if this is planned? How easy is it to port libpngquant over to ffmpeg's png encoder?</p>
  
Tags: <ffmpeg>
Title: ffmpeg png optimization like libpngquant?
UserDisplayName: user984896
ThreadText: # ffmpeg png optimization like libpngquant?
  
  (Asked by: username_0 on 2018-06-27)
  
  The png codec in ffmpeg can result large pngs in certain cases. I know pngs are supposed to be non-lossy but there are libraries such as libpngquant that difference between the pixel and the value predicted by the average filter.
  
  Ffmpeg doesn't seem to support these libraries. It will be great if it could. Does anyone know if this is planned? How easy is it to port libpngquant over to ffmpeg's png encoder?
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-27. Score: 0 | Accepted answer
  
  I'm not aware of anyone working on this.
  
  Is this the library you're referring to - <https://pngquant.org/lib/>?
  
  This appears to generate a palette and then perform the usual PNG encoding upon the palettized image. If so, this can already be reproduced in FFmpeg.
  
  ```
  ffmpeg -i image -filter_complex palettegen[pal];[0][pal]paletteuse,format=pal8 out.png
  
  ```
  
  See docs for [paletteuse](https://ffmpeg.org/ffmpeg-filters.html#paletteuse) for dithering options.
  
  ---
  
  If the specific algorithm were to be added to FFmpeg, it would be as a libav filter, not as changes to the PNG encoder. Although given existing functionality, most acceptable way forward is to improve the palettegen/use filters if their quality isn't acceptable.
  
  > **Comments:**
  > **username_0**: Thanks for explaining this. Yes that is the site for libpngquant. I’ll compare ffmpeg palletegen with libpngquant and see if it works better.  
  > **username_0**: It works, but PSNR is very bad. command to test: ```ffmpeg -y -i 1.png -filter_complex "palettegen=reserve_transparent=1[pal];[0][pal]paletteuse=dither=bayer" 3.png 2>&1 | tail -2 ; ffmpeg -y -i 3.png -i 1.png -filter_complex "psnr" -f null /dev/null 2>&1 | tail -1; ls -lh {1,3}.png; open {1,3}.png```  
  
  ---
  
  