From 8277ea3feb44f634248788cc50d2fe355a58a5d6 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Tue, 15 Sep 2026 00:05:48 +0200 Subject: test: generate media fixtures locally --- .github/workflows/release.yml | 9 +++--- benchmark_test.go | 4 +-- fragment/reader_test.go | 2 +- test-data/.gitignore | 1 + test-data/generate-av1.sh | 38 ++++++++++++++++++++++++ test-data/generate.sh | 68 +++++++++++++++++++++++++++++++++++++++---- 6 files changed, 109 insertions(+), 13 deletions(-) create mode 100755 test-data/generate-av1.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6838ab9..94a57f6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,11 +53,12 @@ jobs: - name: Generate test data run: | set -euxo pipefail - (cd test-data && ./generate.sh) + ./test-data/generate.sh + ./test-data/generate-av1.sh - mkdir -p video-media-samples - curl -fL --retry 3 -o video-media-samples/big-buck-bunny-480p-30sec.mp4 \ - https://github.com/chthomos/video-media-samples/raw/refs/heads/master/big-buck-bunny-480p-30sec.mp4 + curl -fL --retry 3 \ + -o test-data/big-buck-bunny-480p-30sec.mp4 \ + https://raw.githubusercontent.com/chthomos/video-media-samples/master/big-buck-bunny-480p-30sec.mp4 - name: Run tests and benchmarks run: go test -bench=. -benchmem ./... diff --git a/benchmark_test.go b/benchmark_test.go index 453bdb9..6ccf09f 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -10,7 +10,7 @@ import ( func loadTestFile(b *testing.B) []byte { b.Helper() - data, err := os.ReadFile("video-media-samples/big-buck-bunny-480p-30sec.mp4") + data, err := os.ReadFile("test-data/big-buck-bunny-480p-30sec.mp4") if err != nil { b.Skipf("test file not available: %v", err) } @@ -143,7 +143,7 @@ func BenchmarkWriterBuild(b *testing.B) { } func BenchmarkScannerParse(b *testing.B) { - path := "video-media-samples/big-buck-bunny-480p-30sec.mp4" + path := "test-data/big-buck-bunny-480p-30sec.mp4" f, err := os.Open(path) if err != nil { b.Skipf("test file not available: %v", err) diff --git a/fragment/reader_test.go b/fragment/reader_test.go index 96dddaf..946490f 100644 --- a/fragment/reader_test.go +++ b/fragment/reader_test.go @@ -10,7 +10,7 @@ import ( "github.com/tetsuo/mp4/fragment" ) -const testFile = "../video-media-samples/big-buck-bunny-480p-30sec.mp4" +const testFile = "../test-data/big-buck-bunny-480p-30sec.mp4" func openTestFile(t testing.TB) *os.File { t.Helper() diff --git a/test-data/.gitignore b/test-data/.gitignore index 2641667..662c773 100644 --- a/test-data/.gitignore +++ b/test-data/.gitignore @@ -1 +1,2 @@ *.mp4 +*.m4a diff --git a/test-data/generate-av1.sh b/test-data/generate-av1.sh new file mode 100755 index 0000000..e24193d --- /dev/null +++ b/test-data/generate-av1.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Generates AV1 fixtures for codec-string tests. libsvtav1 emits profile 0, +# main-tier streams, so the av1C fields are patched to cover the combinations +# the codec string builder handles. +set -euo pipefail + +dir="$(cd "$(dirname "$0")" && pwd)" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +base="${tmp}/base.mp4" + +ffmpeg -y -loglevel error \ + -f lavfi -i "testsrc=duration=1:size=320x240:rate=30" \ + -c:v libsvtav1 -pix_fmt yuv420p -g 30 \ + -movflags +faststart "$base" + +# patch writes av1C byte 1 (seq_profile<<5 | seq_level_idx) and byte 2 +# (seq_tier<<7 | high_bitdepth<<6 | twelve_bit<<5), then saves the file. +patch() { + python3 - "$base" "$1" "$2" "${dir}/$3" <<'PY' +import sys + +src, b1, b2, out = sys.argv[1], int(sys.argv[2], 16), int(sys.argv[3], 16), sys.argv[4] +data = bytearray(open(src, "rb").read()) +i = data.find(b"av1C") +if i < 0: + raise SystemExit("av1C box not found") +data[i + 5] = b1 +data[i + 6] = b2 +open(out, "wb").write(data) +PY + echo "wrote $3" +} + +patch 08 00 av1-main8-level8.mp4 # av01.0.08M.08 +patch 0c 00 av1-main8-level12.mp4 # av01.0.12M.08 +patch 0c c0 av1-hightier10.mp4 # av01.0.12H.10 +patch 48 60 av1-profile2-12bit.mp4 # av01.2.08M.12 diff --git a/test-data/generate.sh b/test-data/generate.sh index 7780b0f..423d852 100755 --- a/test-data/generate.sh +++ b/test-data/generate.sh @@ -1,12 +1,11 @@ #!/usr/bin/env bash -# Generates synthetic ISOBMFF files for benchmarking the track parser. Each file -# carries an H.264 video track and an AAC audio track. B-frames produce a ctts -# table and faststart places the moov box before mdat. +# Generates deterministic ISOBMFF fixtures used by tests and benchmarks. set -euo pipefail dir="$(cd "$(dirname "$0")" && pwd)" -gen() { +# Progressive H.264/AAC files with B-frames and a front-loaded moov. +gen_av() { local dur="$1" name="$2" ffmpeg -y -loglevel error \ -f lavfi -i "testsrc=duration=${dur}:size=640x480:rate=30" \ @@ -18,5 +17,62 @@ gen() { echo "wrote ${name}" } -gen 10 h264-aac-10s.mp4 -gen 60 h264-aac-60s.mp4 +gen_av 10 h264-aac-10s.mp4 +gen_av 60 h264-aac-60s.mp4 + +# Audio-only input exercises fragment cuts without a video clock. +ffmpeg -y -loglevel error \ + -f lavfi -i "sine=frequency=440:duration=10:sample_rate=48000" \ + -c:a aac -b:a 128k -movflags +faststart \ + "${dir}/aac-10s.mp4" +echo "wrote aac-10s.mp4" + +# Exact one-second GOPs exercise fragments containing interior keyframes. +ffmpeg -y -loglevel error \ + -f lavfi -i "testsrc=duration=10:size=640x480:rate=30" \ + -f lavfi -i "sine=frequency=440:duration=10:sample_rate=48000" \ + -c:v libx264 -preset veryfast -pix_fmt yuv420p \ + -g 30 -keyint_min 30 -sc_threshold 0 \ + -c:a aac -b:a 128k -movflags +faststart \ + "${dir}/h264-aac-10s-gop1.mp4" +echo "wrote h264-aac-10s-gop1.mp4" + +# Two aligned video renditions and two audio tracks exercise muxed track +# selection and fragment-boundary validation. +ffmpeg -y -loglevel error \ + -f lavfi -i "testsrc=duration=3:size=160x90:rate=10" \ + -f lavfi -i "testsrc2=duration=3:size=128x72:rate=10" \ + -f lavfi -i "sine=frequency=440:duration=3:sample_rate=48000" \ + -f lavfi -i "sine=frequency=880:duration=3:sample_rate=48000" \ + -map 0:v -map 1:v -map 2:a -map 3:a \ + -c:v libx264 -preset veryfast -profile:v baseline -pix_fmt yuv420p \ + -g 10 -keyint_min 10 -sc_threshold 0 \ + -c:a aac -b:a 64k -movflags +faststart \ + "${dir}/h264-2video-2audio-3s.mp4" +echo "wrote h264-2video-2audio-3s.mp4" + +# More than four tracks exercises dynamically-sized reader and writer state. +audio_inputs=() +audio_maps=() +for i in 0 1 2 3 4 5; do + audio_inputs+=( -f lavfi -i "sine=frequency=$((440 + i * 110)):duration=1:sample_rate=48000" ) + audio_maps+=( -map "${i}:a" ) +done +ffmpeg -y -loglevel error \ + "${audio_inputs[@]}" "${audio_maps[@]}" \ + -c:a aac -b:a 32k -movflags +faststart \ + "${dir}/aac-6track-1s.mp4" +echo "wrote aac-6track-1s.mp4" + +# Small audio fixtures cover channel metadata and ALAC sample entries. +ffmpeg -y -loglevel error \ + -f lavfi -i "sine=frequency=440:duration=2:sample_rate=48000" \ + -ac 2 -c:a aac -b:a 128k -movflags +faststart \ + "${dir}/aac-stereo-2s.m4a" +echo "wrote aac-stereo-2s.m4a" + +ffmpeg -y -loglevel error \ + -f lavfi -i "anullsrc=channel_layout=5.1:sample_rate=48000" -t 2 \ + -c:a alac -movflags +faststart \ + "${dir}/alac-5.1-2s.m4a" +echo "wrote alac-5.1-2s.m4a" -- cgit v1.3.1