【问题标题】:How to fix .gif with corrupted alpha channel (stuck pixels) collected with Graphicsmagick?如何使用 Graphicsmagick 收集的损坏的 alpha 通道(卡住的像素)修复 .gif?
【发布时间】:2017-09-04 19:22:26
【问题描述】:

我想将带有 alpha 通道的 .avi 转换为 .gif。
首先,我使用

ffmpeg -i source.avi -vf scale=720:-1:flags=lanczos,fps=10 frames/ffout%03d.png

使用 aplha 通道将 .avi 转换为 .png 序列。
然后,我使用

gm convert -loop 0 frames/ffout*.png output.gif

收集 .gif。
但似乎 output.gif 的像素只是在透明区域顶部呈现不透明的东西时卡住了。

这是一个例子:

如您所见,心脏和爆炸不会被渲染。

附: FFMPEG 输出(.png 上的集合)很好。

【问题讨论】:

  • 如何共享 AVI 文件?
  • @MarkSetchell Here you are.
  • 我添加了我的解决方案作为答案。顺便说一句,希望您知道 GIF 没有 alpha 通道,只有单一透明颜色,但这与您的问题无关。

标签: graphics ffmpeg gif encode graphicsmagick


【解决方案1】:

我不使用 Graphicsmagick,但您的 GIF 具有图像 处理模式 0(无动画)。您应该使用处理模式2(清除背景)或3(恢复上一个图像)都适用于您的GIF。处置存在于Packed 值中每个帧的 gfx 扩展中。

因此,如果您可以尝试将编码器配置为使用 disposal = 23 或编写脚本直接流复制您的 GIF 并逐帧更改 gfx 扩展块的 Packed 值.类似这样:

如果您需要脚本方面的帮助,请查看:

当我使用处理 2 在您的 GIF 上尝试此(C++ 脚本)时,我得到了以下结果:

C++ 中的处置改变如下:

struct __gfxext
    {
    BYTE Introducer;        /* Extension Introducer (always 21h) */
    BYTE Label;             /* Graphic Control Label (always F9h) */
    BYTE BlockSize;         /* Size of remaining fields (always 04h) */
    BYTE Packed;            /* Method of graphics disposal to use */
    WORD DelayTime;         /* Hundredths of seconds to wait    */
    BYTE ColorIndex;        /* Transparent Color Index */
    BYTE Terminator;        /* Block Terminator (always 0) */
    __gfxext(){}; __gfxext(__gfxext& a){ *this=a; }; ~__gfxext(){}; __gfxext* operator = (const __gfxext *a) { *this=*a; return this; }; /*__gfxext* operator = (const __gfxext &a) { ...copy... return this; };*/
    };

__gfxext p;
p.Packed&=255-(7<<2);   // clear old disposal and leave the rest as is
p.Packed|=     2<<2;    // set new disposal=2 (the first 2 is disposal , the <<2 just shifts it to the correct position in Packed)

最好保留Packed 的其他位,因为没有人知道其中可以及时编码什么...

【讨论】:

  • 优秀的侦探!使用 GraphicsMagick 实现这个(我已经测试过并且可以工作)的简单方法是使用 OP 的原始脚本修改如下:gm convert -loop 0 -dispose 2 frames/*.png output.gif
  • @MarkSetchell 很容易发现,因为我自己的 C++ 编码器/解码器会抛出诸如处置、每帧清晰代码数量以及更多用于调试目的的信息……我只需单击文件并一看就知道有什么问题:)
  • 非常感谢!这正是我想要的。我感激不尽!
  • @IvanIvanov 顺便说一句,这个Animated gif only loops once in Chrome and Firefox 可能也会让你感兴趣,因为你正在构建 GIF...
猜你喜欢
  • 1970-01-01
  • 2016-03-19
  • 1970-01-01
  • 2011-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-17
相关资源
最近更新 更多