28
play.lua
28
play.lua
@@ -133,7 +133,7 @@ local get_task = {}
|
|||||||
local function readU32(s, pos)
|
local function readU32(s, pos)
|
||||||
if pos + 3 > #s then return nil end
|
if pos + 3 > #s then return nil end
|
||||||
local b1, b2, b3, b4 = s:byte(pos, pos + 3)
|
local b1, b2, b3, b4 = s:byte(pos, pos + 3)
|
||||||
-- 使用网络字节序(大端序)
|
-- 使用 bit32.lshift 和 bit32.bor
|
||||||
return bit32.bor(
|
return bit32.bor(
|
||||||
bit32.lshift(b1, 24),
|
bit32.lshift(b1, 24),
|
||||||
bit32.lshift(b2, 16),
|
bit32.lshift(b2, 16),
|
||||||
@@ -142,45 +142,27 @@ local function readU32(s, pos)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 修复后的 FramePack 解析函数
|
-- 解析 FramePack 二进制数据
|
||||||
local function unpackFramePack(data)
|
local function unpackFramePack(data)
|
||||||
local frames = {}
|
local frames = {}
|
||||||
local pos = 1
|
local pos = 1
|
||||||
|
|
||||||
-- 读取总帧数
|
|
||||||
local frameCount = readU32(data, pos)
|
local frameCount = readU32(data, pos)
|
||||||
if not frameCount then
|
if not frameCount then error("Invalid framepack header") end
|
||||||
error("Invalid framepack header - no frame count found")
|
|
||||||
end
|
|
||||||
print("Parsing " .. frameCount .. " frames")
|
|
||||||
pos = pos + 4
|
pos = pos + 4
|
||||||
|
|
||||||
for i = 1, frameCount do
|
for i = 1, frameCount do
|
||||||
-- 读取当前帧的大小
|
|
||||||
local size = readU32(data, pos)
|
local size = readU32(data, pos)
|
||||||
if not size then
|
if not size then error("Truncated framepack at frame " .. i) end
|
||||||
error("Truncated framepack at frame " .. i .. ", position " .. pos)
|
|
||||||
end
|
|
||||||
|
|
||||||
print("Frame " .. i .. " size: " .. size .. " bytes")
|
|
||||||
pos = pos + 4
|
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)
|
local frameData = data:sub(pos, pos + size - 1)
|
||||||
frames[i] = frameData
|
frames[i] = frameData
|
||||||
|
|
||||||
pos = pos + size
|
pos = pos + size
|
||||||
end
|
end
|
||||||
|
|
||||||
return frames
|
return frames
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- 分批下载(每批 50 帧)
|
-- 分批下载(每批 50 帧)
|
||||||
local BATCH_SIZE = 20
|
local BATCH_SIZE = 20
|
||||||
-- local totalFrames = #videoInfo.frame_urls
|
-- local totalFrames = #videoInfo.frame_urls
|
||||||
|
|||||||
Reference in New Issue
Block a user