From 1d9b2f4b6486bbb4b0ff4a635f74f31a162f2876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 12 Aug 2026 22:33:46 +0300 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20deps(h264):=20the=20softwa?= =?UTF-8?q?re=20decoder=20now=20agrees=20with=20ffmpeg,=20picture=20for=20?= =?UTF-8?q?picture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `rusty_h264` 0.8 was not bit-exact. Across a 1080p High and a 720p Main clip -- 750 pictures, both with B-frames -- it reproduced ffmpeg's own decode byte-for-byte on 26 of them and drifted on the other 724, worst case 69.8 dB PSNR. That is invisible on a monitor and still wrong: it is the picture a grade is measured on, the picture a still is exported from, and the picture a software export re-encodes. 0.9.1 matches ffmpeg on all 750, which is the property the manifest already demands of `ruopus` and `oxideav-ac3` and had never actually checked here. Pinned exactly for the same reason they are. It is faster by the same stroke: 247 Mpx/s against 171 decoding the 1080p clip, 256 against 176 on the 720p one -- 1.44x, single-threaded, min of 20 interleaved rounds on a loaded box (a second binary built from the same 0.9.1 sources came within 1%, which is what the interleaving is for). Software encode is a wash at 1.04x and 0.97x, so nothing about an export's speed changes; what changes is what it encodes *from*. The challenger measured against it, `rust_h264` 0.4.0 (MIT/Apache-2, pure Rust, decode only), does not take the seat on either axis: 1.00x and 0.88x of 0.8's decode rate, so 0.69x of this crate's, and it is not bit-exact either -- 256 of the same 750 pictures, worst 39.2 dB, and the mismatches are pixels ffmpeg never emitted rather than a reordering. The gate wanted 1.25x and no correctness regression; it returned neither. `default-features = false` stays, and keeps the vendored openh264 SIMD kernels (`asm`, `nasm` at build time) out of a build this project promises needs no tools. It does not keep out `rusty_alloc`: the facade pulls its sub-crates with their own defaults and `rusty_h264-common` installs that allocator process-wide for the whole app. Nothing downstream can switch it off. Measured at 0.104 s against glibc's 0.142 s on 2M mixed allocations, so it is a gift rather than a tax -- but it is a gift nobody asked for, and the manifest now says so. --- Cargo.lock | 45 +++++++++++++++++++++++++++++++++------- crates/engine/Cargo.toml | 25 +++++++++++++++++++++- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a22700..d67fee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5012,11 +5012,30 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" name = "rusty_aac" version = "0.5.0" +[[package]] +name = "rusty_alloc" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5f05c71564028538eeba6e2e08c6a512267e85e6a1584beca45c6f26af8651b" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "rusty_alloc-api" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c8c3ecd14424ba980d005147945a745836dea7798d447c419e08be1f79e88f" +dependencies = [ + "rusty_alloc", +] + [[package]] name = "rusty_h264" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fbafa4757ced9c5c1d1185aa936bb040b00c456098874f209e04ed1c1c2d73b" +checksum = "690044fc22dedcc09367177bd50cc7f6b46b72f3227d35a9311e69c64c2a73d4" dependencies = [ "rusty_h264-common", "rusty_h264-decoder", @@ -5025,28 +5044,29 @@ dependencies = [ [[package]] name = "rusty_h264-common" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "421e458fcfcb2580232f212f99451f9075a03d00752a934ee27be6148a6765e3" +checksum = "ed3c3c7ad3a43386460736b7552ab82239bdd703bedcf8c7f5d0032c50cfb8cb" dependencies = [ "bytemuck", + "rusty_alloc-api", "wide", ] [[package]] name = "rusty_h264-decoder" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6316ecba57a77d530fff4fab7be9cc3e0e107e381360ac9d2ffa0895b5b0947a" +checksum = "1cd475fe0f7480930bf735275111922733a323cb9ef7d83d825a0222ccde9fb4" dependencies = [ "rusty_h264-common", ] [[package]] name = "rusty_h264-encoder" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fb69d8977d1d067d6d603df0614678c4a35ac1201fff38783c8847e429c879" +checksum = "8100c6b118fa62ff4f021b47cf2d6feb423dad78e3dec5d8dfc2d0ff3a6729bb" dependencies = [ "rusty_h264-common", ] @@ -7190,6 +7210,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + [[package]] name = "windows-sys" version = "0.61.2" diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 8228f2a..cb64763 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -28,7 +28,30 @@ mp4 = "0.14" # pulls this exact version in through `png`, and it is the pure-Rust inflate the # rest of the ecosystem is built on. miniz_oxide = "0.8" -rusty_h264 = { version = "0.8", default-features = false } +# The software H.264 pair, and the only software decoder this project has for +# any format. Pinned exactly, like `ruopus` and `oxideav-ac3` below, because a +# decoder is a bit-exactness dependency -- and 0.9.1 is where that stopped being +# a figure of speech. Measured 2026-08-12 against ffmpeg's own decode of a 1080p +# High and a 720p Main clip, 750 pictures between them: 0.8 matched it +# byte-for-byte on 26 of the 750 and drifted on the rest (worst 69.8 dB PSNR -- +# invisible, but wrong); 0.9.1 matches on all 750. It is also 1.44x faster at it +# (247 Mpx/s against 171 on the 1080p clip, single-threaded); software *encode* +# is unchanged within noise, so this is a decode bump that the encoder came +# along with. `default-features = false` is what keeps `asm` off: those are +# vendored openh264 SIMD kernels that want `nasm` at build time, which this +# project's no-install rule forbids, and the crate enables them by default. +# +# What that line does not turn off, and cannot: the facade asks for its three +# sub-crates with *their* defaults, and `rusty_h264-common`'s default installs +# `rusty_alloc` -- a pure-Rust mimalloc remake, MIT -- as the process-wide +# `#[global_allocator]`, for the whole application rather than the codec. No +# feature choice downstream switches it back off; only a vendored `common` +# would. It is not a regression to pay for: the same 2M-allocation churn runs in +# 0.104 s under it against 0.142 s under glibc's, so it stays, and this +# paragraph is the disclosure. Frame-threaded decode arrived in 0.9 as well and +# is opt-in through `RS_H264_FRAME_THREADS`, unset here -- the decode loop is +# serial exactly as it was. +rusty_h264 = { version = "=0.9.1", default-features = false } # Both halves of AAC, and the only crate here that is asked for both. The # *encoder*, so an mp4's sound can be a mix rather than a copy: an equalized (or # otherwise processed) lane has to be decoded, and what is decoded has to be