Skip to content

Measure speed against ffmpeg (single core) and file the gaps #2

Open

Description

@tannevaled

Wave D1 (#1) left the speed comparison undone: the machine's 1-minute load was
36 to 50 throughout, and a measurement is not taken above 8.

To do, when load allows: single core (GOMAXPROCS=1), interleaved rounds,
ffmpeg -threads 1 -f null as the reference, on the 1080p and 720p clips the
README lists and a CIF conformance stream. Report frames/s for both and the
ratio; anything slower than ffmpeg is a defect to open against go.264 with the
profile (algorithm first, then SIMD kernels through go-simd / go-asmgen).

Only indication so far, not a measurement (load ~50): a 900-picture 1080p clip
decoded in 28.7 s wall clock.

Also: decode.Decoder copies every output picture out of the reference buffer
(one allocation per frame); a caller-supplied buffer or pool is the obvious
first saving.

Activity

  1. tannevaled commented on Nov 10, 2026

    @tannevaled
    ContributorAuthor

    Speed against ffmpeg, single core: v0.3.0 is slower on every input measured (open defect)

    Baseline: clean clone of tag v0.3.0 (library code identical to main; the only addition is the jvt bench command from the PR that will follow). Apple M4 Max, darwin/arm64, Go 1.27.3, ffmpeg 9.0.2 (Homebrew, clang). Ours: GOMAXPROCS=1, whole input decoded from memory, pictures counted and dropped. ffmpeg: -threads 1 -benchmark -f null - -fps_mode passthrough, fps taken from its own rtime. Interleaved rounds (ours, ffmpeg, ours, ffmpeg...), 5 rounds each, median and (min-max). The harness refuses to start a run when the 1-minute load is >= 8.

    Load before each run: 7.21 / 7.65 / 7.97 (min / median / max) for the bitstreams, 5.89 / 6.62 / 7.69 for the real clips. Times are indicative at that load (the ratios are stable across rounds, spread below); allocation counts are exact.

    input frames ours fps ffmpeg fps ratio ours/ffmpeg allocs/frame KiB/frame
    H.264 High 1080p (real, 1920x808, 600 frames) 600 36.5 (36.4-36.7) 173.1 (171.9-175.9) 0.21 46.3 6733
    HEVC Main 10 2160p (real, 3840x1606, 60 frames) 60 10.3 (10.2-10.3) 27.9 (27.4-27.9) 0.37 30.9 20406
    base_ip_qp26.264 (Constrained Baseline 176x144, x100) 1000 4436 (3924-4482) 20833 (11628-20833) 0.21 34.1 157
    main_ipb_cabac.264 (x100) 1000 3017 (2722-3043) 9901 (9174-10309) 0.30 35.5 159
    main_cif_pyramid.264 (x100) 800 1017 (995-1031) 4396 (4233-4420) 0.23 38.1 514
    high_ipb_8x8_cabac.264 (x100) 1000 2902 (2848-2945) 9709 (9009-10417) 0.30 38.4 159
    main_ipb.265 (x100) 1200 10195 (9575-10528) 27907 (27907-28571) 0.37 49.2 17
    main10_ipb.265 (x100) 1200 9248 (8968-9394) 22642 (13953-23529) 0.41 26.6 26
    main_wpp_slices.265 (x100) 1200 2691 (2594-2781) 8889 (7843-9023) 0.30 152.4 59
    main10_wpp_slices.265 (x100) 1200 2425 (2376-2484) 6667 (6154-6704) 0.36 41.8 91

    Notes on the inputs. The committed bitstreams are a few pictures long, so each was concatenated 100 times (valid: each copy opens with its IDR) into a durable directory and both sides decode that file; ffmpeg's clock has 1 ms resolution, the unrepeated run is not measurable. The two real files are stream-copy clips cut with ffmpeg from local files at minute 40 (-ss 2400, 600 and 60 packets), nothing committed. No real HEVC Main file exists in the library (both x265 files are Main 10, 2160p); HEVC Main is covered by main_ipb/main_wpp_slices only. The JVT/JCT-VC conformance bitstreams themselves are not in the repository (md5 only), so they were not used. Frame counts equal on both sides for every input.

    Open defects (every row is slower than ffmpeg)

    Profile (jvt bench --cpuprofile, pprof top) of the two real inputs. Nothing below was changed.

    H.264, ratio 0.21. The profile is spread over go.264's pure Go kernels, no single hot spot in our wrapper:

    • oops1/go.264@v1.12.0/internal/simd/generic.go:197-203 hFilter1, the 6-tap luma filter, 15.7 % flat (4.6 s of 29.3 s); with vFilter1 (:206), sixTapHorizGeneric (:225), sixTapVertGeneric, sixTapHVGeneric the interpolation is about 35 % cumulative.
    • Cause: internal/simd/dispatch_generic.go:40 (sixTapHorizGeneric) is the build for everything that is not amd64; the assembly kernels exist only in kernels_amd64.s. On arm64 there is no NEON path, while ffmpeg uses NEON. (This table is arm64; an amd64 measurement is needed to know whether AVX2 closes the gap.)
    • CABAC residual decoding is next: internal/cabac DecodeDecision 15 % cumulative, ResidualBlock8x8 11 %. Then deblocking (internal/deblock.filterEdge 5 %), transform.Inverse8x8 4.7 %.
    • Our wrapper: decode.go:257-276 (*Decoder).frame (the per-picture plane copy) is 0.44 % of CPU, so the "one allocation per frame" noted in the issue is not the cause of the gap. Allocation is 46 per picture and 6.7 MiB per 1920x808 picture, while the output planes are 2.3 MiB: the rest is allocated inside go.264, not attributed.

    HEVC Main 10, ratio 0.37 (Main 0.30-0.37 on the small streams). gen2brain/h265@v0.2.4:

    • hevc/interpred.go:63-199 mcLuma[uint16] 39 % cumulative (4.16 s of 10.6 s), mcChroma[uint16] 15 %. The assembly kernels are taken only when bitDepth == 8 && w%8 == 0 (interpred.go:96-104); at 10 bits they fall to the scalar loops, with the 8-tap inner loop through the closure at at interpred.go:90-92 (1.1 s flat on that line alone) and the separable 2-D case at interpred.go:177-197 (about 2.8 s). So the Main 10 path has no SIMD motion compensation at all.
    • predBiGo[uint16] 5 %, decodeResidual 11 % cumulative; idctCols4NEON is present (0.7 s), so the transforms are partly vectorised already.
    • Our wrapper: hevc.go:235-243 cropPlane16 (16-bit planes to little-endian bytes, byte by byte) is 3.9 % of CPU, a small wrapper-side saving available (encoding/binary or a unsafe-free bulk copy when no cropping is needed); not done.
    • Allocation: 20.4 MiB per 3840x1606 picture against 18.5 MiB of output planes.

    The gap is therefore mostly upstream (no arm64 SIMD in go.264; no 16-bit SIMD in h265 motion compensation) and should be filed there after the amd64 numbers are in, per the doctrine of putting kernels in the lowest shared library (go-simd / go-asmgen); not filed from this task. Wrapper-side: cropPlane16, and caller-supplied buffers to remove the per-frame allocation (memory, not time).

    Harness: jvt bench in the tools module (PR to follow, Refs #2): jvt bench --rounds 5 [--repeat N --workdir D] [--cpuprofile F] [--wait 8m] PATH....

  2. tannevaled commented on Nov 10, 2026

    @tannevaled
    ContributorAuthor

    Audio (wave D3, #11, #14, #15): speed against ffmpeg was not measured. The 1-minute load was 18 when the work began and 36 when a measurement was tried, above the limit of 8.

    What is ready for it: BenchmarkAudioTrack in the audio branches decodes the file named by DECODE_BENCH_FILE (a long .mp3, .flac or .ogg) through DecodeAudioTrack and reports MB/s of PCM; the comparison is ffmpeg -threads 1 -i FILE -f null - timed over the same file, interleaved rounds, at load below 8. FLAC (mewkiz/flac), MP3 (tphakala/go-mp3, a minimp3 port) and Opus (pion/opus) are the three to measure; a gap is an open defect.

  3. tannevaled commented on Nov 10, 2026

    @tannevaled
    ContributorAuthor

    hevc-main-ipb.mp4 / hevc-main10-ipb.mp4: ffmpeg returns 10 pictures, we return 12 (localised: not a decode defect)

    Follow-up to the 12/10 count seen while measuring above; checked before anything else, as a correctness question.

    Evidence (ffmpeg 9.0.2, -threads 1, -f framemd5):

    • mp4ff-info: both files have elst with one entry segmentDuration=480000 mediaTime=96000 (timescale 1200000, so the edit starts 2 frames into the media; mdhd duration is 576000 = 12 frames), a single stts entry, and no ctts box, although the streams contain B pictures. ffprobe -show_entries packet therefore gives pts = dts = -2, -1, 0, ... frames and flags the first two packets D (discard: before the edit start).
    • ffmpeg default and -fps_mode passthrough give 9 and 10 pictures; the null/framemd5 muxer's frame-rate logic only changes how timestamps repeat, it is not what drops pictures.
    • -ignore_editlist 1 gives 12 pictures, and the same 12 MD5s as ffmpeg decoding the raw main_ipb.265 stream, and as our DecodeTrack (checked: ours == -ignore_editlist, ours != default).
    • The two pictures ffmpeg drops are display indexes 0 and 4 of our output: the I and the first P, i.e. the pictures of the first two samples in decoding order. Without ctts the decoding order is the presentation order the edit list is applied to.

    Verdict: (b). All 12 pictures are really in the stream; ffmpeg's default drops those that the edit list places before the start of presentation. decode returns every decoded picture with its PTS and leaves presentation trimming to the caller (avkit's edit-list handling), so there is no defect here and no change. The fixtures are valid files, only unusual (elst without ctts, as an ffmpeg remux of a raw HEVC stream gives).

    Same check on the H.264 fixtures: bframes.mp4, bframes-delayed.mp4 and bframes.mkv return 10/10 with identical MD5s on both sides. bframes.mp4 also has an elst (mediaTime=1280, 2 frames) but carries a ctts that shifts the presentation times by the same amount, so nothing is trimmed. (hvc1.mp4 is the deliberately undecodable fixture.)

    Consequence for the oracle: comparing a container file with ffmpeg -f framemd5 is exact only when the file's edit list trims no picture; -ignore_editlist 1 is the flag that compares decoding alone. The real-file hashes in testdata/*real-files.txt are stream-copy clips whose counts matched, so they are unaffected.

  4. tannevaled commented on Nov 10, 2026

    @tannevaled
    ContributorAuthor

    AAC-LC speed against ffmpeg: not measured. The 1-minute load was 19 to 61 each time I tried on 2026-11-10 (the limit is 8), so no number is given. BenchmarkAACDecode (aac_bench_test.go, PR #31) decodes the pinned conformance stream al05_48 (stereo, 48 kHz, about 7.4 s) single core; run it with AAC_CONFORMANCE_DIR set and -cpu 1, interleaved with ffmpeg -threads 1 -benchmark -i al05_48.mp4 -f null - (and -cpuflags 0 for the C paths) once the load is low. An indication under load, not a result: 9.3 ms per op for the benchmark, which is about 800 times real time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions