VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 14 of 14
Thread
  1. I'm hoping for minimal colour loss (I often find in gifs I create with ffmpeg that women with red/pinkish lipstick often have the colour in their lips washed out to a golden brown!), minimal banding (preferably none), minimal noise, and NO crosshatch patterning. I normally just use this standard command,

    Code:
    ffmpeg -i input.ext -vf palettegen palette.png
    followed by

    Code:
    ffmpeg -i input.ext -i palette.png -lavfi paletteuse output.gif
    and they work pretty fine most of the time. But then there are these clips where, as I've said, I often notice women's lips being drained of colour. Instead of a healthy crimson, they often look yellowy/browny/goldy/beigey/orangey. Can someone help me out?

    PS In case anyone wants to tell me the golden lips are a result of the limitations of the gif format, there's a program called Instagiffer that can make gifs of the same videos without that colour loss. The women keep their red lips. Only reasons I don't choose to use that over ffmpeg are it's incredibly slow and ya have to "enhance" each gif to eliminate banding. I just want gifs as close as I can get to the original videos. Better isn't necessary.
    Quote Quote  
  2. The problem is that gif uses a 256 color palette. Some programs choose the colors based one what colors appear most in the video. If reds are a very small portion of the video reds will not be in the 256 colors palette. So you need to generate a palette that includes red for the lips.

    One way of doing that is to use a palette that has 256 colors spread throughout the RGB cube. The problem with that is you may end up with banding or a very grainy image.

    Another way is to trick ffmpeg into generating a palette with reds. Maybe by cropping the video to a smaller area when generating the palette. But then you may miss colors in other parts of the frame.
    Quote Quote  
  3. Originally Posted by jagabo View Post
    The problem is that gif uses a 256 color palette. Most program choose the colors based one what colors appear most in the video. If reds are a very small portion of the video reds will not be in the 256 colors palette. So you need to generate a palette that includes red for the lips.
    How do I do that?
    Quote Quote  
  4. I outlined two ways later in the post.
    Quote Quote  
  5. Originally Posted by jagabo View Post
    I outlined two ways later in the post.
    So, basically, it's back to using Instagiffer. Both of those methods come at too high a price.
    Quote Quote  
  6. In GIF every frame may have own 256CLUT (it will increase size of frame by 768 bytes), using proper dithering may save bandwidth.

    Script provided bellow may be helpful, feel free to modify:

    Code:
    @echo off
    @setlocal
    @set /p CLUT=How Many Colors (4..256): 
    @echo Number of colors: %CLUT%
    
    @set /p BS=Bayer_Strength (0..5 lower is stronger): 
    @echo Bayer Strength: %BS%
    
    @echo Generating Palette...
    
    @ffmpeg.exe -i %1 -vf "palettegen=max_colors=%CLUT%:reserve_transparent=0:stats_mode=diff" %1_C%CLUT%_D.png
    
    @echo Generating GIF...
    
    @rem echo --video--
    @rem possible vidither are: 0,1,2,3,4,5,6 or "bayer","ed","a_dither", "x_dither"
    @set vidither=a_dither
    
    
    @ffmpeg.exe  -i %1 -i %1_C%CLUT%_D.png -lavfi "paletteuse=dither=bayer:bayer_scale=%BS%" -sws_dither %vidither% -loop 0 -vsync 0 %1_C%CLUT%_BS%BS%.gif
    @ffmpeg.exe  -i %1 -i %1_C%CLUT%_D.png -lavfi "paletteuse=dither=sierra2_4a" -sws_dither %vidither% -loop 0 -vsync 0 %1_C%CLUT%_S.gif
    
    @echo Optimizing GIF...
    
    @rem gifsicle.exe -V -O2 %1_d.gif -o %1_d_o.gif
    @rem gifsicle.exe -V -O2 %1_d_b2.gif -o %1_d_b2_o.gif
    @rem gifsicle.exe -V -O2 %1_f.gif -o %1_o_f.gif
    
    @echo DONE^^! Press ENTER to close window...
    @PAUSE
    With gifscisle you may further optimize size of gif and reduce its size (losslessly)

    Bellow link may be useful too:
    https://medium.com/@colten_jackson/doing-the-gif-thing-on-debian-82b9760a8483
    http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
    http://pippin.gimp.org/a_dither/
    https://forum.videohelp.com/threads/365696-avi-to-Gif-%28High-quality%29

    You may think about creating single CLUT using tircks that works for me OK (sometimes) - i generate large pic made from series of video frames and i use modern color quantization algorithm such as https://scientificgems.wordpress.com/stuff/neuquant-fast-high-quality-image-quantization/ or https://people.eecs.berkeley.edu/~dcoetzee/downloads/scolorq/ - both deliver very good perceived quality.
    Quote Quote  
  7. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    How long are your GIF's? If they are not too long you can use FFMPEG and a free software called CONVERT.EXE which is part of ImageMagick. Below is a sample video and the subsequent optimized and non-optimized GIF's. I ask abouty length because Convert is memory intensive and long conversions will tie up your CMD process for quite a while as well as use a lot of memory. Small videos are no problem and usually come out pretty well.

    Image
    [Attachment 49036 - Click to enlarge]


    Code:
    ffmpeg -i "C:\Users\Bud\Desktop\250_red.mp4" -vf scale=640:480 -r 20 -f image2pipe -vcodec ppm - | convert -delay 5 - gif:- | convert -layers Optimize -loop 0 - "C:\Users\Bud\Desktop\250_red_Gif_1.gif"
    Image
    [Attachment 49037 - Click to enlarge]


    Code:
    ffmpeg -i "C:\Users\Bud\Desktop\250_red.mp4" -vf scale=640:480 -r 20 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - "C:\Users\Bud\Desktop\250_red_Gif_1.gif"
    Image
    [Attachment 49038 - Click to enlarge]
    Quote Quote  
  8. Originally Posted by pandy View Post
    In GIF every frame may have own 256CLUT (it will increase size of frame by 768 bytes), using proper dithering may save bandwidth.

    Script provided bellow may be helpful, feel free to modify:

    Code:
    @echo off
    @setlocal
    @set /p CLUT=How Many Colors (4..256): 
    @echo Number of colors: %CLUT%
    
    @set /p BS=Bayer_Strength (0..5 lower is stronger): 
    @echo Bayer Strength: %BS%
    
    @echo Generating Palette...
    
    @ffmpeg.exe -i %1 -vf "palettegen=max_colors=%CLUT%:reserve_transparent=0:stats_mode=diff" %1_C%CLUT%_D.png
    
    @echo Generating GIF...
    
    @rem echo --video--
    @rem possible vidither are: 0,1,2,3,4,5,6 or "bayer","ed","a_dither", "x_dither"
    @set vidither=a_dither
    
    
    @ffmpeg.exe  -i %1 -i %1_C%CLUT%_D.png -lavfi "paletteuse=dither=bayer:bayer_scale=%BS%" -sws_dither %vidither% -loop 0 -vsync 0 %1_C%CLUT%_BS%BS%.gif
    @ffmpeg.exe  -i %1 -i %1_C%CLUT%_D.png -lavfi "paletteuse=dither=sierra2_4a" -sws_dither %vidither% -loop 0 -vsync 0 %1_C%CLUT%_S.gif
    
    @echo Optimizing GIF...
    
    @rem gifsicle.exe -V -O2 %1_d.gif -o %1_d_o.gif
    @rem gifsicle.exe -V -O2 %1_d_b2.gif -o %1_d_b2_o.gif
    @rem gifsicle.exe -V -O2 %1_f.gif -o %1_o_f.gif
    
    @echo DONE^^! Press ENTER to close window...
    @PAUSE
    With gifscisle you may further optimize size of gif and reduce its size (losslessly)

    Bellow link may be useful too:
    https://medium.com/@colten_jackson/doing-the-gif-thing-on-debian-82b9760a8483
    http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
    http://pippin.gimp.org/a_dither/
    https://forum.videohelp.com/threads/365696-avi-to-Gif-%28High-quality%29

    You may think about creating single CLUT using tircks that works for me OK (sometimes) - i generate large pic made from series of video frames and i use modern color quantization algorithm such as https://scientificgems.wordpress.com/stuff/neuquant-fast-high-quality-image-quantization/ or https://people.eecs.berkeley.edu/~dcoetzee/downloads/scolorq/ - both deliver very good perceived quality.
    Sorry, mate, I appreciate the help but I'm not tech-minded. I don't understand any of that, sorry. But one of those links proved useful. I learned how to create a palettized avi with virtualdub, so that helped. Thanks. The resulting gifs do have more noise than I'd like but I guess that's the price of colour retention.
    Quote Quote  
  9. Originally Posted by Budman1 View Post
    How long are your GIF's? If they are not too long you can use FFMPEG and a free software called CONVERT.EXE which is part of ImageMagick. Below is a sample video and the subsequent optimized and non-optimized GIF's. I ask abouty length because Convert is memory intensive and long conversions will tie up your CMD process for quite a while as well as use a lot of memory. Small videos are no problem and usually come out pretty well.

    Image
    [Attachment 49036 - Click to enlarge]


    Code:
    ffmpeg -i "C:\Users\Bud\Desktop\250_red.mp4" -vf scale=640:480 -r 20 -f image2pipe -vcodec ppm - | convert -delay 5 - gif:- | convert -layers Optimize -loop 0 - "C:\Users\Bud\Desktop\250_red_Gif_1.gif"
    Image
    [Attachment 49037 - Click to enlarge]


    Code:
    ffmpeg -i "C:\Users\Bud\Desktop\250_red.mp4" -vf scale=640:480 -r 20 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - "C:\Users\Bud\Desktop\250_red_Gif_1.gif"
    Image
    [Attachment 49038 - Click to enlarge]
    Hi. Just tried the first command. I'll let ya know how it goes. It's taking a lot longer than I thought it would. What does "-delay 5" mean?

    EDIT: Holy shit, that worked brilliantly! Thanks! That does exactly what I was hoping for. Only slight problem was the gif seemed a bit slow. I think that must be the "-delay 5" bit so I took it out and am trying again now.

    EDIT: Oops, taking out the "-delay 5" bit made it slower. How do I fix that? The video's fps is 24.601. I put that in for -r. What do I need to do to get the gif to play at the same fps?
    Last edited by Bruce Banner; 10th May 2019 at 16:37.
    Quote Quote  
  10. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    The -r and -delay work together with computing animation speed. I use a program that plugs it in automatically . I will post that and an explaination later when I get my computer fired up. For now changing one or bother affect the outcome in different ways. How exactly fails my memory at this minute,but I will post later.

    Try this web page for now for an explanation.
    https://imagemagick.org/script/convert.php
    Last edited by Budman1; 10th May 2019 at 17:00.
    Quote Quote  
  11. Originally Posted by Budman1 View Post
    The -r and -delay work together with computing animation speed. I use a program that plugs it in automatically . I will post that and an explaination later when I get my computer fired up. For now changing one or bother affect the outcome in different ways. How exactly fails my memory at this minute,but I will post later.

    Try this web page for now for an explanation.
    https://imagemagick.org/script/convert.php
    Great, thanks.
    Quote Quote  
  12. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    From https://imagemagick.org/Usage/anim_basics/

    -delay {time} Set the time delay (in 1/100th of a second) to pause after drawing the images that are read in or created after this setting has been defined.
    You can specify a different scale for the time delay by specifying a 'x' scaling (giving in ticks per second). For example '10x1' is 10, 1 second ticks, while '10x100' is 10, one hundredth of a second ticks.
    Basically the 'x' is equivalent to a fraction '/' sign. For example if you specify '1x160' will set a delay that is appropriate for 160 frames per second.
    GIF animation delays must be specified in hundredths of a second for correct working, which is why that is the default time unit. The 'x' factor is used more for generating other more movie like formats, such a MNG's, and AVI's.
    Quote Quote  
  13. Originally Posted by Budman1 View Post
    From https://imagemagick.org/Usage/anim_basics/

    -delay {time} Set the time delay (in 1/100th of a second) to pause after drawing the images that are read in or created after this setting has been defined.
    You can specify a different scale for the time delay by specifying a 'x' scaling (giving in ticks per second). For example '10x1' is 10, 1 second ticks, while '10x100' is 10, one hundredth of a second ticks.
    Basically the 'x' is equivalent to a fraction '/' sign. For example if you specify '1x160' will set a delay that is appropriate for 160 frames per second.
    GIF animation delays must be specified in hundredths of a second for correct working, which is why that is the default time unit. The 'x' factor is used more for generating other more movie like formats, such a MNG's, and AVI's.
    Great, understood. Thanks!
    Quote Quote  
  14. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    FYI... Anyone interested in the use of ImageMagick's Convert, I have enclosed several images and an explanation of the use of '-delay" and '-r'.
    Using a 30 FPS MP4, Calibrated in microseconds, I used the delay of 5 and FPS of 20 and time of 10 (-t 10).

    This is calibrated as:
    FPS x Time = Frames (20 x 10 = 200 Frames)
    Frames / Time = Frames per second of GIF (200 / 10 = 20 FPS of GIF)
    Ticks per second / GIF FPS = delay ( 100 / 20 = delay of 5)

    Notice in the image below the final GIF has approximately 200 Frames in 10 seconds compared to the MP4 that has 300 (30 x 10) . This is proportional to Gif FPS / Source FPS, even though the video will run for the approximate time specified (10 seconds).

    OOPS. The second image should show input as MP4 not GIF.

    Image
    [Attachment 49039 - Click to enlarge]


    Image
    [Attachment 49040 - Click to enlarge]


    Image
    [Attachment 49041 - Click to enlarge]
    Quote Quote  



Similar Threads