rigaya / NVEnc

NVENCによる高速エンコードの性能実験
https://rigaya34589.blog.fc2.com/blog-category-17.html
Other
1.07k stars 111 forks source link

AV1 encoding to IVF #607

Closed Dendraspis closed 1 month ago

Dendraspis commented 1 month ago

Hello rigaya,

I have an issue when encoding to AV1. Until now NVEncC created an .av1 file that was muxed to MKV/MP4. Due to a bug and to be compliant with the other encoders, I decided to switch the extension to .ivf which is the sort of default extension for AV1 encoders. This is also supported by NVEncC, but the result is broken. Maybe I am missing something or is it a bug?

Little addition: It should also affect QSVEncC and VCEEncC.

Source File ``` General Complete name : A:\_StaxRip-Test\XXX.mkv Format : Matroska Format version : Version 4 File size : 17.5 MiB Duration : 3 min 33 s Overall bit rate : 686 kb/s Frame rate : 25.000 FPS Writing application : Lavf58.35.100 Writing library : Lavf58.35.100 ErrorDetectionType : Per level 1 Video ID : 1 Format : VP9 Format profile : 0 Codec ID : V_VP9 Duration : 3 min 33 s <=== Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 25.000 FPS <=== Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Language : English Default : Yes Forced : No Color range : Limited Color primaries : BT.709 Transfer characteristics : BT.709 Matrix coefficients : BT.709 Audio ID : 2 Format : AAC LC Format/Info : Advanced Audio Codec Low Complexity Codec ID : A_AAC-2 Duration : 3 min 33 s Channel(s) : 2 channels Channel layout : L R Sampling rate : 44.1 kHz Frame rate : 43.066 FPS (1024 SPF) Compression mode : Lossy Title : ISO Media file produced by Google Inc. Language : English Default : Yes Forced : No ```

Without altering the fps using this command line: NVEncC64.exe --avsdll [..]\AviSynth.dll --qvbr 28 --codec av1 --preset P1 --output-depth 10 --colormatrix bt709 --colorprim bt709 --transfer bt709 -i XXX_AV1.avs -o XXX_AV1_out.av1

...NVEncC outputs the right values:

Output Info    AV1 main 10bit @ Level auto
               1920x1080p 0:0 25.000fps (25/1fps)

... and the media info is okay, even the fps are not mentioned, and the playback is also okay:

AV1 File ``` General Count : 349 Count of stream of this kind : 1 Kind of stream : General Kind of stream : General Stream identifier : 0 Complete name : .\XXX_AV1_out.av1 Folder name : . File name extension : XXX_AV1_out.av1 File name : XXX_AV1_out File extension : av1 File size : 27374358 File size : 26.1 MiB File size : 26 MiB File size : 26 MiB File size : 26.1 MiB File size : 26.11 MiB Stream size : 27374358 Stream size : 26.1 MiB (100%) Stream size : 26 MiB Stream size : 26 MiB Stream size : 26.1 MiB Stream size : 26.11 MiB Stream size : 26.1 MiB (100%) Proportion of this stream : 1.00000 ```

But when using the same command line with an .ivf file extension, NVEncC is also right:

Output Info    AV1 main 10bit @ Level auto
               1920x1080p 0:0 25.000fps (25/1fps)
               avwriter: av1 => ivf

... but the result is completely off, indicating 100 fps instead of 25, which leads to massive issues when mixing with audio to MKV/MP4:

IVF File ``` General Complete name : .\XXX_AV1_out.ivf Format : IVF File size : 26.2 MiB Duration : 53 s 420 ms Overall bit rate : 4 109 kb/s Frame rate : 100.000 FPS Video Format : AV1 Format/Info : AOMedia Video 1 Codec ID : AV01 Duration : 53 s 420 ms <=== Bit rate : 4 099 kb/s Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate : 100.000 FPS <=== Bits/(Pixel*Frame) : 0.020 Stream size : 26.1 MiB (100%) ```
rigaya commented 1 month ago

It seems like that ivf format requires it's timebase of the stream to be as exact inverse of framerate, it's little weird behavior.

I'll have it changed in the next release, but I recommend to avoid use of ivf format, as "setting timebase to exact inverse of framerate" means that it cannot handle VFR (variable framerate) properly, and can only handle CFR (constant framerate).

I recommend to output video in mkv or mp4 format, which can handle timestamps more precisely. You shall be able to mux audio afterwards even if the video is in mkv or mp4 format.

Dendraspis commented 1 month ago

Oh, okay, very interesting and truly weird.

So I will avoid IVF and find another way and see, if I can implement a workflow with an MKV or MP4 file.

Thank you.