diff --git a/play.lua b/play.lua index f7b75fe..67b3551 100644 --- a/play.lua +++ b/play.lua @@ -133,7 +133,7 @@ local get_task = {} local function readU32(s, pos) if pos + 3 > #s then return nil end local b1, b2, b3, b4 = s:byte(pos, pos + 3) - -- 使用 bit32.lshift 和 bit32.bor + -- 使用网络字节序(大端序) return bit32.bor( bit32.lshift(b1, 24), bit32.lshift(b2, 16), @@ -142,27 +142,45 @@ local function readU32(s, pos) ) end --- 解析 FramePack 二进制数据 +-- 修复后的 FramePack 解析函数 local function unpackFramePack(data) local frames = {} local pos = 1 + -- 读取总帧数 local frameCount = readU32(data, pos) - if not frameCount then error("Invalid framepack header") end + if not frameCount then + error("Invalid framepack header - no frame count found") + end + print("Parsing " .. frameCount .. " frames") pos = pos + 4 for i = 1, frameCount do + -- 读取当前帧的大小 local size = readU32(data, pos) - if not size then error("Truncated framepack at frame " .. i) end + if not size then + error("Truncated framepack at frame " .. i .. ", position " .. pos) + end + + print("Frame " .. i .. " size: " .. size .. " bytes") pos = pos + 4 - if pos + size - 1 > #data then error("Frame " .. i .. " out of bounds") end + + -- 检查是否有足够的数据来读取这个帧 + if pos + size - 1 > #data then + error("Frame " .. i .. " size (" .. size .. ") extends beyond data boundary") + end + + -- 提取帧数据(这应该是完整的PNG图像数据) local frameData = data:sub(pos, pos + size - 1) frames[i] = frameData + pos = pos + size end return frames end + + -- 分批下载(每批 50 帧) local BATCH_SIZE = 20 -- local totalFrames = #videoInfo.frame_urls