dec05eba / gpu-screen-recorder-issues

GPU Screen Recorder issue tracker
11 stars 0 forks source link

[BUG] Rhythmic stutter after changing workspace and back to game #2

Closed Nama closed 3 months ago

Nama commented 3 months ago

Describe the bug After changing from the workspace the game is on to another workspace and back (might take a few tries/minutes), the game stutters periodically.

To Reproduce gpu-screen-recorder -w DP-3 -f 60 -q medium -r 20 -k h264 -c mp4 -ac aac -a "$(pactl get-default-sink).monitor" -o /tmp -v no -sc scripts/clip_upload.sh This happens on sway and hyprland. On every game I played so far (Proton games: Overwatch, Helldivers II) After killing the gpu-screen-recorder process, the stutters go away, else they don't seem to stop.

Expected behavior No stutters

Screenshots Recorded with gpu-screen-recorder: https://streamable.com/v2altf screen recording in slowmotion from 144Hz: https://gitlab.freedesktop.org/drm/amd/uploads/f301d4e6ab3dcd0ffe4e89ecf47d3acb/ow.mp4 (from the AMD repo issue) Screen recording was actual in-game footage, no recorded video. (both too big to upload here)

Desktop (please complete the following information):

Additional context I couldn't record these stutters with OBS, but gpu-screen-recorder seems to record them.
I have this issue for a long time now and thought its a driver issue >_<
Couldn't reproduce on desktop only drm_info Output always starts with this. There is no output as the stuttering starts.

[h264_vaapi @ 0x5646698fb280] ignoring invalid SAR: 0/0 [h264_vaapi @ 0x5646698fb280] Driver does not support some wanted packed headers (wanted 0xd, found 0x1). gsr info: gsr_kms_client_init: waiting for server to connect kms server info: connecting to the client gsr info: gsr_kms_client_init: server connected gsr info: replacing file-backed unix domain socket with socketpair kms server info: connected to the client gsr info: using socketpair [h264_vaapi @ 0x5646698fb280] ignoring invalid SAR: 0/0 [h264_vaapi @ 0x5646698fb280] Driver does not support some wanted packed headers (wanted 0xd, found 0x1).

dec05eba commented 3 months ago

When you record with OBS are you recording with vaapi video encoder enabled? try doing that to see if you have the same issue. Also try recording with hevc codec in gpu screen recorder to see if there is a difference. I have a rx 7800xt and I cant reproduce this issue myself so it might be an issue specifically with 7900 xt. Also have you tested if this issue happens when recording a regular video, not replay?

Nama commented 3 months ago

When you record with OBS are you recording with vaapi video encoder enabled? try doing that to see if you have the same issue.

Yes. I tried again now with these settings. The game didn't stutter. image

Also try recording with hevc codec in gpu screen recorder to see if there is a difference.

Seems like its making a difference! Didn't get the stutters with hevc :O Thank you! Hopefully it wont just take longer or something. I'll change the command and we'll see... Saving clips as hevc wouldn't be too bad, since I started to process the clips with ffmpeg to optimize them for web (-movflags +faststart) for faster playback in the browser. (Would that be possible to directly save them like that, or is that an hardware limitation?)

Also have you tested if this issue happens when recording a regular video, not replay?

Just did, yes.

dec05eba commented 3 months ago

I dont know if hevc working with no issue is a false positive or not, it may just not have the issue right now. I dont know how often it happened to you. The only extra thing that gpu screen recorder uses for h264 vaapi config that differs from yours on obs is that quality is set to 5. Obs seems to not use that option at all. About the faststart I did consider it around 2 years ago but I didn't do it, I dont remember why. Maybe it didn't work with hardware encoders. It's still in the TODO list. I'll try enabling it sometime.

Nama commented 3 months ago

I dont know if hevc working with no issue is a false positive or not, it may just not have the issue right now. I dont know how often it happened to you.

Generally happens mostly after being on a different workspace for 3-5 minutes (and sometimes faster). Rarely I need to be on another workspace for 10 or more minutes.

The only extra thing that gpu screen recorder uses for h264 vaapi config that differs from yours on obs is that quality is set to 5. Obs seems to not use that option at all.

You don't mean QP I assume, since that would be absurdly high quality.

About the faststart I did consider it around 2 years ago but I didn't do it, I dont remember why. Maybe it didn't work with hardware encoders.

I do it with vaapi and it seems to work: ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -loglevel quiet -i $clip_o -preset fast -threads 16 -movflags +faststart -qp 31 -vcodec h264_vaapi -c:a copy $local_folder$clip

dec05eba commented 3 months ago

You don't mean QP I assume, since that would be absurdly high quality.

No i meant "quality", as this says: ffmpeg -h encoder=h264_vaapi. Maybe I should remove it. Can you try using that in obs to see if it triggers the issue? maybe that can be done by adding -quality 5 to that FFmpeg options at the bottom on that settings page.

I do it with vaapi and it seems to work: ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -loglevel quiet -i $clip_o -preset fast -threads 16 -movflags +faststart -qp 31 -vcodec h264_vaapi -c:a copy $local_folder$clip

Thanks, i'll add that then if there aren't any downsides

Nama commented 3 months ago

Can you try using that in obs to see if it triggers the issue?

Didn't trigger it in the "short" test I just did.

Thanks, i'll add that then if there aren't any downsides

Thank you! I didn't notice any downsides and as far as I know, it just moves the meta data without tinkering with the quality. A switch to enable would work, too.

dec05eba commented 3 months ago

Actually I think I know what the real issue might be. Can you try using the flatpak version instead with the same h264 command? first install with flatpak install flathub --system com.dec05eba.gpu_screen_recorder and then run the command: flatpak run --command=gpu-screen-recorder com.dec05eba.gpu_screen_recorder -w DP-3 -f 60 -q medium -r 20 -k h264 -c mp4 -ac aac -a "$(pactl get-default-sink).monitor" -o /tmp -v no -sc ./scripts/clip_upload.sh

Nama commented 3 months ago

Still happening.

Regarding hevc: No stutters so far.

dec05eba commented 3 months ago

I updated gpu-screen-recorder on aur with a test change, can you update and try again with h264 codec?

Nama commented 3 months ago

The issue seems to be fixed, thank you very much!

I let a recording running then the replay, both for half an hour with the game in the background and no stutters so far. Would have appeared until now.

Is your fix also related to hevc or just h264 specific?

dec05eba commented 3 months ago

The fix is h264 specific (the option that was set doesn't exist for hevc). Thanks for testing! Im not sure if the stutter is a driver issue or if its too heavy for drivers to handle. Nvidia actually has a similar issue (in the case of nvidia its worse as it causes the application to freeze as well sometimes). I have found a lot of driver issues in amd, intel and nvidia when making gpu screen recorder. There are a billion workarounds in gpu screen recorder to prevent these from happening.

Nama commented 3 months ago

That sounds awful... Thanks for going thru all that D:

Is this really the fix and not the first attempt with the flatpak? According to the timestamps, seems like it :O

dec05eba commented 3 months ago

Yes it's the fix xd