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.52k stars 156 forks source link

gbrp pixel format gets "End of file" error #827

Open bczhc opened 7 months ago

bczhc commented 7 months ago

Maybe a follow-up of #395. Demonstration file (audio muted).

Hello. I use ffmpeg x11grab to record lossless rgb videos like this:

ffmpeg -f x11grab -framerate "$framerate" -i "$DISPLAY" \
        -f pulse -i "$pulse_device" \
        -c:v libx264rgb -r "$framerate" ${=FF_ARGS} \
        -crf 0 \
        -preset ultrafast \
        -c:a libopus -b:a 96k \
        "$output_file"

But when using av1an, it gives "End of file" error during scene scanning.

~/screenrecord ❯ ~/av1an --sc-only -s scenes.json -i 1.mp4                                                                                                                                 07:50:46
INFO [av1an_core::context] Input: 2560x1440 @ 30.000 fps, GBRP, SDR
Scene detection
⠒ 00:00:01 ▕                                                                                                                                                      ▏   0%  0/300 (0 fps, eta unknown)
Error: End of file

Also, if hevc gbrp (Rext profile) is used, e.g.:

ffmpeg -i 1.mp4 -c:v hevc_nvenc -b:v 50M -pix_fmt gbrp 2.mp4

Then for 2.mp4, av1an gives the same error.

av1an --version:

av1an 0.4.1-unstable (rev e69826f) (Release)

* Compiler
  rustc 1.75.0-nightly (LLVM 17.0)

* Target Triple
  x86_64-unknown-linux-gnu

* Date Info
  Commit Date:  2024-04-23

* VapourSynth Plugins
  systems.innocent.lsmas : Not found
  com.vapoursynth.ffms2  : Not found
  com.vapoursynth.dgdecodenv : Not found
  com.vapoursynth.bestsource : Not found
master-of-zen commented 7 months ago

Try converting to yuv420p lossless with ffmpeg, or use vapoursynth script that use your video as input and converts to yuv420p, and set that script as input

bczhc commented 7 months ago

Actually what does "yuv420p lossless" mean please? If I first convert it to yuv420p (or yuv420p10le) using ffmpeg, and then set it as the input of av1an, it will work.

For screenrecords I prefer rgb instead of yuv, and ffmpeg can do this. That's, these two ffmpeg commands will work:

# gbrp
ffmpeg -i 1.mp4 -c:v libaom-av1 -row-mt 1 -tile-rows 2 -tile-columns 2 -tune psnr -cpu-used 5 -crf 50 -threads 16 -pix_fmt yuv420p a.mkv

# yuv420p
ffmpeg -i 1.mp4 -c:v libaom-av1 -row-mt 1 -tile-rows 2 -tile-columns 2 -tune psnr -cpu-used 5 -crf 50 -threads 16 -pix_fmt yuv420p b.mkv

I used to hear of, that aomenc cannot output rgb videos, and this is a limitation of aomenc the CLI but not libaom-av1 the library which ffmpeg uses? May be related to aomenc?

master-of-zen commented 7 months ago

Actually what does "yuv420p lossless" mean please?

It means convert video with something like ffmpeg x264 yuv420p for compatible color space, and using crf 0 for lossless encoding, so there is no quality loss.

ffmpeg -i input -c:a copy -c:v libx264 -crf 0 -pix_fmt yuv420p input_for_av1an.mkv will suffice

In case when ffmpeg gets RGB as input, it does the conversion internally

bczhc commented 7 months ago

Yes, I tried and this worked.

ffmpeg -i 1.mp4 -c:a copy -c:v libx264 -crf 0 -pix_fmt yuv420p input_for_av1an.mkv
<ffmpeg outputs>
/mnt/nvme/av1/3 ❯ ~/av1an -i input_for_av1an.mkv                                19:46:30
INFO [av1an_core::context] Input: 2560x1440 @ 30.000 fps, YUV420P, SDR
Scene detection
INFO [av1an_core::context] scenecut: found 1 scene(s) [with extra_splits (300 frames): 1 scene(s)]
  00:00:02 ▕█████████████████████████████████████████▏ 100%  300/300 (133.32 fps, eta 0s)Queue 1 Workers 1 Passes 2
Params: --threads=8 --cpu-used=6 --end-usage=q --cq-level=30 --tile-columns=1 --tile-rows=0
/mnt/nvme/av1/3 ❯

Seems the error encounters only with RGB inputs.