moonlight-stream / moonlight-qt

GameStream client for PCs (Windows, Mac, Linux, and Steam Link)
GNU General Public License v3.0
10.28k stars 600 forks source link

Hardware accelerated video decode doesn't work on qcom-venus #1042

Closed jenneron closed 1 year ago

jenneron commented 1 year ago

Description

Hardware accelerated video decode doesn't work on Qualcomm SoCs with Venus video decoder which uses the same API as raspberry pi (v4l2m2m)

I'm using it from https://flathub.org/apps/com.moonlight_stream.Moonlight on debian sid with gnome wayland

I also tried to run it with flatpak run --env=H264_DECODER_HINT=h264_v4l2m2m --env=DRM_FORCE_DIRECT=1 com.moonlight_stream.Moonlight as suggested on https://github.com/moonlight-stream/moonlight-docs/wiki/Installing-Moonlight-Qt-on-Raspberry-Pi-4, but it probably wasn't supposed to help in this case

Hardware

The device I'm trying to run it on: https://wiki.postmarketos.org/wiki/Acer_Chromebook_Spin_513_(google-lazor)

I tested this video decoder using ffplay -vcodec h264_v4l2m2m file.mp4 which works fine and reports driver 'qcom-venus' on card 'Qualcomm Venus video decoder' in mplane mode, but it doesn't work in moonlight

Logs

related part ``` 00:00:03 - SDL Info (0): Opened DRM render node: /dev/dri/renderD128 00:00:03 - SDL Info (0): Direct rendering via DRM is disabled 00:00:03 - SDL Info (0): Using DRM renderer 00:00:03 - FFmpeg: [h264_mp4toannexb @ 0xffff40273bf0] The input looks like it is Annex B already 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] Format nv12 chosen by get_format(). 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] probing device /dev/video3 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] driver 'qcom-venus' on card 'Qualcomm Venus video decoder' in mplane mode 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] Using device /dev/video3 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] driver 'qcom-venus' on card 'Qualcomm Venus video decoder' in mplane mode 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] requesting formats: output=H264/none capture=NV12/yuv420p 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] output: H264 16 buffers initialized: 1920x1080, sizeimage 01568768, bytesperline 00000000 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] VIDIOC_G_FMT ioctl 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] capture buffer[0] initialization (Invalid argument) 00:00:03 - FFmpeg: [h264_v4l2m2m @ 0xffff40e4f030] can't request capture buffers 00:00:03 - SDL Warn (0): Test decode failed (avcodec_send_packet): Cannot allocate memory ```

full-log.txt

cgutman commented 1 year ago

Can you post logs from the working ffplay command (preferably with verbose output like Moonlight's v4l2m2m log lines)

jenneron commented 1 year ago

Is ffplay -v debug -vcodec h264_v4l2m2m Big_Buck_Bunny_720_10s_30MB.mp4 fine?

ffplay-debug.txt

jenneron commented 1 year ago

Also -v verbose here too

ffplay-verbose.txt

cgutman commented 1 year ago

Interesting, so 720p seems to work. Can you try with a 1080p version of Big Buck Bunny?

jenneron commented 1 year ago

Sorry for the delay.

I've tried https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_30MB.mp4, it seems to work, but it is laggy.

ffplay-debug-h264-1080.txt

I also tried https://download4.dvdloc8.com/trailers/divxdigest/simpsons_movie_1080p_hddvd_trailer.zip (1920×800) which is not laggy unlike Big Buck Bunny

ffplay-debug-h264-1080-2.txt

jenneron commented 1 year ago

Tested it on master (including the patch above). It works

log ``` 00:08:36 - FFmpeg: [hevc_mp4toannexb @ 0xffff9d8aacd0] The input looks like it is Annex B already 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] probing device /dev/video2 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] driver 'qcom-venus' on card 'Qualcomm Venus video decoder' in mplane mode 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] Using device /dev/video2 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] driver 'qcom-venus' on card 'Qualcomm Venus video decoder' in mplane mode 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] requesting formats: output=HEVC/none capture=NV12/yuv420p 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] output: HEVC 16 buffers initialized: 1280x0720, sizeimage 00708608, bytesperline 00000000 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] VIDIOC_G_FMT ioctl 00:08:36 - FFmpeg: [hevc_v4l2m2m @ 0xffff9a96e350] capture: NV12 20 buffers initialized: 1280x0736, sizeimage 01425408, bytesperline 00001280 00:08:36 - SDL Info (0): FFmpeg-based video decoder chosen ```

I also tested it on exynos 5420 with a few patches on top of mainline kernel. It uses another v4l2m2m video decoder and works here as well. https://wiki.postmarketos.org/wiki/Samsung_Chromebook_2_11.6%22_(google-peach-pit)

Thank you for fixing this

Geofferey commented 7 months ago

@jenneron Can you tell me what kernel version you were on? I'm trying to get v4l2m2m working on trogdor running 5.19.1. I notice I only have /dev/video0. When running ffmpeg as you did I get...

h264_v4l2m2m @ 0x7d840090e0] probing device /dev/video0
[h264_v4l2m2m @ 0x7d840090e0] driver 'v4l2 loopback' on card 'Virtual Camera' in splane mode
[h264_v4l2m2m @ 0x7d840090e0] v4l2 capture format not supported
[h264_v4l2m2m @ 0x7d840090e0] Could not find a valid device
[h264_v4l2m2m @ 0x7d840090e0] can't configure decoder
Failed to open file 'Big_Buck_Bunny_1080_10s_5MB.webm' or configure filtergraph
[AVIOContext @ 0x7d84009780] Statistics: 368149 bytes read, 0 seeks

Maybe my kernel isn't new enough?

jenneron commented 7 months ago

@Geofferey that kernel is quide old. Video decoder works for me on postmarketOS. you can see kernel version at https://pkgs.postmarketos.org/package/master/postmarketos/aarch64/linux-postmarketos-qcom-sc7180