Decoder for DCI XYZ' JPEG2000 streams into YUV with colorspace correction.
Find a file
2024-09-18 13:17:36 +02:00
bin Initial commit 2024-02-19 20:06:49 +01:00
cmd Make limited YUV range not clamp as strict 2024-09-18 13:17:36 +02:00
colorspace Make limited YUV range not clamp as strict 2024-09-18 13:17:36 +02:00
converter Make limited YUV range not clamp as strict 2024-09-18 13:17:36 +02:00
libav Add support for concat input files 2024-09-17 14:33:29 +02:00
libopenjp2 Minimize jp2 copies 2024-09-07 13:31:43 +02:00
scripts Add subtitles to mpv script 2024-09-18 05:04:23 +02:00
utils Implement fast matrix[3x3] * vec[3] multiplication for go pipeline 2024-09-07 15:00:07 +02:00
.gitignore Initial commit 2024-02-19 20:06:49 +01:00
.gitmodules Move conv to converter 2024-09-04 09:26:05 +02:00
build.sh Move xyz2yuv cmd to its own folder 2024-09-04 10:39:48 +02:00
go.mod fallback frame rate fetch from stream 2024-08-26 12:49:47 +02:00
go.sum fallback frame rate fetch from stream 2024-08-26 12:49:47 +02:00
LICENSE Initial commit 2024-02-19 20:06:49 +01:00
README.md Update README.md 2024-09-07 15:02:17 +02:00

xyz2yuv tool

Decode DCI XYZ' and apply conversions to your desired output colorspace. Supports Rec. 709 and Rec. 2020, with adjustable precision and gamma values.

Supports AVX-512 and AVX2 targets, and a generic implementation in C and Go as well.

See go-dcp for a tool that can handle sample trailer DCPs.

Dependencies

  • Go >= 1.22
  • CGO enabled and working
  • libopenjp2-dev OpenJPEG
    • Necessary due to FFMPEG's JPEG2000 now default decoder being broken and producing corrupted output.
  • libavformat-dev
  • libavcodec-dev
  • libavutil-dev

Build

# initialize conv/simd_utils
git submodules update --init

# build binaries with specific Go toolchain path
GOROOT=~/go/go1.22.4 ./build.sh

After building multiple tools will appear under bin/. These binaries are compiled with

  • xyz2yuv: Defaults to use the highest native features available. This includes 512-bit pipeline and AVX-512 usage if supported.
  • xyz2yuv_avx2: Disables AVX-512 and 512-bit pipelines. Prefer using the above on most systems as it will pick native features.
  • xyz2yuv_2pump: Executes two unrolled operations per loop. Might be faster on systems with only AVX2 or better superscalar support.
  • xyz2yuv_4pump: Executes four unrolled operations per loop. Might be faster on systems with only AVX2 or better superscalar support.
  • xyz2yuv_8pump: Executes eight unrolled operations per loop. Might be faster on systems with only AVX2 or better superscalar support.

Usage

The input file must include a video stream with codec JPEG2000 and with pixel format XYZ12. Other video inputs are unsupported.

Any other tracks (audio/subtitles) will be ignored.

Most containers that ffmpeg can support are valid, usually this will be MXF or Matroska.

You need to select the color space that matches what you need. Sometimes custom gamma values are applied on mastering depending on viewing targets. Custom color spaces can be defined via JSON files. See colorspace/config for examples. Companding transfer functions require -use-go-pipeline

Performance can be increased by using -float to reduce the precision of the conversion pipeline. This will cause precision issues.

Low-resolution JPEG2000 decoding can be implemented via -lowres parameter. Value of zero equals original resolution.

Default output is in the form of YUVMPEG2 16-bit 4:4:4 with full color range. Bit depth is configurable to 10/12/14/16 bit, and you can request limited range output.

It can output to a file or stdout for immediate consumption.

./bin/xyz2yuv -lowres=0 \
-in /path/to/input.mkv \
-colorspace "rec709_pure22" \
-out /path/to/output.y4m
Usage of xyz2yuv:
  -colorspace string
        Path to JSON colorspace and parameters to convert into. Default templates: rec709, rec709_pure22, rec709_pure24, rec2020, rec2020_pure22, rec2020_pure24, srgb, dci-p3 (default "rec709_pure22")
  -decoder-threads uint
        Threads for JPEG2000 decoding. Defaults to number of logical CPU
  -depth int
        Output bit depth. Must be one of 10, 12, 14, 16 (default 16)
  -end uint
        End frame number exclusive (default 18446744073709551615)
  -float
        Use float pipeline instead of double, although less precise. Very fast.
  -hash
        Hash with SHA256 each output frame for accuracy comparisons
  -in string
        Input file
  -limited
        Output limited/tv YUV range instead of full/pc range
  -lowres uint
        Feed lowres parameter. Default is full resolution
  -out string
        Output file. Use - for stdout (default "-")
  -pipeline-threads uint
        Threads for colorspace conversion pipeline. Defaults to number of logical CPU
  -precision-rgb2yuv int
        RGB -> YUV conversion matrix precision. 0 = maximum
  -precision-xyz2rgb int
        XYZ -> RGB conversion matrix precision. 0 = maximum
  -progress
        Output progress and speed information
  -start uint
        Start frame number inclusive
  -use-go-pipeline
        Use Go pipeline, although slower. Does not support float mode.

Scripts

MPV playback

For convenience mpv playback scripts are included under scripts/.

The first audio track from the input file will also be included in the playback.

Playback will be loosely seekable as it decodes from pipe. 4 GiB of cache is default and recommended to keep a few seconds of buffer.

Rec. 709 output

./scripts/playback-rec709_22-mpv.sh /path/to/input.mkv

Rec. 2020 output

./scripts/playback-rec2020_24-mpv.sh /path/to/input.mkv

ffmpeg FFV1 lossless encode