2017-04-09 102 views
2

我想將帶有alpha通道的.avi轉換爲.gif文件。
首先,我用如何修復與Graphicsmagick收集損壞的alpha通道(卡住像素).gif?

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

爲.avi轉換爲巴紐的序列與APLHA通道。
然後,我用

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

收集一個.gif。
但是,在透明區域頂部呈現不透明的東西時,output.gif的像素似乎只會卡住。

下面是一個例子:

img

正如你所看到的心靈和爆炸沒有得到derendered。

P.S. FFMPEG輸出(在.png上收集)很好。

+0

如何共享AVI文件? –

+0

@MarkSetchell [你在這裏。](https://www.dropbox.com/s/wmvno7jaw8uijar/vid.avi?dl=0) –

+1

我添加了我的解決方案作爲答案。順便說一句,希望你知道** GIF **沒有一個alpha通道只是單一的透明顏色,但這與你的問題無關。 – Spektre

回答

2

我不使用GraphicsMagick工具,但你的GIF具有圖像處置模式0(不包括動畫)。您應該使用處理模式2(清除背景)或3(恢復以前的圖像)都適用於您的GIF。這個處置是以Packed的值在每幀的gfx擴展中出現的。

所以,如果你可以嘗試配置編碼器使用disposal = 23或寫腳本,直接流複製您的GIF和框架改變GFX延伸塊幀的Packed值。與此相似:

如果您需要腳本幫助,然後看看:

當我試圖這(C++腳本)上使用的處置2GIF我得到了這樣的結果:

disposal=2

處置前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的其他位,因爲沒有人知道可以在那裏編碼的內容......

+2

優秀的偵探!用** GraphicsMagick **實現這個(我已經測試過並且工作正常)的簡單方法是使用OP的原始腳本,像這樣修改:'gm convert -loop 0 -dispose 2 frames/*。png output.gif' –

+2

@MarkSetchell很容易發現,因爲我自己的C++編碼器/解碼器會拋出像處置這樣的信息,每幀清除代碼的數量以及更多用於調試的目的......我只需單擊該文件並查看一個外觀上的錯誤: ) – Spektre

+0

非常感謝!這正是我想要的。 我不能夠感謝你! –