逆向工程无损视频编解码器(photoshop格式视频层)

reverse engineering lossless video codec (photoshop format video layer)

我正在实施解码 photoshop (PSD) 文件。他们的格式大多记录在案,但不是全部。在较新版本的 photoshop 中,您可以拥有视频图层。视频层数据存储在 'PxSD' 标签中(内容未记录)。我已经成功地使用以下代码对一些元数据进行了逆向工程:

            case "PxSD": {
                // Raw data for 3D or video layers.
                var length = stream.readUint64();

                var layer_id = stream.readUint32(); // id of video layer

                var unknown1 = stream.readUint32(); // = 2
                var unknown2 = stream.readUint32(); // = 2

                var size = stream.readUint64(); // remaining size

                var numFrames = stream.readUint32();

                for (var nframe = 0; nframe < numFrames; ++nframe)
                {
                    var size2 = stream.readUint64();
                    var absFrame = stream.readUint32();
                    var layerTop = stream.readUint32();
                    var layerLeft = stream.readUint32();

                    // TODO: mode, 1 for grayscale image, 3 = RGB image
                    // They are always same?
                    var mode = stream.readUint32();
                    var mode2 = stream.readUint32();

                    // TODO: numChannels
                    // 4 if painting on a frame from blank video layer
                    // 6 if painting on top of an imported RGB video
                    var channels = 4;

                    for (var ch = 0; ch < channels; ++ch)
                    {
                        var depth = stream.readUint32();    // 8
                        var top = stream.readInt32();     // layer dimensions
                        var left = stream.readInt32();
                        var bottom = stream.readInt32();
                        var right = stream.readInt32();

                        var unknown3 = stream.readUint32();
                        let sz = stream.readUint32();

                        var dt = new Uint8Array(sz);
                        stream.readUint8Array(dt);
                        console.log(dt);
                    }
                }
                break;
            }

实际压缩数据内容的几个例子

宽度:1,高度:1 - 全黑 (0) 通道

[0, 3, 72, 137, 250, 15, 16, 96, 0, 1, 0, 1, 0, 0, 0, 0] (length=16)

宽度:1,高度:1 - 全白 (255) 通道

[0, 3, 72, 137, 98, 0, 8, 48, 0, 0, 1, 0, 1, 0, 0, 0] (length=16)

宽度:96,高度:8 - 全黑 (0) 通道

[0, 3, 72, 137, 250, 207, 64, 91, 240, 127, 212, 252, 81, 243, 7, 177, 249, 0, 1, 6, 0, 118, 67, 7, 249, 0, 0, 0]

宽度:96,高度:8 - 全白 (255) 通道

[0, 3, 72, 137, 98, 96, 24, 5, 163, 96, 228, 2, 128, 0, 3, 0, 3, 0, 0, 1]

宽度:96,高度:7 - 全黑 (0) 通道

[0, 3, 72, 137, 250, 207, 64, 91, 240, 127, 212, 252, 81, 243, 41, 0, 0, 1, 6, 0, 120, 182, 6, 250]

有没有人知道使用哪种压缩? (它肯定是无损的)(他们是否使用宏块,某种无损 JPEG?,它只是 zlib 吗?)有人指出我正确的方向吗?它是什么样子的?想法?

谢谢

好的,数据中的前2个字节似乎是压缩的

0=uncompressed
1=RLE
2=ZLIB
3=ZLIB with prediction

还没有彻底测试