master-of-zen / Av1an

Cross-platform command-line AV1 / VP9 / HEVC / H264 encoding framework with per scene quality encoding
GNU General Public License v3.0
1.51k stars 155 forks source link

rav1e arguments are broken when used with --target-quality #668

Closed phpb-com closed 2 years ago

phpb-com commented 2 years ago

I was trying to use rav1e encoder for some HDR content and it is failing with:

Queue 1 Workers 1 Passes 2
Params: --speed 0 --quantizer 50 --threads 8 --keyint 48 --min-keyint 48 --content-light 0,0 --mastering-display G(8500,39850)B(6550,2300)R(34000,146000)WP(15635,16450)L(10000000,1) --matrix bt2020nc --primaries bt2020 --transfer arib-std-b67
WARN [av1an_core::broker] Encoder failed (on chunk 0):
encoder crashed: exit status: 2
stdout:

stderr:
        error: Found argument '-q' which wasn't expected, or isn't valid in this context

                If you tried to supply `-q` as a value rather than a flag, use `-- -q`

        USAGE:
            rav1e [OPTIONS] --output <OUTPUT> <INPUT> [SUBCOMMAND]

        For more information try --help

source pipe stderr:

ffmpeg pipe stderr:

WARN [av1an_core::broker] Encoder failed (on chunk 0):
encoder crashed: exit status: 2
stdout:

stderr:
        error: Found argument '-q' which wasn't expected, or isn't valid in this context

                If you tried to supply `-q` as a value rather than a flag, use `-- -q`

        USAGE:
            rav1e [OPTIONS] --output <OUTPUT> <INPUT> [SUBCOMMAND]

        For more information try --help

source pipe stderr:

ffmpeg pipe stderr:

ERROR [av1an_core::broker] [chunk 0] encoder failed 3 times, shutting down worker
ERROR [av1an_core::broker] [chunk 0] encoder crashed: exit status: 2
stdout:

stderr:
        error: Found argument '-q' which wasn't expected, or isn't valid in this context

                If you tried to supply `-q` as a value rather than a flag, use `-- -q`

        USAGE:
            rav1e [OPTIONS] --output <OUTPUT> <INPUT> [SUBCOMMAND]

        For more information try --help

source pipe stderr:

ffmpeg pipe stderr:

The command that spins-up av1an is:

      docker run --privileged -v $(pwd):/videos --user $(id -u):$(id -g) -it --rm av1an:latest \
        -i "test_HDR.mkv" \
        -s test.scenese.json \
        -e rav1e \
        --target-quality "${TQ}" \
        -l "test_log" \
        --concat mkvmerge \
        -p 2 \
        -w 0 \
        -v "--speed 0
            --quantizer 50
            --threads 8
            --keyint 48
            --min-keyint 48
            --content-light '0,0'
            --mastering-display '${MASTER_DISPLAY}'
            --matrix ${COLORSPACE}
            --primaries ${COLORPRIMARIES}
            --transfer ${COLORTRANSFER}" \
        -f "-movflags frag_keyframe+empty_moov+default_base_moof+faststart -vf ${RESOLUTION_FILTER}" \
        -a "-c:a libfdk_aac -profile:a aac_low -b:a 128k -ar 48000" \
        -o test.mkv

I suspect it is --target-quality trying to adjust quality for the scenes.

phpb-com commented 2 years ago

https://github.com/master-of-zen/Av1an/blob/77f77a1aea4bf0162d9ebac91561a0991124852d/av1an-core/src/encoder.rs#L161 https://github.com/master-of-zen/Av1an/blob/77f77a1aea4bf0162d9ebac91561a0991124852d/av1an-core/src/encoder.rs#L243

Is probably where it comes from and is not accepted by rav1e any longer.

phpb-com commented 2 years ago
rav1e --help
rav1e p20220913-4-g17a70d5 (Release)
AV1 video encoder

USAGE:
    rav1e [OPTIONS] --output <OUTPUT> <INPUT> [SUBCOMMAND]

OPTIONS:
    -h, --help
            Print help information

    -V, --version
            Print version information

INPUT/OUTPUT:
    -o, --output <OUTPUT>
            Compressed AV1 in IVF video output

    -y
            Overwrite output file

    <INPUT>
            Uncompressed YUV4MPEG2 video input

THREADING:
        --threads <THREADS>
            Set the threadpool size

            [default: 0]

        --tile-cols <TILE_COLS>
            Number of tile columns. Must be a power of 2. rav1e may override this based on video resolution

            [default: 0]

        --tile-rows <TILE_ROWS>
            Number of tile rows. Must be a power of 2. rav1e may override this based on video resolution

            [default: 0]

        --tiles <TILES>
            Number of tiles. Tile-cols and tile-rows are overridden so that the video has at least this many tiles

ENCODE SETTINGS:
    -b, --bitrate <BITRATE>
            Bitrate (kbps)

        --film-grain-table <FILM_GRAIN_TABLE>
            Uses a film grain table file to apply grain synthesis to the encode. Uses the same table file format as aomenc and svt-av1

        --first-pass <STATS_FILE>
            Perform the first pass of a two-pass encode, saving the pass data to the specified file for future passes

    -i, --min-keyint <MIN_KEYINT>
            Minimum interval between keyframes

            [default: 12]

    -I, --keyint <KEYINT>
            Maximum interval between keyframes. When set to 0, disables fixed-interval keyframes

            [default: 240]

    -l, --limit <LIMIT>
            Maximum number of frames to encode

            [default: 0]

        --low-latency
            Low latency mode; disables frame reordering. Has a significant speed-to-quality trade-off

        --min-quantizer <MIN_QUANTIZER>
            Minimum quantizer (0-255) to use in bitrate mode [default: 0]

        --no-scene-detection
            Disables scene detection entirely. Has a significant speed-to-quality trade-off in full encodes. Useful for chunked encoding

        --photon-noise <PHOTON_NOISE>
            Uses grain synthesis to add photon noise to the resulting encode. Takes a strength value 0-64

            [default: 0]

        --quantizer <QUANTIZER>
            Quantizer (0-255), smaller values are higher quality [default: 100]

        --rdo-lookahead-frames <RDO_LOOKAHEAD_FRAMES>
            Number of frames encoder should lookahead for RDO purposes\n\ [default value for speed levels: 10,9 - 10; 8,7,6 - 20; 5,4,3 - 30; 2,1,0 - 40]

        --reservoir-frame-delay <RESERVOIR_FRAME_DELAY>
            "Number of frames over which rate control should distribute the reservoir [default: min(240, 1.5x keyint)] A minimum value of 12 is enforced

    -s, --speed <SPEED>
            Speed level (0 is best quality, 10 is fastest)
            Speeds 10 and 0 are extremes and are generally not recommended

            [default: 6]

    -S, --switch-frame-interval <SWITCH_FRAME_INTERVAL>
            Maximum interval between switch frames. When set to 0, disables switch frames

            [default: 0]

        --scd-speed <SCD_SPEED>
            Speed level for scene-change detection, 0: best quality, 1: fastest mode. [default: 0 for s0-s9, 1 for s10]

        --second-pass <STATS_FILE>
            Perform the second pass of a two-pass encode, reading the pass data saved from a previous pass from the specified file

        --skip <SKIP>
            Skip n number of frames and encode

            [default: 0]

        --still-picture
            Still picture mode

        --tune <TUNE>
            Quality tuning

            [default: Psychovisual]

VIDEO METADATA:
        --content-light <CONTENT_LIGHT>
            Content light level used to describe content luminosity (cll,fall)

        --frame-rate <FRAME_RATE>
            Constant frame rate to set at the output (inferred from input when omitted)

        --mastering-display <MASTERING_DISPLAY>
            Mastering display primaries in the form of G(x,y)B(x,y)R(x,y)WP(x,y)L(max,min)

        --matrix <MATRIX>
            Matrix coefficients used to describe color parameters

        --primaries <PRIMARIES>
            Color primaries used to describe color parameters

        --range <RANGE>
            Pixel range

        --time-scale <TIME_SCALE>
            The time scale associated with the frame rate if provided (ignored otherwise)

            [default: 0]

        --transfer <TRANSFER>
            Transfer characteristics used to describe color parameters

DEBUGGING:
        --benchmark
            Provide a benchmark report at the end of the encoding

        --metrics
            Calculate and display several metrics including PSNR, SSIM, CIEDE2000 etc

        --psnr
            Calculate and display PSNR metrics

        --quiet
            Do not output any status message

    -r, --reconstruction <RECONSTRUCTION>
            Outputs a Y4M file containing the output from the decoder

        --verbose
            Verbose logging; outputs info for every frame

SUBCOMMANDS:
    advanced
            Advanced features
    help
            Print this message or the help of the given subcommand(s)
redzic commented 2 years ago

I've opened https://github.com/xiph/rav1e/pull/3022 to add back the -q flag

phpb-com commented 2 years ago

why not do it in av1an and just use long form? I am sure I am missing something, but still ...

diff --git a/av1an-core/src/encoder.rs b/av1an-core/src/encoder.rs
--- a/av1an-core/src/encoder.rs
+++ b/av1an-core/src/encoder.rs
@@ -158,7 +158,7 @@ impl Encoder {
       )
       .collect(),
       Self::rav1e => chain!(
-        into_array!["rav1e", "-", "-y", "-q"],
+        into_array!["rav1e", "-", "-y", "--quiet"],
         params,
         into_array!["--first-pass", format!("{}.stat", fpf), "--output", NULL]
       )
@@ -240,7 +240,7 @@ impl Encoder {
       )
       .collect(),
       Self::rav1e => chain!(
-        into_array!["rav1e", "-", "-y", "-q"],
+        into_array!["rav1e", "-", "-y", "--quiet"],
         params,
         into_array!["--second-pass", format!("{}.stat", fpf), "--output", output]
       )
redzic commented 2 years ago

why not do it in av1an and just use long form?

My reasoning was that you have to update one of the binaries either way, and fixing it in rav1e would also fix any other scripts/programs that were broken by the removal of the flag. I'll make a PR for av1an as well though.

phpb-com commented 2 years ago

Very good point, thanks for explanation. Yeah, it must have broken a few scripts out there.