Hello All! I would like to propose a libavcodec wrapper for libgail, a GPU JPEG 2000 encoder that produces DCI-compliant codestreams (SMPTE ST 428-1 / ST 429-4, 2K and 4K, 12-bit X'Y'Z', under the 250 Mbit/s frame limit) for digital cinema packages (DCP).
These packages are used in digital cinema outlets such as your local theater. Cinema servers and projectors cannot play ordinary video files like MP4 or MKV at all. Content must be encoded as DCI-compliant JPEG 2000 and wrapped in a DCP (Digital Cinema Package), or the projector will not play it. Simply encoding to JPEG 2000 is not enough, it must be DCI compliant or the projector will not play it. GAIL (libgail) is the first open source, GPU accelerated (CUDA/Vulkan) encoder for this format. (A CPU backend is also supported, but GPU acceleration is the focus) Before preparing a full submission I would like to ask whether a libgail wrapper would be welcome, and whether there is anything you would want changed. The library - GAIL, the GPU Accelerated Intraframe Library: https://github.com/Josephur/libgail - MIT licensed, with a C API (include/gail/gail.h) and a stable soname (libgail.so.1). It is found with pkg-config ("gail"). - Backends: CUDA (NVIDIA Turing or newer), Vulkan 1.3 (any vendor in principle, tested on NVIDIA only so far) and a CPU backend. The Tier-1 output of all three is bit-identical, so the CPU backend works anywhere. CI builds and runs the tests on Linux, Windows and macOS (CPU backend on the CI runners, which have no GPU). - Everything in the DCI pipeline runs on the GPU, including EBCOT Tier-1 entropy coding and rate control to the per-frame byte limit. I wrote this to be FFmpeg-forward first. Another project, dcp-o-matic has been discussing integration with me as well, and that integration should be complete in its next major version. Currently dcp-o-matic users sit through hours of encoding to prepare a simple movie for projection, or they pay commercial products like Grok $250/mo for the privilege. The wrapper - libavcodec/libgailenc.c, about 390 lines, licensed MIT OR LGPL-2.1-or-later. It follows the libopenjpeg wrapper's approach: one codestream per packet. - Input pixel formats: yuv420p/422p/444p (8, 10 and 12 bit), gbrp (8 to 16 bit), rgb48le and xyz12le. Y'CbCr and R'G'B' input is converted to X'Y'Z' by the library from the stream's colour tags (transfer, primaries, matrix, range, mastering peak); xyz12le is encoded as is, so a filter graph can do the conversion instead if preferred. - The options are the DCI profile (2K/4K), the container (flat, scope, full), the bitrate (-b:v or -mbps, default 230, DCI limit 250), the backend, the GPU list, frames in flight, and HDR and gamut handling. - It is enabled with --enable-libgail. I also added documentation (doc/encoders.texi and doc/general_contents.texi) and a Changelog entry. - Tested on current master (baa68e6, no warnings from the new file): 4K HDR10 H.264 in, 240 frames out. Every codestream passed the library's own DCI conformance checker, all 240 frames decode with FFmpeg's native jpeg2000 decoder (and a sample frame with OpenJPEG), and the frames wrapped into a SMPTE DCP pass libdcp's dcpverify. Why a wrapper - FFmpeg's native jpeg2000 encoder is not aimed at DCI profiles, and libopenjpeg can produce them but only on the CPU. On my machine (Ryzen 9 5900X, RTX 3090 + RTX 5060 Ti) libgail encodes 4K at about 250 frames/s on the two GPUs with frames preloaded, and about 127 fps end to end from an H.264 file through ffmpeg. OpenJPEG's DCI 4K encoder manages about 1.5 fps on 24 CPU threads. Charts and details are in the repository (docs/BENCHMARKS.md). - The DCPs have been played back on Christie Solaria One, CP2210 and CP2220 and NEC NC900C-A projectors, a GDC SR-1000 media block and ScreenWriter Plus 2.7.5-1983 (docs/VALIDATION.md). Disclosure and licensing - The library and wrapper were developed with substantial AI assistance (Claude), under my direction and review. I did not reverse engineer anything or steal code, I based it on the standards. I am the author of record and take responsibility for the code. I know there was an RFC here in 2025 about AI contributions, so I would rather say this up front. Nothing is copied from OpenJPEG, FFmpeg internals, libdcp or other codecs; constants and tables come from the ISO/IEC 15444-1 and SMPTE standards and are cited in the source. Open questions - Would you accept an external-library wrapper for a young library like this one, or would you want it to be packaged by distributions first? - Is there anything about CUDA or GPU-specific code that would be a concern? The wrapper itself only uses the library's C API, and the CPU and Vulkan backends are open. - Is a FATE test possible? The CPU backend would work on any machine, but the test would depend on the library being installed. I have the patch ready on top of current master (one commit: wrapper, configure, docs and Changelog) and can send it with git send-email as soon as you would like to see it. Thanks for any thoughts, Joseph Stackhouse _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
