Zero 3W Hardware Decoding and Encoding (Wayland / KMS)

I have been testing HW decoding / encoding on Zero 3W, and pushing it to the limits.
My goal was to decode a video and make a screencast simultaneously.
Initially, pushing rkenc to max freq, hanged the board while encoding, so i only pushed rkdec, GPU, and CPU to max freq, and then I got the expected results with Wayland but not KMS (for a reason below).

The test was done with HDMI 1920x1080.

Decoding file: Beauty_3840x2160_120fps_420_8bit_HEVC_MP4.mp4

wget http://ultravideo.fi/video/Beauty_3840x2160_120fps_420_8bit_HEVC_MP4.mp4

Decoding:

gst-launch-1.0 filesrc location=Beauty_3840x2160_120fps_420_8bit_HEVC_MP4.mp4 ! qtdemux ! h265parse ! mppvideodec ! waylandsink

Result:

So, i had to rescale it to 1920x1080 (using hw):

gst-launch-1.0 filesrc location=Beauty_3840x2160_120fps_420_8bit_HEVC_MP4.mp4 ! qtdemux ! h265parse ! mppvideodec ! waylandsink render-rectangle=’<0,0,1920,1080>’

Result:

Encoding:

sudo ffmpeg -device /dev/dri/card0 -framerate 30 -f kmsgrab -i - -vf ‘hwdownload,format=bgr0’ -c:v hevc_rkmpp -y screencast_30fps_3.mkv

screencast result here:

https://mega.nz/file/9KYVWS4K#obesVhLWSwEZleT01p7GhBXNywRfOntgZo4jmVp9fYk

Recording KMS session did not work, looks like i need to change planeid. KMS decoding worked fine.

Result:

https://mega.nz/file/9X4XhJxA#Hhml_pAqfZEqSS1i7c36KEsIyrrQPeMiNQCaNpvjuQc

@nyanmisaka @boogiepop
How to record a specific planeid and how to change bitrate?

I tried the cnx trick but did not work for any other plane.

cat /sys/kernel/debug/dri/0/state | grep 'plane\['
plane[54]: Smart0-win0
plane[76]: Esmart0-win0
plane[90]: Cluster0-win0

ffmpeg -device /dev/dri/card0 -framerate 30 -plane_id 90 -f kmsgrab -i - -vf ‘hwdownload,format=bgr0’ -c:v hevc_rkmpp -y screencast_30fps_4.mkv