zlib.NET | 1.04 |
---|---|
.NET Framework | 2.0 |
[swf @ 0034A5F0]Compressed SWF format not supported in.swf: I/O error occurred Usually that means that input file is truncated and/or corrupted.検索してみたところ、swfファイルの中には圧縮されたものがあり、それは一旦展開しないとffmpegで扱えないとのこと。
*1 : 使用バイナリエディタはStirling
byte[] body = 先頭8バイトを除去したCWSファイルのバイナリ列 MemoryStream bodyStream = new MemoryStream(body); byte[] buffer = new byte[255]; int length = 0; System.IO.Compression.GZipStream objGZipStream = new System.IO.Compression.GZipStream(bodyStream, System.IO.Compression.CompressionMode.Decompress); List<byte> res = new List<byte>(); while (true) { length = objGZipStream.Read(buffer, 0, buffer.Length); if (length <= 0) break; for (int idx = 0; idx < length; idx++) res.Add(buffer[idx]); } body = res.ToArray();InvalidDataExceptionで次のようなメッセージが返ります
GZip ヘッダーのマジック ナンバーが適切ではありません。GZip ストリームを渡していることを確認してください。
byte[] body = 先頭8バイトを除去したCWSファイルのバイナリ列 MemoryStream bodyStream = new MemoryStream(body); byte[] buffer = new byte[255]; int length = 0; ICSharpCode.SharpZipLib.GZip.GZipInputStream objGZipInputStream = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(bodyStream); List<byte> res = new List<byte>(); while (true) { length = objGZipInputStream.Read(buffer, 0, buffer.Length); if (length <= 0) break; for (int idx = 0; idx < length; idx++) res.Add(buffer[idx]); } body = res.ToArray();GZipExceptionでこんなメッセージが返ります
Error GZIP header, first magic byte doesn't match
byte[] body = 先頭8バイトを除去したCWSファイルのバイナリ列 MemoryStream bodyStream = new MemoryStream(body); byte[] buffer = new byte[255]; int length = 0; zlib.ZInputStream objZlibStream = new zlib.ZInputStream(bodyStream); List<byte> res = new List<byte>(); while (true) { // ReadだとBinaryReaderクラスのメソッドを読んでしまうので注意 length = objZlibStream.read(buffer, 0, buffer.Length); if (length <= 0) break; for (int idx = 0; idx < length; idx++) res.Add(buffer[idx]); } body = res.ToArray();
using System; using System.Collections.Generic; using System.Text; using System.IO; using zlib; namespace CwsTest { class Program { static void Main(string[] args) { // 第一引数を入力ファイルパス string input = args[0]; // 第二引数が出力ファイルパス string output = args[1]; // CWSヘッダのサイズ int SIZE_HEADER = 8; // ファイルからバイト列に読み込み List<byte> src = new List<byte>(File.ReadAllBytes(input)); // 先頭8バイト分をヘッダとして読み込み byte[] header = src.GetRange(0, SIZE_HEADER).ToArray(); // 残りをzlib展開対象として取得 byte[] body = src.GetRange(SIZE_HEADER, src.Count - SIZE_HEADER).ToArray(); // ZLib.NETに渡すためにバイト列をストリームに接続 using (MemoryStream bodyStream = new MemoryStream(body)) { // zlib展開読み込みバッファのサイズ int BUFFER_SIZE = 255; // Zlib.NETの展開用クラスはZInputStream ZInputStream zis = new ZInputStream(bodyStream); // 通常のストリームと同様に末尾まで読み込んでいく List<byte> res = new List<byte>(); byte[] buffer = new byte[BUFFER_SIZE]; int len = 0; while (true) { len = zis.read(buffer, 0, buffer.Length); if (len == -1) break; for (int lci = 0; lci < len; lci++) res.Add(buffer[lci]); } body = res.ToArray(); zis.Close(); bodyStream.Close(); } // ヘッダの一文字目をFにしてヘッダと本体を結合して書き出す List<byte> after = new List<byte>(); header[0] = Convert.ToByte('F'); after.AddRange(header); after.AddRange(body); File.WriteAllBytes(output, after.ToArray()); } } }サンプルダウンロード:CwsTest.zip
CwsTest.exe 入力CWSファイル.swf 出力SWFファイル名.swf
new CsCws2FwsEngine().Cws2Fws("入力CWSファイルパス", "出力SWFファイルパス");