AMF icon indicating copy to clipboard operation
AMF copied to clipboard

[Bug]: AV1 Zero QIndex produces undecodable bitstream

Open RFCArrow opened this issue 2 years ago • 3 comments

Describe the bug The AMF AV1 encoder accepts 0 as a valid value for QIndex, but then encodes a bitstream which cannot be correctly decoded.

To Reproduce Steps to reproduce the behavior:

  1. Build the AMF TranscodeHW sample project
  2. Run the sample with the following arguments: -WIDTH 1280 -HEIGHT 720 -INPUT input_1280x720_8bit_420p.yuv -OUTPUT output.mp4 -CODEC AV1 -AV1QIndex_Inter 0 -AV1QIndex_Intra 0
  3. Inspect the output. The output file is generated with seemingly the right file size and metadata, but it doesn't play back properly. Depending on the player, it will either fail to open at all, fail to render a frame, or render a frame with smeary artefacts across the entire frame.

Setup (please complete the following information):

  • OS: Windows 11 Pro (22H2 / 22621.2283)
  • Driver Version: 21.9.3
  • GPU: RX 7900 XTX
  • AMF: 1.4.30 (2f32635)
  • Which component has the issue: Encoder

Debug Log (please upload or paste): Attached here: amf_qindex_zero_debug_log.txt

Expected behavior One of the following:

  • The encoder reports an error that the setting is invalid and produces no output.
  • Encoder generates an output without errors. The output can be played back and renders correctly in the player.

Screenshots Here is a sample frame which shows the smearing effect. image

Additional context It may be worth nothing that if QIndex_Inter is set to 0 and QIndex_Intra is given another valid value, the intra frames can be decoded correctly, but the inter frames are still not able to be decoded correctly.

TranscodeHW --help text lists the valid range of values as including 0:

   -Av1QIndex_Inter inter-frame QIndex (integer 0-255, default = depends on USAGE)
   -Av1QIndex_Intra intra-frame QIndex (integer 0-255, default = depends on USAGE)

The docs in amf/doc/AMF_Video_Encode_AV1_API.md also list 0 as being a valid value:

Name: AMF_VIDEO_ENCODER_AV1_Q_INDEX_INTRA Values: 0255 Default Value: 26 Description: Sets the constant Q for Intra frames. Remarks: Only available for CQP rate control method.

Name: AMF_VIDEO_ENCODER_AV1_Q_INDEX_INTER Values: 0255 Default Value: 26 Description: Sets the constant Q for Inter frames. Remarks: Only available for CQP rate control method.

Finally the docs in the wiki only reference qp_i and qp_p, instead of qindex_intra and qindex_inter - perhaps a copy-paste error from the H264/HEVC docs?

qp_i 	int 		Quantization Parameter for I-Frame (from -1 to 51) (default -1, reserved for internal use)
qp_p 	int 		Quantization Parameter for P-Frame (from -1 to 51) (default -1, reserved for internal use)

RFCArrow avatar Oct 24 '23 16:10 RFCArrow

I realise that in the repro case above I forget to set the rate control mode, but I can confirm that the same issue occurs when explicitly setting -AV1RateControlMode CQP.

RFCArrow avatar Oct 25 '23 10:10 RFCArrow

The corresponding doc in the Wiki has been corrected and an internal ticket has been created for the main issue of generating a bitstream which cannot be correctly decoded.

rhutsAMD avatar Oct 25 '23 20:10 rhutsAMD

Please try again with a .NV12 file being used as input to TranscodeHW instead of .YUV. You can also upload and share your input file so we can double check as well. You may reference how AMF treats file extensions in RawStreamReader.cpp

Additionally, the valid range has been updated to 1 – 255 for the QIndex in the latest AMF v1.4.33 release, preventing the invalid 0 QIndex values from being set.

rhutsAMD avatar Jan 24 '24 18:01 rhutsAMD

Closing as resolved considering the submitted fix being publicly released and inactivity in verifying the suggested steps.

Please reopen if you are still seeing this issue on the latest drivers.

rhutsAMD avatar Apr 05 '24 18:04 rhutsAMD