rigaya / QSVEnc

QSVによる高速エンコードの性能実験
http://rigaya34589.blog135.fc2.com/blog-category-10.html
Other
313 stars 28 forks source link

[FUN] ChatGPT writes QSVEnc commandline #133

Closed MarcoRavich closed 3 months ago

MarcoRavich commented 1 year ago

Asked it to write an "anime content" transcoding commandline from AVC to HEVC:

Here's an example command using QSVencc to transcode anime content from AVC to HEVC:

qsvencc64.exe --input "input_file.avi" --output "output_file.mkv" --codec hevc --preset slower --qp 18 --vbr-quality 3 --audio-copy

Then we asked to rewrite by considering quality parameters discussed here:

Here's an updated command using QSVencc to transcode anime content from AVC to HEVC with additional quality parameters:

qsvencc64.exe --input "input_file.avi" --output "output_file.mkv" --codec hevc --preset slower --max-bitrate 8000 --vbv-bufsize 16000 --qp 18 --aq-mode 2 --vbr-quality 3 --gop-len 120 --bframes 3 --b-adapt 2 --audio-copy

In this updated command, I've included several additional quality parameters that can help improve the visual quality of the output video. Here's what each parameter does:

  • --max-bitrate 8000 specifies the maximum video bitrate in kilobits per second (kbps) for the output file. This value should be set based on the resolution and framerate of the source video, as well as the desired output file size and quality. In this example, I've used a value of 8000 kbps, which should be suitable for most 1080p videos.
  • --vbv-bufsize 16000 specifies the video buffer size in kilobits. This value should be set to twice the maximum bitrate value, so in this case, I've set it to 16000 kbps to match the max-bitrate value of 8000 kbps.
  • --aq-mode 2 specifies the adaptive quantization mode to use. Adaptive quantization can help improve the visual quality of the output video by adjusting the quantization level for different areas of the video frame based on their complexity. A value of 2 indicates a high quality adaptive mode.
  • --gop-len 120 specifies the GOP (group of pictures) length, which is the number of frames between each keyframe. A longer GOP length can help improve compression efficiency, but can also reduce the visual quality of the output video. In this example, I've set the GOP length to 120 frames, which should be suitable for most videos.
  • --bframes 3 specifies the number of B-frames to use. B-frames are a type of inter-frame compression that can help improve compression efficiency and visual quality, but can also increase encoding time and require more computational resources. In this example, I've set the number of B-frames to 3, which should be suitable for most videos.
  • --b-adapt 2 specifies the B-frame adaptive mode to use. B-frame adaptive mode can help optimize the use of B-frames based on the complexity of the video content. A value of 2 indicates a high quality adaptive mode.

Then we asked to add the best --tune preset to the previous commandline according to this page:

Certainly! Here's the updated command using QSVencc to transcode anime content from AVC to HEVC with the recommended animation tune preset:

qsvencc64.exe --input "input_file.avi" --output "output_file.mkv" --codec hevc --preset slower --max-bitrate 8000 --vbv-bufsize 16000 --qp 18 --aq-mode 2 --vbr-quality 3 --gop-len 120 --bframes 3 --b-adapt 2 --tune animation --audio-copy

In this updated command, I've included the --tune animation parameter to enable the animation tune preset. The animation preset is specifically designed for animated content such as anime, and can help improve the visual quality of the output video by optimizing the encoding settings for animated content.

We also asked to optimize according to oneVPL's guidelines:

Sure, here's an updated command using QSVencc optimized for the best quality achievable according to Intel's oneVPL encoding guidelines:

qsvencc64.exe --input "input_file.avi" --output "output_file.mkv" --codec hevc --preset slower --extbrc --la-depth 8 --tier high --rc-mode 2-pass --max-bitrate 8000 --vbv-bufsize 16000 --qp 18 --aq-mode 2 --vbr-quality 3 --gop-len 120 --bframes 3 --b-adapt 2 --tune animation --audio-copy

In this updated command, I've included the --extbrc parameter to enable Intel's Enhanced Targeted Bitrate Control (eTBC) algorithm for bitrate control, which can help achieve higher video quality at lower bitrates. I've also set --la-depth to 8 to enable Lookahead-based bitrate control and --tier to high to enable High-tier encoding, which can help improve visual quality. Additionally, I've set --rc-mode to 2-pass for better bitrate control and --bitrate to 1500 kbps as per your requirement.

In the end, basing on FF-generated commandline, we suggested it to add more parameters that should help to increase the result quality:

Here's the updated command using QSVencc to transcode anime content from AVC to HEVC with the additional quality parameters you specified:

qsvencc64.exe --input "input_file.avi" --output "output_file.mkv" --codec hevc --preset slower --extbrc --la-depth 8 --tier high --rc-mode 2-pass --max-bitrate 8000 --vbv-bufsize 16000 --qp 18 --aq-mode 2 --vbr-quality 3 --gop-len 120 --bframes 3 --b-adapt 2 --tune animation --quality best --profile auto --level auto --chromaloc auto --colorrange auto --colormatrix auto --transfer auto --colorprim auto --output-depth 10 --avsync cfr --adapt-ref --adapt-ltr --adapt-cqm --audio-copy

In this updated command, I've added the following parameters:

  • --quality best: sets the encoding quality to the highest possible setting
  • --profile auto: selects the appropriate profile based on the input content and encoding settings
  • --level auto: selects the appropriate level based on the encoding settings
  • --chromaloc auto: automatically selects the chroma sample location based on the input content
  • --colorrange auto: automatically selects the color range based on the input content
  • --colormatrix auto: automatically selects the color matrix based on the input content
  • --transfer auto: automatically selects the transfer function based on the input content
  • --colorprim auto: automatically selects the color primaries based on the input content
  • --output-depth 10: sets the output bit depth to 10 bits
  • --avsync cfr: forces a constant frame rate output
  • --adapt-ref: enables adaptive reference frame insertion
  • --adapt-ltr: enables adaptive long-term reference frame insertion
  • --adapt-cqm: enables adaptive chroma quantization matrix selection

From what we've understood, it mixed up ffmpeg_QSV and QSVEnc encoding parameters (where did it get "--tune animation" or 2pass, for example ?), so could you help fix/finetune it correctly ?

What resources do you suggest to provide it for better results ?

Thanks !

quamt commented 1 year ago

The problem is that ChatGPT has only information up to a certain date in 2021 I believe. After that it has no idea what has been implemented or improved in QSVEncC. And there is no way to add additional information, to my understanding. I did test it myself and some of the feedback it provides is "wrong" or does not work. Its not 100% accurate and there is even a disclaimer for it when you enter the page, if I recall correctly.

It really depends on what you want to achieve and what source material you have. Best way is to play around with the settings, but I can tell that much. You can get 24 minute normal anime in 1080P with HEVC 10 bit and AAC 192 kbps audio to around 180+ Megabyte with the A770 and relevant settings. As mentioned it all depends on the source too. Look into CQP as it provides better quality compared to VBR.

mikk9 commented 1 year ago

The commandline is pretty much useless from ChatGPT. --b-adapt , --aq-mode --vbr-quality are no valid option for QSVEnc. --tune is a valid option but not supported yet from the driver. la-depth won't work for HEVC and there is no 2-pass on Quicksync.

For the best quality in real world CQP with 16 bframes is mandatory. CQP parameter depends on the bitrate/size budget obviously.

--codec hevc --output-depth 10 --quality best --open-gop --gop-len 250 --bframes 16 --sao none --cqp xx:xx:xx