ValveSoftware / gamescope

SteamOS session compositing window manager
Other
3k stars 198 forks source link

ffmpeg kmsgrab crashes because plane format changes #448

Closed Foxboron closed 1 year ago

Foxboron commented 2 years ago

This is above my head sadly so I'm not super sure what the proper solution is :)

If I use kmsgrab on the Steam Deck with

$ ffmpeg -f kmsgrab -i - -vaapi_device /dev/dri/renderD128 -vf hwmap=derive_device=vaapi,scale_vaapi=format=nv12 -c:v h264_vaapi -bf 1 -f flv rtmp://.....

It will crash with [kmsgrab @ 0x561e6ec9d180] Plane 55 framebuffer format changed: now 34325258 whenever I swap between the UI and the game.

This seems to be because gamescope is actively changing the buffer format: https://github.com/Plagman/gamescope/blob/master/src/drm.cpp#L144

Where as ffmpeg assumes it will be the same for the entire recording session. https://github.com/FFmpeg/FFmpeg/blob/master/libavdevice/kmsgrab.c#L172

I'm not sure if this is solveable or if this is inherently an issue with ffmpeg. But thought I'd write an issue.

Samsagax commented 2 years ago

I think ffmpeg wont work, but gamescope exposes a pipewire stream. Try using something like this: https://git.sr.ht/~emersion/gamescope-pipewire-demo/

For reference: https://github.com/Plagman/gamescope/issues/213 https://github.com/Plagman/gamescope/pull/219

Foxboron commented 2 years ago

Funny enough I didn't need to specify the path and stuff just works. Currently trying to figure out how to sync up audio and video and not going so well :)

gst-launch-1.0 -e pipewiresrc do-timestamp=true ! videoconvert ! vaapih264enc ! h264parse ! flvmux streamable=true skip-backwards-streams=true name=mux ! rtmpsink location='rtmp://192.168.1.4/live/external.stream live=1' pulsesrc device="alsa_output.pci-0000_04_00.5-platform-acp5x_mach.0.HiFi__hw_acp5x_1__sink.monitor" ! audioconvert !  audioresample ! faac ! mux.
parkerlreed commented 2 years ago

I wonder if OBS may work for the RTMP streaming/recording? It doesn't look like there is pipewire support outside of screen capture on Wayland, but there's an external plug-in that seems promising https://github.com/feldim2425/obs-pipewire

Foxboron commented 2 years ago

I did a blogpost on how to properly stream from the Steam Deck a while ago.

https://linderud.dev/blog/streaming-the-steam-deck-to-obs/

CptnRogers commented 2 years ago

Have you had any luck with the Audio/Video Sync? Also, have you found a way to record locally without the need for an RTMP Stream? I have tried every way I can think to do it with absolutely no luck.

Joshua-Ashton commented 2 years ago

I have an obs studio branch that uses the gamescope pipewire interface

parkerlreed commented 2 years ago

@CptnRogers https://git.sr.ht/~avery/recapture

Golang that uses the gstreamer interface