ws-video2-flv: video/flv (FLV demux: tags, onMetaData AMF0, Sorenson / H.264 (avcC, composition times) / VP6 / screen video / enhanced FourCC tracks, MP3 / AAC / PCM / G.711 / ADPCM / Nellymoser / Speex audio, keyframe seek; FLV mux: H.264 / Sorenson / VP6 / screen copied, AAC (ADTS re-framed) / MP3 / PCM audio, onMetaData)
Outside the folder: codecs/video/Video BUILTIN gains known (decoder-less) entries vp6f, vp6a, flashsv, flashsv2.
This commit is contained in:
1 parent
2a5da31c80
commit
efc0812746
9 files changed
+1230
No files matched your search
@@ -0,0 +1,42 @@
|
||||
-- tools/fixtures/_flv_encode: run by tools/fixtures/flv.py (luau, from the repo root) so ffprobe / ffmpeg can check our
|
||||
-- FLV writer: remuxes FLV fixtures (tests/gen/flv_cases) and the MP4 / Matroska / MPEG-TS sources (tests/gen/flv_src)
|
||||
-- and prints "<name> <source> <hex>" lines (or "<name> <source> ERR <message>").
|
||||
local F = require("@formats")
|
||||
local Cases = require("@tests/gen/flv_cases")
|
||||
local Src = require("@tests/gen/flv_src")
|
||||
|
||||
local function hex(b: buffer): string
|
||||
local t = table.create(buffer.len(b))
|
||||
for i = 0, buffer.len(b) - 1 do
|
||||
t[i + 1] = string.format("%02x", buffer.readu8(b, i))
|
||||
end
|
||||
return table.concat(t)
|
||||
end
|
||||
|
||||
local function find(name: string): string
|
||||
for _, c in Cases do
|
||||
if c.name == name then
|
||||
return c.data
|
||||
end
|
||||
end
|
||||
error("no fixture " .. name)
|
||||
end
|
||||
|
||||
local JOBS = {
|
||||
{ "remux_h264_aac.flv", "h264_aac.flv", find("h264_aac.flv") },
|
||||
{ "remux_sorenson_mp3.flv", "sorenson_mp3.flv", find("sorenson_mp3.flv") },
|
||||
{ "remux_pcm.flv", "sorenson_pcm.flv", find("sorenson_pcm.flv") },
|
||||
{ "remux_screen.flv", "screen.flv", find("screen.flv") },
|
||||
{ "mp4_h264_aac.flv", "mp4", Src.mp4 },
|
||||
{ "mkv_h264_mp3.flv", "mkv", Src.mkv },
|
||||
{ "ts_h264_aac.flv", "ts", Src.ts },
|
||||
}
|
||||
for _, j in JOBS do
|
||||
local name, source, data = j[1], j[2], j[3]
|
||||
local out, err = F.convert(buffer.fromstring(data), "flv")
|
||||
if out then
|
||||
print(name .. " " .. source .. " " .. hex(out))
|
||||
else
|
||||
print(name .. " " .. source .. " ERR " .. tostring(err))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,86 @@
|
||||
# FLV fixtures (tools/fixtures.py): files made by ffmpeg (Sorenson Spark + MP3 / PCM s16 / PCM u8 / Flash ADPCM /
|
||||
# Nellymoser / Speex / A-law, H.264 with B-frames + AAC, Flash screen video), with ffprobe's streams and packets,
|
||||
# ffmpeg's frames (CRC-32 of `-flags +bitexact -idct int` decoding; the first two raw) and audio (f32); then our FLV
|
||||
# writer (tools/fixtures/_flv_encode.luau) remuxes FLV, MP4, Matroska and MPEG-TS sources and each output is probed,
|
||||
# decoded and emitted the same way, so the test can read our files with our demuxer and compare them with ffmpeg's view.
|
||||
# tests/gen/flv_cases.luau { { name, data, streams, packets, frames, yuv, pcm, pcmBytes } }
|
||||
# tests/gen/flv_src.luau { mp4 = H.264 + AAC MP4, mkv = H.264 + MP3 Matroska, ts = H.264 + AAC MPEG-TS }
|
||||
# tests/gen/flv_mux.luau { { name, source, data, streams, packets, frames, pcm, pcmBytes } | { name, err } }
|
||||
import importlib.util, os, shutil, subprocess, tempfile
|
||||
|
||||
_spec = importlib.util.spec_from_file_location("_video_helpers", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_video.py"))
|
||||
V = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(V)
|
||||
|
||||
INPUTS = ["tools/fixtures/_video.py", "tools/fixtures/_flv_encode.luau", "src/Formats/video/flv", "src/Formats/codecs/video/Video"]
|
||||
|
||||
SRC = ["-f", "lavfi", "-i", "testsrc2=size=160x120:rate=12"]
|
||||
|
||||
|
||||
def aud(rate, ch=1, freq=550):
|
||||
return ["-f", "lavfi", "-i", "sine=frequency=%d:sample_rate=%d" % (freq, rate), "-ac", str(ch)]
|
||||
|
||||
|
||||
def case(tmp, name, decode_audio=True):
|
||||
path = os.path.join(tmp, name)
|
||||
c = {"name": name, "data": open(path, "rb").read(), "streams": V.streams(path), "packets": V.packets(path)}
|
||||
vs = [s for s in c["streams"] if s["kind"] == "video"]
|
||||
if vs and vs[0]["codec"] in ("flv1", "h264"):
|
||||
w, h = vs[0]["width"], vs[0]["height"]
|
||||
raw = V.ffmpeg(["-flags", "+bitexact", "-idct", "int", "-i", path, "-map", "0:v:0", "-fps_mode", "passthrough", "-f",
|
||||
"rawvideo", "-pix_fmt", "yuv420p", "-"])
|
||||
n = w * h + 2 * ((w + 1) // 2) * ((h + 1) // 2)
|
||||
frames = [raw[i:i + n] for i in range(0, len(raw) - n + 1, n)]
|
||||
c["frames"] = [V.crc(f) for f in frames]
|
||||
c["yuv"] = frames[:2]
|
||||
if decode_audio and any(s["kind"] == "audio" for s in c["streams"]):
|
||||
pcm = V.pcm_f32(path)
|
||||
c["pcm"] = pcm[:8192 * 4]
|
||||
c["pcmBytes"] = len(pcm)
|
||||
return c
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
tmp = tempfile.mkdtemp(prefix="flvfx_")
|
||||
ff = lambda *a: V.ffmpeg(list(a), cwd=tmp)
|
||||
ff(*SRC, *aud(44100), "-t", "1", "-c:v", "flv", "-b:v", "300k", "-g", "6", "-c:a", "libmp3lame", "-b:a", "64k", "sorenson_mp3.flv")
|
||||
ff(*SRC, *aud(44100), "-t", "1", "-c:v", "libx264", "-preset", "veryfast", "-bf", "2", "-g", "6", "-c:a", "aac", "-b:a", "96k",
|
||||
"h264_aac.flv")
|
||||
ff(*SRC, *aud(22050, 2), "-t", "1", "-c:v", "flv", "-g", "12", "-c:a", "pcm_s16le", "sorenson_pcm.flv")
|
||||
ff(*SRC, *aud(11025), "-t", "1", "-c:v", "flv", "-g", "12", "-c:a", "pcm_u8", "sorenson_pcm8.flv")
|
||||
ff(*SRC, *aud(22050), "-t", "0.5", "-c:v", "flv", "-c:a", "adpcm_swf", "sorenson_adpcm.flv")
|
||||
ff(*SRC, *aud(22050), "-t", "0.5", "-c:v", "flv", "-c:a", "nellymoser", "sorenson_nelly.flv")
|
||||
ff(*SRC, *aud(16000), "-t", "0.5", "-c:v", "flv", "-c:a", "libspeex", "sorenson_speex.flv")
|
||||
ff(*SRC, *aud(8000), "-t", "0.5", "-c:v", "flv", "-c:a", "pcm_alaw", "sorenson_alaw.flv")
|
||||
ff("-f", "lavfi", "-i", "testsrc2=size=64x48:rate=10", "-t", "0.5", "-c:v", "flashsv", "screen.flv")
|
||||
ff(*aud(44100, 2), "-t", "0.5", "-c:a", "libmp3lame", "audio_only.flv")
|
||||
names = ["sorenson_mp3.flv", "h264_aac.flv", "sorenson_pcm.flv", "sorenson_pcm8.flv", "sorenson_adpcm.flv",
|
||||
"sorenson_nelly.flv", "sorenson_speex.flv", "sorenson_alaw.flv", "screen.flv", "audio_only.flv"]
|
||||
cases = [case(tmp, n) for n in names]
|
||||
ctx.emit("flv_cases", cases)
|
||||
|
||||
# sources for the writer
|
||||
ff(*SRC, *aud(44100), "-t", "1", "-c:v", "libx264", "-preset", "veryfast", "-bf", "2", "-g", "6", "-c:a", "aac", "src.mp4")
|
||||
ff(*SRC, *aud(44100, 2), "-t", "1", "-c:v", "libx264", "-preset", "veryfast", "-bf", "0", "-g", "12", "-c:a", "libmp3lame",
|
||||
"src.mkv")
|
||||
ff(*SRC, *aud(44100), "-t", "1", "-c:v", "libx264", "-preset", "veryfast", "-c:a", "aac", "src.ts")
|
||||
srcs = {k: open(os.path.join(tmp, "src." + k), "rb").read() for k in ("mp4", "mkv", "ts")}
|
||||
ctx.emit("flv_src", srcs)
|
||||
|
||||
luau = os.environ.get("LUAU") or shutil.which("luau")
|
||||
cmd = [luau, "tools/fixtures/_flv_encode.luau"] if luau else ["nix", "shell", "nixpkgs#luau", "-c", "luau", "tools/fixtures/_flv_encode.luau"]
|
||||
out = subprocess.run(cmd, capture_output=True, check=True, cwd=ctx.root).stdout.decode()
|
||||
mux = []
|
||||
for line in out.split("\n"):
|
||||
if not line.strip():
|
||||
continue
|
||||
name, source, rest = line.split(" ", 2)
|
||||
if rest.startswith("ERR "):
|
||||
mux.append({"name": name, "source": source, "err": rest[4:]})
|
||||
continue
|
||||
open(os.path.join(tmp, name), "wb").write(bytes.fromhex(rest))
|
||||
c = case(tmp, name)
|
||||
c["source"] = source
|
||||
c.pop("yuv", None)
|
||||
mux.append(c)
|
||||
ctx.emit("flv_mux", mux)
|
||||
Reference in new issue
Block a user