QP Spikes, which causes what looks like key frame popping

Issue #586 new
Stacey Spears created an issue

I am trying to encode 1080p HDR content. Avg 89 Mbps, Peak 98 Mbps. The 2nd pass says it will only hit 66 Mbps.

I see nasty key frame popping. If set --no-wpp, that seems to go away. I built the code from the 3.5 branch as of today.

I have attached a quick snapshot from the stats file. This particular section is a static opening title card that is 72 frames long.

I see lots of P and B frames at QP 0 and then I will see the I frame at QP 20.

I am willing to provide part of the 10-bit 4:2:0 YUV file and I have attached my encoder settings if it will help. Using --no-wpp is going to take way too long, especially once I encode the UHD version.

Comments (6)

  1. Stacey Spears reporter

    If I change --b-adapt to 0, from 2, then I get the same results as setting --no-wpp. It also fixes the tearing that occurs in one shot. So I think something is wrong with --b-adapt.

    Still does not solve overall QP spikes along the way. I tried using a QP file to force the I frames to a particular QP with no luck. Same with --zones. I will report a separate issue on QP files/zones. It could just be my understanding on how qpfile or zones is supposed to work. Maybe clear up the docs.

  2. Ben Waggoner

    You might try --b-adapt 1; results would help narrow things down.

    But that bitrate with 1080p is crazy high, and may be confusing RC. There’s a good chance you could encode the whole thing with --crf 4 and be within the VBV limits without setting --vbv-bitrate/maxsize.

    You are also using --subme 7 which isn’t even in preset placebo and I can’t imagine is helpful at these bitrates; I think I maybe found 1% savings at 50 Kbps 400x224 with it. I doubt that gets much regression testing!

    With a static card opening, I’d try --tskip and perhaps --cu-lossless. --scenecut-aware-qp and --hist-scenecut (2 or 3 - whichever is the bidirectional one) could help as well. If there are fine details in the card, --tu-intra 4 --tu-inter 4 can help too. And --aq-mode 2 or --hevc-aq can give better results.

    Also, for the .qpfile, I’ve gotten confused about encode and decode order in that. It is in encode order IIRC, and IIRC that corresponds with the “out” frame number, not the in. It’s been a long while since I used a .qpfile to set QP.

  3. Stacey Spears reporter

    Here is an example of some artifacts with high bitrate HD encodes. It always occurs on this shot:

    I circled the area in read where you can see the blocking / tearing.

    Here is an xlsx where I list every shot that has an issue. This shot and the poppy flower both have the tearing at the bottom. Seems to show up for one GOP on the poppy and more than one GOP on the deer. https://www.dropbox.com/scl/fi/z9y0h9fp1a9ae7t3gwnzg/HDR_Montage_ShotLis_21_04_19_HD_Artifacts.xlsx?dl=0&rlkey=a11q8xpd6q576yh7w9kjfmv1o

    Here is the 1st pass stats file and a CSV from pass 2. https://www.dropbox.com/s/32fsukqtx9989es/HDR_Montage_HD_Logs.zip?dl=1

    I targeted 90 Mbps and it hit 58 Mbps. Here is the hevc encoded file: https://www.dropbox.com/s/fga72t1azk44w0t/HDR_Montage_V2_01000_HD_BT2020.hevc?dl=1

    Happy to share the YUV file (10-bit 4:2:0) if you are interested in tiring to fix it. I am currently re-encoding using the Sony UHD BD encoder as well as Ateme. The x265 encode is not usable at all.

  4. Stacey Spears reporter

    Here are all the files you need.

    1. YUV (inside a 7z to reduce the size to 14 GB. When you decompress, it will be ~65 GB or 11235 frames)

    2. The bat files. I use two bat files. 01_Encode_HDR_Montage_HD_01000.bat is the file that feeds the main bat file Encode_HDR_Montage_HD_2pass_90.bat. Obviously you will need to tweak the paths. And yes, the MaxCLL is higher than Mastering Display Luminance. Those are the odd specular highlights that go above 1000. Lots of them.

    3. The QPFile is set so that I can set chapter points on any shot. For authoring, we have a marker every second that allows the user to switch between the different montage flavors and jump to roughly the same point, which makes it easier to compare.

    4. There is some moiré in various shots due to the scaling from UHD2 (7680x4320) to HD. I will re-visit before the final-final encoding. The peacock feather and parrots feathers show the moiré. Looks much better at UHD. In fact, one of the montages is a UHD vs. HD. In that case, I had to scale the HD to UHD and then I do the circular wipe.

    5. AnalyzeIt is my YUV viewer. Lots of little tools built-in. (WFM, Vector, Histogram, Pixel Values, etc...) The raw_data is a text file with basic image info so you don't have to manually type in the resolution, color space and FOURCC codes when opening a YUV file. This also opens AVIs and BMPs. I wrote this back in 2004, so please forgive the Win32 UI. 

    It is also a viewer, not a player. It does not scale the image, so you can drag it around inside the viewer. There is a zoom window you can bring up. (alt + z) The highlight feature will show all pixels <16 (or 64 in 10-bit) as green and > 235 (940) as hot pink. It highlights the pixels outside the range AFTER conversion to RGB, not in YUV. You can view any channel, R, G, B, Y, U and V. The histogram can show both YUV and RGB histograms. It is the tool we wrote so we can verify our test patterns. Alt + D will bring up the macroblock widow. (16x16 grid of pixel values) Use the arrow keys to move the cursor around.

    1. The shot list with the shots in question called out in column P. (Called HD Encode for some odd reason)

    2. The hevc encoded file from the bat file.

  5. Log in to comment