ws-video: video/mp4 (MP4 / MOV / 3GP on containers/IsoBmff: edit lists, fragments, dOps -> OpusHead, PCM entries, AAC priming as codec delay; writer: copied H.264 / HEVC / AV1 / MJPEG / AAC / ALAC / Opus / FLAC / MP3, MJPEG from frames, PCM in MOV, edit lists for B-frame / codec delays); IsoBmff Mux writes no empty DecoderSpecificInfo (ffmpeg refuses it); writer checks extended to MP4 / MOV / H.264 remux
This commit is contained in:
1 parent
8d2deb13ab
commit
f2a4a33713
8 files changed
+475
-6
No files matched your search
@@ -1,9 +1,10 @@
|
||||
-- tools/fixtures/_video_encode: run by tools/fixtures/videoenc.py (luau, from the repo root) so ffprobe / ffmpeg can
|
||||
-- check our video writers: remuxes and re-encodes the container fixtures (tests/gen/mkv_cases, avi_cases) and the
|
||||
-- check our video writers: remuxes and re-encodes the container fixtures (tests/gen/mkv_cases, avi_cases, mp4_cases) and the
|
||||
-- animated GIF of tests/gen/videoenc_src, and prints "<name> <hex>" lines (or "<name> ERR <message>").
|
||||
local F = require("@formats")
|
||||
local Mkv = require("@tests/gen/mkv_cases")
|
||||
local Avi = require("@tests/gen/avi_cases")
|
||||
local Mp4 = require("@tests/gen/mp4_cases")
|
||||
local Src = require("@tests/gen/videoenc_src")
|
||||
|
||||
local function hex(b: buffer): string
|
||||
@@ -34,6 +35,12 @@ local JOBS = {
|
||||
{ "gif.mkv", Src.gif, "mkv", { quality = 95 } },
|
||||
{ "gif.y4m", Src.gif, "y4m", {} },
|
||||
{ "webm.y4m", find(Mkv, "vp8_opus.webm"), "y4m", {} },
|
||||
{ "gif.mp4", Src.gif, "mp4", { quality = 95 } },
|
||||
{ "pcm.mov", find(Mkv, "mjpeg_pcm.mkv"), "mov", {} },
|
||||
{ "h264_aac.mov", find(Mp4, "h264_aac.mp4"), "mov", {} },
|
||||
{ "h264_aac.mkv", find(Mp4, "h264_aac.mp4"), "mkv", {} },
|
||||
{ "vp8_mjpeg.mp4", find(Mkv, "vp8_opus.webm"), "mp4", { quality = 92 } },
|
||||
{ "flac.mp4", find(Mp4, "mjpeg_flac.mp4"), "mp4", {} },
|
||||
}
|
||||
for _, j in JOBS do
|
||||
local name, data, fmt, opts = j[1], j[2], j[3], j[4]
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# MP4 / MOV fixtures (tools/fixtures.py): files made by ffmpeg (MJPEG + AAC MP4, MJPEG + PCM MOV, H.264 with B-frames
|
||||
# + AAC (edit lists), fragmented MP4, MPEG-1 + Opus, MJPEG + FLAC, MJPEG + MP2 MOV) with ffprobe's streams and packets,
|
||||
# ffmpeg's frames (CRC-32; the first raw) and audio (f32). Our MP4 / MOV writer's files are checked in
|
||||
# tools/fixtures/videoenc.py.
|
||||
# tests/gen/mp4_cases.luau { { name, data, streams, packets, frames, yuv, pcm, pcmBytes } }
|
||||
import importlib.util, os, 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"]
|
||||
|
||||
SRC = ["-f", "lavfi", "-i", "testsrc2=size=160x120:rate=12"]
|
||||
|
||||
|
||||
def aud(rate, ch=1):
|
||||
return ["-f", "lavfi", "-i", "sine=frequency=550:sample_rate=%d" % rate, "-ac", str(ch)]
|
||||
|
||||
|
||||
def case(tmp, name):
|
||||
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:
|
||||
frames = V.yuv_frames(path, vs[0]["width"], vs[0]["height"], codec=vs[0]["codec"])
|
||||
c["frames"] = [V.crc(f) for f in frames]
|
||||
c["yuv"] = frames[:2]
|
||||
if 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="mp4fx_")
|
||||
ff = lambda *a: V.ffmpeg(list(a), cwd=tmp)
|
||||
ff(*SRC, *aud(44100), "-t", "1", "-c:v", "mjpeg", "-q:v", "4", "-c:a", "aac", "-b:a", "96k", "mjpeg_aac.mp4")
|
||||
ff(*SRC, *aud(48000, 2), "-t", "1", "-c:v", "mjpeg", "-c:a", "pcm_s16le", "mjpeg_pcm.mov")
|
||||
ff(*SRC, *aud(44100), "-t", "1", "-c:v", "libx264", "-preset", "veryfast", "-bf", "2", "-g", "6", "-c:a", "aac",
|
||||
"h264_aac.mp4")
|
||||
ff(*SRC, *aud(48000), "-t", "1", "-c:v", "mjpeg", "-c:a", "aac", "-movflags", "frag_keyframe+empty_moov",
|
||||
"fragmented.mp4")
|
||||
ff(*SRC, *aud(48000), "-t", "1", "-r", "25", "-c:v", "mpeg1video", "-c:a", "libopus", "mpeg1_opus.mp4")
|
||||
ff(*SRC, *aud(44100, 2), "-t", "1", "-c:v", "mjpeg", "-c:a", "flac", "mjpeg_flac.mp4")
|
||||
ff(*SRC, *aud(44100), "-t", "1", "-c:v", "mjpeg", "-c:a", "mp2", "mjpeg_mp2.mov")
|
||||
cases = [case(tmp, n) for n in ("mjpeg_aac.mp4", "mjpeg_pcm.mov", "h264_aac.mp4", "fragmented.mp4",
|
||||
"mpeg1_opus.mp4", "mjpeg_flac.mp4", "mjpeg_mp2.mov")]
|
||||
ctx.emit("mp4_cases", cases)
|
||||
@@ -1,6 +1,7 @@
|
||||
# Our video writers checked by ffprobe / ffmpeg (tools/fixtures.py): tools/fixtures/_video_encode.luau remuxes /
|
||||
# re-encodes the container fixtures (WebM remux, MJPEG Matroska / AVI from VP8 and MPEG-1, MJPEG copies, an animated
|
||||
# GIF with uneven delays to AVI / Matroska / Y4M, WebM to Y4M); each output must probe in ffprobe and decode in
|
||||
# re-encodes the container fixtures (WebM remux, MJPEG Matroska / AVI / MP4 from VP8 and MPEG-1, MJPEG copies, H.264 +
|
||||
# AAC MP4 to MOV / Matroska, PCM MOV, FLAC MP4, an animated GIF with uneven delays to AVI / Matroska / Y4M / MP4, WebM
|
||||
# to Y4M); each output must probe in ffprobe and decode in
|
||||
# ffmpeg. Emitted per file: our bytes, ffprobe's streams and packets, ffmpeg's frames (CRC-32; the first raw) and
|
||||
# audio, so the test can decode our file with our decoders and compare.
|
||||
# tests/gen/videoenc_src.luau { gif = <animated GIF made by Pillow: 4 frames, 100 / 50 / 200 / 100 ms> }
|
||||
@@ -11,8 +12,8 @@ _spec = importlib.util.spec_from_file_location("_video_helpers", os.path.join(os
|
||||
V = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(V)
|
||||
|
||||
INPUTS = ["tools/fixtures/_video.py", "tools/fixtures/_video_encode.luau", "tools/fixtures/mkv.py", "tools/fixtures/avi.py",
|
||||
"src/Formats/video", "src/Formats/codecs/Video", "src/Formats/containers/Ebml", "src/Formats/containers/Avi",
|
||||
INPUTS = ["tools/fixtures/_video.py", "tools/fixtures/_video_encode.luau", "tools/fixtures/mkv.py", "tools/fixtures/avi.py", "tools/fixtures/mp4.py",
|
||||
"src/Formats/video", "src/Formats/codecs/Video", "src/Formats/containers/Ebml", "src/Formats/containers/Avi", "src/Formats/containers/IsoBmff",
|
||||
"src/Formats/codecs/Jpeg", "src/Formats/codecs/Vp8"]
|
||||
|
||||
GIF = r"""
|
||||
|
||||
Reference in new issue
Block a user