Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package gpu-screen-recorder for openSUSE:Factory checked in at 2025-02-20 16:38:33 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/gpu-screen-recorder (Old) and /work/SRC/openSUSE:Factory/.gpu-screen-recorder.new.1873 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "gpu-screen-recorder" Thu Feb 20 16:38:33 2025 rev:16 rq:1247183 version:20250217 Changes: -------- --- /work/SRC/openSUSE:Factory/gpu-screen-recorder/gpu-screen-recorder.changes 2025-01-27 20:55:32.183331783 +0100 +++ /work/SRC/openSUSE:Factory/.gpu-screen-recorder.new.1873/gpu-screen-recorder.changes 2025-02-20 16:39:35.256053787 +0100 @@ -1,0 +2,23 @@ +Wed Feb 19 16:53:24 UTC 2025 - mantari...@pm.me + +- Update to version 20250217: + * Only show codec warning for image output + * Support taking a screenshot (-o image.jpg/image.png) + * Revert kde plasma 6.2 hdr workaround code + * Info about hdr + * Revert readme for hdr + * Revert hdr color fix. It looked better for fullscreen hdr games + before + * Change hdr colors again + * Make hdr better for limited range colors + * Attempt to fix incorrect hdr colors on kde plasma 6.2 + * HDR: always set has_primaries and has_luminance, otherwise + data will be missing from file + * hdr works, for fullscreen applications? + * Fix crash when trying to capture hdr and it fails + * Increase replay max allowed duration to 3 hours + * fix: proper cleanup for init_filter_graph + * Pipewire: support 10-bit formats (where alpha is 2 bits, total + 32-bits) + +------------------------------------------------------------------- Old: ---- gpu-screen-recorder-20250125.tar.zst New: ---- gpu-screen-recorder-20250217.tar.zst ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ gpu-screen-recorder.spec ++++++ --- /var/tmp/diff_new_pack.Mx1M6v/_old 2025-02-20 16:39:36.988126206 +0100 +++ /var/tmp/diff_new_pack.Mx1M6v/_new 2025-02-20 16:39:36.992126373 +0100 @@ -18,7 +18,7 @@ %bcond_with test Name: gpu-screen-recorder -Version: 20250125 +Version: 20250217 Release: 0 Summary: An extremely fast hardware-accelerated screen recorder License: GPL-3.0-only ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.Mx1M6v/_old 2025-02-20 16:39:37.032128045 +0100 +++ /var/tmp/diff_new_pack.Mx1M6v/_new 2025-02-20 16:39:37.036128213 +0100 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://repo.dec05eba.com/gpu-screen-recorder.git</param> - <param name="changesrevision">cafcda102287a836dde5342a53ddf755487b1ccb</param></service></servicedata> + <param name="changesrevision">3c0b607154f324e0f34503e2eb661ded49705c93</param></service></servicedata> (No newline at EOF) ++++++ gpu-screen-recorder-20250125.tar.zst -> gpu-screen-recorder-20250217.tar.zst ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/.gitignore new/gpu-screen-recorder-20250217/.gitignore --- old/gpu-screen-recorder-20250125/.gitignore 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/.gitignore 2025-02-17 19:23:54.000000000 +0100 @@ -23,3 +23,6 @@ *.mov *.webm *.ts +*.jpg +*.jpeg +*.png diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/README.md new/gpu-screen-recorder-20250217/README.md --- old/gpu-screen-recorder-20250125/README.md 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/README.md 2025-02-17 19:23:54.000000000 +0100 @@ -7,6 +7,8 @@ This screen recorder can be used for recording your desktop offline, for live streaming and for nvidia shadowplay-like instant replay, where only the last few minutes are saved. +This software can also take screenshots. + This is a cli-only tool, if you want an UI for this check out [GPU Screen Recorder GTK](https://git.dec05eba.com/gpu-screen-recorder-gtk/) or if you prefer a ShadowPlay-like UI then check out [GPU Screen Recorder UI](https://git.dec05eba.com/gpu-screen-recorder-ui/). Supported video codecs: @@ -20,16 +22,19 @@ * Opus (default) * AAC -## Note +Supported image formats: +* JPEG +* PNG + This software works on X11 and Wayland on AMD, Intel and NVIDIA. ### TEMPORARY ISSUES 1) Videos are in variable framerate format. Use MPV to play such videos, otherwise you might experience stuttering in the video if you are using a buggy video player. You can try saving the video into a .mkv file instead as some software may have better support for .mkv files (such as kdenlive). You can use the "-fm cfr" option to to use constant framerate mode. 2) FLAC audio codec is disabled at the moment because of temporary issues. ### AMD/Intel/Wayland root permission -When recording a window or when using the `-w portal` option under AMD/Intel no special user permission is required, -however when recording a monitor (or when using wayland) the program needs root permission (to access KMS).\ +When recording a window or when using the `-w portal` option no special user permission is required, +however when recording a monitor the program needs root permission (to access KMS).\ This is safe in GPU Screen Recorder as the part that needs root access has been moved to its own small program that only does one thing.\ -For you as a user this only means that if you installed GPU Screen Recorder as a flatpak then a prompt asking for root password will show up when you start recording. +For you as a user this only means that if you installed GPU Screen Recorder as a flatpak then a prompt asking for root password will show up once when you start recording. # Performance On a system with a i5 4690k CPU and a GTX 1080 GPU:\ When recording Legend of Zelda Breath of the Wild at 4k, fps drops from 30 to 7 when using OBS Studio + nvenc, however when using this screen recorder the fps remains at 30.\ @@ -181,4 +186,5 @@ ## Kdenlive says that the video is not usable for editing because it has variable frame rate To fix this you can either record the video in .mkv format or constant frame rate (-fm cfr). ## Colors look incorrect when recording HDR (with hevc_hdr/av1_hdr) or using an ICC profile -The latest version of KDE Plasma breaks HDR and ICC profiles for recording applications. Wayland in general doesn't properly support recording HDR yet. Use desktop portal option (`-w portal`) for now to turn HDR recording into SDR and to be able to record with correct colors when using an ICC profile. +KDE Plasma version 6.2 broke HDR and ICC profiles for screen recorders. This was changed in KDE plasma version 6.3 and recording HDR works now, as long as you set HDR brightness to 100% (which means setting "Maximum SDR Brightness" in KDE plasma display settings to 203). If you want to convert HDR to SDR then record with desktop portal option (`-w portal`) instead. +I don't know how well recording HDR works in wayland compositors other than KDE plasma. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/TODO new/gpu-screen-recorder-20250217/TODO --- old/gpu-screen-recorder-20250125/TODO 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/TODO 2025-02-17 19:23:54.000000000 +0100 @@ -194,8 +194,7 @@ Add option to automatically select best video codec available. Add -k best, -k best_10bit and -k best_hdr. -HDR is broken on kde plasma > 6.2 because of change to how HDR metadata works. See https://github.com/dec05eba/gpu-screen-recorder-issues/issues/60. - Use wayland color management protocol when it's available: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/14. +Use wayland color management protocol when it's available: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/14. Use different exit codes for different errors. Use one for invalid -w option, another one for invalid -a option for audio devices, etc. This is to make UI error reporting better. Document these exit codes in an exit code .md file, or finally create a manpage where this can be documented. @@ -220,3 +219,14 @@ Use explicit sync in pipewire video code: https://docs.pipewire.org/page_dma_buf.html. Support vaapi rotation. Support for it is added in mesa here: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32919. + +Replay (and recording?) fails to save properly sometimes (especially for long videos). This is noticable with mp4 files since they get corrupt and become unplayable. + The entire video does seem to get saved (it's a large video file) and it seems to have the correct headers but it's not playable. + +Make it possible to save a shorter replay clip remotely. Maybe implement ipc first, to then also allow starting recording/stream while a replay is running. + +Add an option to pass http headers when streaming. Some streaming services require streaming keys to be passed in a http header instead of in the url as a parameter. + +When adding vulkan video support add VK_VIDEO_ENCODE_TUNING_MODE_LOW_LATENCY_KHR. + +Implement screenshot without invoking opengl (which is slow to start on some systems). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/include/capture/nvfbc.h new/gpu-screen-recorder-20250217/include/capture/nvfbc.h --- old/gpu-screen-recorder-20250125/include/capture/nvfbc.h 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/include/capture/nvfbc.h 2025-02-17 19:23:54.000000000 +0100 @@ -14,7 +14,6 @@ gsr_color_depth color_depth; gsr_color_range color_range; bool record_cursor; - bool use_software_video_encoder; vec2i output_resolution; } gsr_capture_nvfbc_params; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/include/color_conversion.h new/gpu-screen-recorder-20250217/include/color_conversion.h --- old/gpu-screen-recorder-20250125/include/color_conversion.h 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/include/color_conversion.h 2025-02-17 19:23:54.000000000 +0100 @@ -22,7 +22,8 @@ typedef enum { GSR_DESTINATION_COLOR_NV12, /* YUV420, BT709, 8-bit */ - GSR_DESTINATION_COLOR_P010 /* YUV420, BT2020, 10-bit */ + GSR_DESTINATION_COLOR_P010, /* YUV420, BT2020, 10-bit */ + GSR_DESTINATION_COLOR_RGB8 } gsr_destination_color; typedef struct { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/include/egl.h new/gpu-screen-recorder-20250217/include/egl.h --- old/gpu-screen-recorder-20250125/include/egl.h 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/include/egl.h 2025-02-17 19:23:54.000000000 +0100 @@ -104,11 +104,13 @@ #define GL_RG 0x8227 #define GL_RGB 0x1907 #define GL_RGBA 0x1908 +#define GL_RGB8 0x8051 #define GL_RGBA8 0x8058 #define GL_R8 0x8229 #define GL_RG8 0x822B #define GL_R16 0x822A #define GL_RG16 0x822C +#define GL_RGB16 0x8054 #define GL_UNSIGNED_BYTE 0x1401 #define GL_COLOR_BUFFER_BIT 0x00004000 #define GL_TEXTURE_WRAP_S 0x2802 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/include/encoder/video/image.h new/gpu-screen-recorder-20250217/include/encoder/video/image.h --- old/gpu-screen-recorder-20250125/include/encoder/video/image.h 1970-01-01 01:00:00.000000000 +0100 +++ new/gpu-screen-recorder-20250217/include/encoder/video/image.h 2025-02-17 19:23:54.000000000 +0100 @@ -0,0 +1,15 @@ +#ifndef GSR_ENCODER_VIDEO_IMAGE_H +#define GSR_ENCODER_VIDEO_IMAGE_H + +#include "video.h" + +typedef struct gsr_egl gsr_egl; + +typedef struct { + gsr_egl *egl; + gsr_color_depth color_depth; +} gsr_video_encoder_image_params; + +gsr_video_encoder* gsr_video_encoder_image_create(const gsr_video_encoder_image_params *params); + +#endif /* GSR_ENCODER_VIDEO_IMAGE_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/include/pipewire_video.h new/gpu-screen-recorder-20250217/include/pipewire_video.h --- old/gpu-screen-recorder-20250125/include/pipewire_video.h 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/include/pipewire_video.h 2025-02-17 19:23:54.000000000 +0100 @@ -9,7 +9,7 @@ #include <spa/param/video/format.h> #define GSR_PIPEWIRE_VIDEO_MAX_MODIFIERS 1024 -#define GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS 6 +#define GSR_PIPEWIRE_VIDEO_MAX_VIDEO_FORMATS 12 #define GSR_PIPEWIRE_VIDEO_DMABUF_MAX_PLANES 4 typedef struct gsr_egl gsr_egl; @@ -82,7 +82,7 @@ uint32_t width, height; } crop; - gsr_video_format supported_video_formats[GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS]; + gsr_video_format supported_video_formats[GSR_PIPEWIRE_VIDEO_MAX_VIDEO_FORMATS]; gsr_pipewire_video_data_version server_version; gsr_pipewire_video_video_info video_info; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/include/utils.h new/gpu-screen-recorder-20250217/include/utils.h --- old/gpu-screen-recorder-20250125/include/utils.h 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/include/utils.h 2025-02-17 19:23:54.000000000 +0100 @@ -50,6 +50,7 @@ uint32_t monitor_identifier_from_type_and_count(int monitor_type_index, int monitor_type_count); bool gl_get_gpu_info(gsr_egl *egl, gsr_gpu_info *info); +bool version_greater_than(int major, int minor, int patch, int other_major, int other_minor, int other_patch); bool gl_driver_version_greater_than(const gsr_gpu_info *gpu_info, int major, int minor, int patch); bool try_card_has_valid_plane(const char *card_path); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/meson.build new/gpu-screen-recorder-20250217/meson.build --- old/gpu-screen-recorder-20250125/meson.build 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/meson.build 2025-02-17 19:23:54.000000000 +0100 @@ -1,4 +1,4 @@ -project('gpu-screen-recorder', ['c', 'cpp'], version : '5.1.0', default_options : ['warning_level=2']) +project('gpu-screen-recorder', ['c', 'cpp'], version : '5.1.1', default_options : ['warning_level=2']) add_project_arguments('-Wshadow', language : ['c', 'cpp']) if get_option('buildtype') == 'debug' @@ -18,6 +18,7 @@ 'src/encoder/video/vaapi.c', 'src/encoder/video/vulkan.c', 'src/encoder/video/software.c', + 'src/encoder/video/image.c', 'src/codec_query/nvenc.c', 'src/codec_query/vaapi.c', 'src/codec_query/vulkan.c', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/project.conf new/gpu-screen-recorder-20250217/project.conf --- old/gpu-screen-recorder-20250125/project.conf 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/project.conf 2025-02-17 19:23:54.000000000 +0100 @@ -1,7 +1,7 @@ [package] name = "gpu-screen-recorder" type = "executable" -version = "5.1.0" +version = "5.1.1" platforms = ["posix"] [config] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/src/capture/kms.c new/gpu-screen-recorder-20250217/src/capture/kms.c --- old/gpu-screen-recorder-20250125/src/capture/kms.c 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/src/capture/kms.c 2025-02-17 19:23:54.000000000 +0100 @@ -236,6 +236,11 @@ if(self->fast_path_failed) fprintf(stderr, "gsr warning: gsr_capture_kms_start: your amd driver (mesa) version is known to be buggy (<= version 24.0.9), falling back to opengl copy\n"); + //if(self->params.hdr) { + // self->fast_path_failed = true; + // fprintf(stderr, "gsr warning: gsr_capture_kms_start: recording with hdr requires shader color conversion which might be slow. If this is an issue record with -w portal instead (which converts HDR to SDR)\n"); + //} + self->mesa_supports_compute_only_vaapi_copy = self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && gl_driver_version_greater_than(&self->params.egl->gpu_info, 24, 3, 6); frame->width = video_codec_context->width; @@ -756,8 +761,8 @@ mastering_display_metadata->min_luminance = av_make_q(self->hdr_metadata.hdmi_metadata_type1.min_display_mastering_luminance, 10000); mastering_display_metadata->max_luminance = av_make_q(self->hdr_metadata.hdmi_metadata_type1.max_display_mastering_luminance, 1); - mastering_display_metadata->has_primaries = mastering_display_metadata->display_primaries[0][0].num > 0; - mastering_display_metadata->has_luminance = mastering_display_metadata->max_luminance.num > 0; + mastering_display_metadata->has_primaries = true; + mastering_display_metadata->has_luminance = true; return true; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/src/capture/xcomposite.c new/gpu-screen-recorder-20250217/src/capture/xcomposite.c --- old/gpu-screen-recorder-20250125/src/capture/xcomposite.c 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/src/capture/xcomposite.c 2025-02-17 19:23:54.000000000 +0100 @@ -98,7 +98,7 @@ /* Disable vsync */ self->params.egl->eglSwapInterval(self->params.egl->egl_display, 0); if(window_texture_init(&self->window_texture, self->display, self->window, self->params.egl) != 0 && !self->params.follow_focused) { - fprintf(stderr, "gsr error: gsr_capture_xcomposite_start: failed to get window texture for window %ld\n", self->window); + fprintf(stderr, "gsr error: gsr_capture_xcomposite_start: failed to get window texture for window %ld\n", (long)self->window); return -1; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/src/color_conversion.c new/gpu-screen-recorder-20250217/src/color_conversion.c --- old/gpu-screen-recorder-20250125/src/color_conversion.c 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/src/color_conversion.c 2025-02-17 19:23:54.000000000 +0100 @@ -9,6 +9,7 @@ #define MAX_SHADERS 4 #define MAX_FRAMEBUFFERS 2 +#define EXTERNAL_TEXTURE_SHADER_OFFSET 2 static float abs_f(float v) { return v >= 0.0f ? v : -v; @@ -69,6 +70,8 @@ } break; } + case GSR_DESTINATION_COLOR_RGB8: + return ""; default: return NULL; } @@ -93,6 +96,12 @@ " gl_Position = vec4(offset.x, offset.y, 0.0, 0.0) + vec4(pos.x, pos.y, 0.0, 1.0); \n" "} \n"); + const char *main_code = + main_code = + " vec4 pixel = texture(tex1, texcoords_out); \n" + " FragColor.x = (RGBtoYUV * vec4(pixel.rgb, 1.0)).x; \n" + " FragColor.w = pixel.a; \n"; + char fragment_shader[2048]; if(external_texture) { snprintf(fragment_shader, sizeof(fragment_shader), @@ -106,10 +115,8 @@ "%s" "void main() \n" "{ \n" - " vec4 pixel = texture(tex1, texcoords_out); \n" - " FragColor.x = (RGBtoYUV * vec4(pixel.rgb, 1.0)).x; \n" - " FragColor.w = pixel.a; \n" - "} \n", color_transform_matrix); + "%s" + "} \n", color_transform_matrix, main_code); } else { snprintf(fragment_shader, sizeof(fragment_shader), "#version 300 es \n" @@ -120,10 +127,8 @@ "%s" "void main() \n" "{ \n" - " vec4 pixel = texture(tex1, texcoords_out); \n" - " FragColor.x = (RGBtoYUV * vec4(pixel.rgb, 1.0)).x; \n" - " FragColor.w = pixel.a; \n" - "} \n", color_transform_matrix); + "%s" + "} \n", color_transform_matrix, main_code); } if(gsr_shader_init(shader, egl, vertex_shader, fragment_shader) != 0) @@ -145,7 +150,7 @@ "in vec2 pos; \n" "in vec2 texcoords; \n" "out vec2 texcoords_out; \n" - "uniform vec2 offset; \n" + "uniform vec2 offset; \n" "uniform float rotation; \n" ROTATE_Z "void main() \n" @@ -154,6 +159,12 @@ " gl_Position = (vec4(offset.x, offset.y, 0.0, 0.0) + vec4(pos.x, pos.y, 0.0, 1.0)) * vec4(0.5, 0.5, 1.0, 1.0) - vec4(0.5, 0.5, 0.0, 0.0); \n" "} \n"); + const char *main_code = + main_code = + " vec4 pixel = texture(tex1, texcoords_out); \n" + " FragColor.xy = (RGBtoYUV * vec4(pixel.rgb, 1.0)).yz; \n" + " FragColor.w = pixel.a; \n"; + char fragment_shader[2048]; if(external_texture) { snprintf(fragment_shader, sizeof(fragment_shader), @@ -167,10 +178,8 @@ "%s" "void main() \n" "{ \n" - " vec4 pixel = texture(tex1, texcoords_out); \n" - " FragColor.xy = (RGBtoYUV * vec4(pixel.rgb, 1.0)).yz; \n" - " FragColor.w = pixel.a; \n" - "} \n", color_transform_matrix); + "%s" + "} \n", color_transform_matrix, main_code); } else { snprintf(fragment_shader, sizeof(fragment_shader), "#version 300 es \n" @@ -181,10 +190,66 @@ "%s" "void main() \n" "{ \n" + "%s" + "} \n", color_transform_matrix, main_code); + } + + if(gsr_shader_init(shader, egl, vertex_shader, fragment_shader) != 0) + return -1; + + gsr_shader_bind_attribute_location(shader, "pos", 0); + gsr_shader_bind_attribute_location(shader, "texcoords", 1); + uniforms->offset = egl->glGetUniformLocation(shader->program_id, "offset"); + uniforms->rotation = egl->glGetUniformLocation(shader->program_id, "rotation"); + return 0; +} + +static unsigned int load_shader_rgb(gsr_shader *shader, gsr_egl *egl, gsr_color_uniforms *uniforms, bool external_texture) { + char vertex_shader[2048]; + snprintf(vertex_shader, sizeof(vertex_shader), + "#version 300 es \n" + "in vec2 pos; \n" + "in vec2 texcoords; \n" + "out vec2 texcoords_out; \n" + "uniform vec2 offset; \n" + "uniform float rotation; \n" + ROTATE_Z + "void main() \n" + "{ \n" + " texcoords_out = (vec4(texcoords.x - 0.5, texcoords.y - 0.5, 0.0, 0.0) * rotate_z(rotation)).xy + vec2(0.5, 0.5); \n" + " gl_Position = vec4(offset.x, offset.y, 0.0, 0.0) + vec4(pos.x, pos.y, 0.0, 1.0); \n" + "} \n"); + + const char *main_code = + main_code = " vec4 pixel = texture(tex1, texcoords_out); \n" - " FragColor.xy = (RGBtoYUV * vec4(pixel.rgb, 1.0)).yz; \n" - " FragColor.w = pixel.a; \n" - "} \n", color_transform_matrix); + " FragColor = pixel; \n"; + + char fragment_shader[2048]; + if(external_texture) { + snprintf(fragment_shader, sizeof(fragment_shader), + "#version 300 es \n" + "#extension GL_OES_EGL_image_external : enable \n" + "#extension GL_OES_EGL_image_external_essl3 : require \n" + "precision mediump float; \n" + "in vec2 texcoords_out; \n" + "uniform samplerExternalOES tex1; \n" + "out vec4 FragColor; \n" + "void main() \n" + "{ \n" + "%s" + "} \n", main_code); + } else { + snprintf(fragment_shader, sizeof(fragment_shader), + "#version 300 es \n" + "precision mediump float; \n" + "in vec2 texcoords_out; \n" + "uniform sampler2D tex1; \n" + "out vec4 FragColor; \n" + "void main() \n" + "{ \n" + "%s" + "} \n", main_code); } if(gsr_shader_init(shader, egl, vertex_shader, fragment_shader) != 0) @@ -272,18 +337,37 @@ } if(self->params.load_external_image_shader) { - if(load_shader_y(&self->shaders[2], self->params.egl, &self->uniforms[2], params->destination_color, params->color_range, true) != 0) { + if(load_shader_y(&self->shaders[EXTERNAL_TEXTURE_SHADER_OFFSET], self->params.egl, &self->uniforms[EXTERNAL_TEXTURE_SHADER_OFFSET], params->destination_color, params->color_range, true) != 0) { fprintf(stderr, "gsr error: gsr_color_conversion_init: failed to load Y shader\n"); goto err; } - if(load_shader_uv(&self->shaders[3], self->params.egl, &self->uniforms[3], params->destination_color, params->color_range, true) != 0) { + if(load_shader_uv(&self->shaders[EXTERNAL_TEXTURE_SHADER_OFFSET + 1], self->params.egl, &self->uniforms[EXTERNAL_TEXTURE_SHADER_OFFSET + 1], params->destination_color, params->color_range, true) != 0) { fprintf(stderr, "gsr error: gsr_color_conversion_init: failed to load UV shader\n"); goto err; } } break; } + case GSR_DESTINATION_COLOR_RGB8: { + if(self->params.num_destination_textures != 1) { + fprintf(stderr, "gsr error: gsr_color_conversion_init: expected 1 destination textures for destination color RGB8, got %d destination texture(s)\n", self->params.num_destination_textures); + return -1; + } + + if(load_shader_rgb(&self->shaders[0], self->params.egl, &self->uniforms[0], false) != 0) { + fprintf(stderr, "gsr error: gsr_color_conversion_init: failed to load Y shader\n"); + goto err; + } + + if(self->params.load_external_image_shader) { + if(load_shader_rgb(&self->shaders[EXTERNAL_TEXTURE_SHADER_OFFSET], self->params.egl, &self->uniforms[EXTERNAL_TEXTURE_SHADER_OFFSET], true) != 0) { + fprintf(stderr, "gsr error: gsr_color_conversion_init: failed to load Y shader\n"); + goto err; + } + } + break; + } } if(load_framebuffers(self) != 0) @@ -415,7 +499,7 @@ self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffers[0]); //cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT); // TODO: Do this in a separate clear_ function. We want to do that when using multiple drm to create the final image (multiple monitors for example) - const int shader_index = external_texture ? 2 : 0; + const int shader_index = external_texture ? EXTERNAL_TEXTURE_SHADER_OFFSET : 0; gsr_shader_use(&self->shaders[shader_index]); self->params.egl->glUniform1f(self->uniforms[shader_index].rotation, rotation); self->params.egl->glUniform2f(self->uniforms[shader_index].offset, pos_norm.x, pos_norm.y); @@ -426,7 +510,7 @@ self->params.egl->glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffers[1]); //cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT); - const int shader_index = external_texture ? 3 : 1; + const int shader_index = external_texture ? EXTERNAL_TEXTURE_SHADER_OFFSET + 1 : 1; gsr_shader_use(&self->shaders[shader_index]); self->params.egl->glUniform1f(self->uniforms[shader_index].rotation, rotation); self->params.egl->glUniform2f(self->uniforms[shader_index].offset, pos_norm.x, pos_norm.y); @@ -453,6 +537,13 @@ color2[2] = 0.0f; color2[3] = 1.0f; break; + } + case GSR_DESTINATION_COLOR_RGB8: { + color2[0] = 0.0f; + color2[1] = 0.0f; + color2[2] = 0.0f; + color2[3] = 1.0f; + break; } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/src/encoder/video/image.c new/gpu-screen-recorder-20250217/src/encoder/video/image.c --- old/gpu-screen-recorder-20250125/src/encoder/video/image.c 1970-01-01 01:00:00.000000000 +0100 +++ new/gpu-screen-recorder-20250217/src/encoder/video/image.c 2025-02-17 19:23:54.000000000 +0100 @@ -0,0 +1,130 @@ +#include "../../../include/encoder/video/image.h" +#include "../../../include/egl.h" + +#include <libavcodec/avcodec.h> +#include <libavutil/frame.h> + +#include <stdlib.h> + +#define LINESIZE_ALIGNMENT 4 + +typedef struct { + gsr_video_encoder_image_params params; + + unsigned int target_texture; +} gsr_video_encoder_image; + +static unsigned int gl_create_texture(gsr_egl *egl, int width, int height, int internal_format, unsigned int format) { + unsigned int texture_id = 0; + egl->glGenTextures(1, &texture_id); + egl->glBindTexture(GL_TEXTURE_2D, texture_id); + egl->glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, NULL); + + egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + egl->glBindTexture(GL_TEXTURE_2D, 0); + return texture_id; +} + +static bool gsr_video_encoder_image_setup_textures(gsr_video_encoder_image *self, AVCodecContext *video_codec_context, AVFrame *frame) { + int res = av_frame_get_buffer(frame, LINESIZE_ALIGNMENT); + if(res < 0) { + fprintf(stderr, "gsr error: gsr_video_encoder_image_setup_textures: av_frame_get_buffer failed: %d\n", res); + return false; + } + + res = av_frame_make_writable(frame); + if(res < 0) { + fprintf(stderr, "gsr error: gsr_video_encoder_image_setup_textures: av_frame_make_writable failed: %d\n", res); + return false; + } + + self->target_texture = gl_create_texture(self->params.egl, video_codec_context->width, video_codec_context->height, self->params.color_depth == GSR_COLOR_DEPTH_8_BITS ? GL_RGB8 : GL_RGB16, GL_RGB); + if(self->target_texture == 0) { + fprintf(stderr, "gsr error: gsr_capture_kms_setup_cuda_textures: failed to create opengl texture\n"); + return false; + } + + return true; +} + +static void gsr_video_encoder_image_stop(gsr_video_encoder_image *self, AVCodecContext *video_codec_context); + +static bool gsr_video_encoder_image_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame) { + gsr_video_encoder_image *self = encoder->priv; + + video_codec_context->width = FFALIGN(video_codec_context->width, LINESIZE_ALIGNMENT); + video_codec_context->height = FFALIGN(video_codec_context->height, 2); + + frame->width = video_codec_context->width; + frame->height = video_codec_context->height; + + if(!gsr_video_encoder_image_setup_textures(self, video_codec_context, frame)) { + gsr_video_encoder_image_stop(self, video_codec_context); + return false; + } + + return true; +} + +void gsr_video_encoder_image_stop(gsr_video_encoder_image *self, AVCodecContext *video_codec_context) { + (void)video_codec_context; + self->params.egl->glDeleteTextures(1, &self->target_texture); + self->target_texture = 0; +} + +static void gsr_video_encoder_image_copy_textures_to_frame(gsr_video_encoder *encoder, AVFrame *frame, gsr_color_conversion *color_conversion) { + gsr_video_encoder_image *self = encoder->priv; + // TODO: hdr support + self->params.egl->glBindTexture(GL_TEXTURE_2D, self->target_texture); + // We could use glGetTexSubImage and then we wouldn't have to use a specific linesize (LINESIZE_ALIGNMENT) that adds padding, + // but glGetTexSubImage is only available starting from opengl 4.5. + self->params.egl->glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, frame->data[0]); + self->params.egl->glBindTexture(GL_TEXTURE_2D, 0); + // cap_kms->kms.base.egl->eglSwapBuffers(cap_kms->kms.base.egl->egl_display, cap_kms->kms.base.egl->egl_surface); + + self->params.egl->glFlush(); + self->params.egl->glFinish(); +} + +static void gsr_video_encoder_image_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color) { + gsr_video_encoder_image *self = encoder->priv; + textures[0] = self->target_texture; + *num_textures = 1; + // TODO: 10-bit support + //*destination_color = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? GSR_DESTINATION_COLOR_P010 : GSR_DESTINATION_COLOR_NV12; + *destination_color = GSR_DESTINATION_COLOR_RGB8; +} + +static void gsr_video_encoder_image_destroy(gsr_video_encoder *encoder, AVCodecContext *video_codec_context) { + gsr_video_encoder_image_stop(encoder->priv, video_codec_context); + free(encoder->priv); + free(encoder); +} + +gsr_video_encoder* gsr_video_encoder_image_create(const gsr_video_encoder_image_params *params) { + gsr_video_encoder *encoder = calloc(1, sizeof(gsr_video_encoder)); + if(!encoder) + return NULL; + + gsr_video_encoder_image *encoder_image = calloc(1, sizeof(gsr_video_encoder_image)); + if(!encoder_image) { + free(encoder); + return NULL; + } + + encoder_image->params = *params; + + *encoder = (gsr_video_encoder) { + .start = gsr_video_encoder_image_start, + .copy_textures_to_frame = gsr_video_encoder_image_copy_textures_to_frame, + .get_textures = gsr_video_encoder_image_get_textures, + .destroy = gsr_video_encoder_image_destroy, + .priv = encoder_image + }; + + return encoder; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/src/main.cpp new/gpu-screen-recorder-20250217/src/main.cpp --- old/gpu-screen-recorder-20250125/src/main.cpp 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/src/main.cpp 2025-02-17 19:23:54.000000000 +0100 @@ -13,6 +13,7 @@ #include "../include/encoder/video/vaapi.h" #include "../include/encoder/video/vulkan.h" #include "../include/encoder/video/software.h" +#include "../include/encoder/video/image.h" #include "../include/codec_query/nvenc.h" #include "../include/codec_query/vaapi.h" #include "../include/codec_query/vulkan.h" @@ -112,7 +113,9 @@ VP8, VP9, H264_VULKAN, - HEVC_VULKAN + HEVC_VULKAN, + JPEG, + PNG }; enum class AudioCodec { @@ -216,6 +219,16 @@ } } +static bool video_codec_is_image(VideoCodec video_codec) { + switch(video_codec) { + case VideoCodec::JPEG: + case VideoCodec::PNG: + return true; + default: + return false; + } +} + struct PacketData { PacketData() {} PacketData(const PacketData&) = delete; @@ -580,7 +593,22 @@ if (codec_context->codec_id == AV_CODEC_ID_MPEG1VIDEO) codec_context->mb_decision = 2; - if(!use_software_video_encoder && vendor != GSR_GPU_VENDOR_NVIDIA && bitrate_mode != BitrateMode::CBR) { + if(video_codec_is_image(video_codec)) { + switch(video_quality) { + case VideoQuality::MEDIUM: + codec_context->compression_level = 8; + break; + case VideoQuality::HIGH: + codec_context->compression_level = 6; + break; + case VideoQuality::VERY_HIGH: + codec_context->compression_level = 4; + break; + case VideoQuality::ULTRA: + codec_context->compression_level = 2; + break; + } + } else if(!use_software_video_encoder && vendor != GSR_GPU_VENDOR_NVIDIA && bitrate_mode != BitrateMode::CBR) { // 8 bit / 10 bit = 80%, and increase it even more const float quality_multiply = hdr ? (8.0f/10.0f * 0.7f) : 1.0f; if(codec_context->codec_id == AV_CODEC_ID_AV1 || codec_context->codec_id == AV_CODEC_ID_H264 || codec_context->codec_id == AV_CODEC_ID_HEVC) { @@ -715,6 +743,15 @@ return frame; } +static void open_video_image(AVCodecContext *codec_context) { + AVDictionary *options = nullptr; + int ret = avcodec_open2(codec_context, codec_context->codec, &options); + if (ret < 0) { + fprintf(stderr, "Error: Could not open video codec: %s\n", av_error_to_string(ret)); + _exit(1); + } +} + static void dict_set_profile(AVCodecContext *codec_context, gsr_gpu_vendor vendor, gsr_color_depth color_depth, AVDictionary **options) { #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 17, 100) if(codec_context->codec_id == AV_CODEC_ID_H264) { @@ -1197,7 +1234,7 @@ printf("\n"); printf(" --info\n"); printf(" List info about the system. Lists the following information (prints them to stdout and exits):\n"); - printf(" Supported video codecs (h264, h264_software, hevc, hevc_hdr, hevc_10bit, av1, av1_hdr, av1_10bit, vp8, vp9 (if supported)).\n"); + printf(" Supported video codecs (h264, h264_software, hevc, hevc_hdr, hevc_10bit, av1, av1_hdr, av1_10bit, vp8, vp9) and image codecs (jpeg, png) (if supported).\n"); printf(" Supported capture options (window, focused, screen, monitors and portal, if supported by the system).\n"); printf(" If opengl initialization fails then the program exits with 22, if no usable drm device is found then it exits with 23. On success it exits with 0.\n"); printf("\n"); @@ -1257,6 +1294,7 @@ printf(" %s -w screen -f 60 -a \"app:firefox|app:csgo\" -o \"$HOME/Videos/video.mp4\"\n", program_name); printf(" %s -w screen -f 60 -a \"app-inverse:firefox|app-inverse:csgo\" -o \"$HOME/Videos/video.mp4\"\n", program_name); printf(" %s -w screen -f 60 -a \"default-input|app-inverse:Brave\" -o \"$HOME/Videos/video.mp4\"\n", program_name); + printf(" %s -w screen -f 60 -o \"$HOME/Pictures/image.jpg\"\n", program_name); //fprintf(stderr, " gpu-screen-recorder -w screen -f 60 -q ultra -pixfmt yuv444 -o video.mp4\n"); fflush(stdout); _exit(1); @@ -1354,16 +1392,17 @@ return; } - const char *args[6]; + const char *args[7]; const bool inside_flatpak = getenv("FLATPAK_ID") != NULL; if(inside_flatpak) { args[0] = "flatpak-spawn"; args[1] = "--host"; - args[2] = script_file_full; - args[3] = video_file; - args[4] = type; - args[5] = NULL; + args[2] = "--"; + args[3] = script_file_full; + args[4] = video_file; + args[5] = type; + args[6] = NULL; } else { args[0] = script_file_full; args[1] = video_file; @@ -1442,17 +1481,17 @@ if(!light_metadata || !mastering_display_metadata) { if(light_metadata) - av_freep(light_metadata); + av_freep(&light_metadata); if(mastering_display_metadata) - av_freep(mastering_display_metadata); + av_freep(&mastering_display_metadata); return false; } if(!gsr_capture_set_hdr_metadata(cap, mastering_display_metadata, light_metadata)) { - av_freep(light_metadata); - av_freep(mastering_display_metadata); + av_freep(&light_metadata); + av_freep(&mastering_display_metadata); return false; } @@ -1471,10 +1510,10 @@ #endif if(!content_light_level_added) - av_freep(light_metadata); + av_freep(&light_metadata); if(!mastering_display_metadata_added) - av_freep(mastering_display_metadata); + av_freep(&mastering_display_metadata); // Return true even on failure because we dont want to retry adding hdr metadata on failure return true; @@ -1644,6 +1683,12 @@ return (int)str.size() >= len && memcmp(str.data(), substr, len) == 0; } +static bool string_ends_with(const char *str, const char *substr) { + int str_len = strlen(str); + int substr_len = strlen(substr); + return str_len >= substr_len && memcmp(str + str_len - substr_len, substr, substr_len) == 0; +} + static const AudioDevice* get_audio_device_by_name(const std::vector<AudioDevice> &audio_devices, const char *name) { for(const auto &audio_device : audio_devices) { if(strcmp(audio_device.name.c_str(), name) == 0) @@ -1716,29 +1761,44 @@ return false; } -// TODO: Proper cleanup -static int init_filter_graph(AVCodecContext *audio_codec_context, AVFilterGraph **graph, AVFilterContext **sink, std::vector<AVFilterContext*> &src_filter_ctx, size_t num_sources) { +static int init_filter_graph(AVCodecContext* audio_codec_context, AVFilterGraph** graph, AVFilterContext** sink, std::vector<AVFilterContext*>& src_filter_ctx, size_t num_sources) { char ch_layout[64]; int err = 0; ch_layout[0] = '\0'; - AVFilterGraph *filter_graph = avfilter_graph_alloc(); + // C89-style variable declaration to + // avoid problems because of goto + AVFilterGraph* filter_graph = nullptr; + AVFilterContext* mix_ctx = nullptr; + + const AVFilter* mix_filter = nullptr; + const AVFilter* abuffersink = nullptr; + AVFilterContext* abuffersink_ctx = nullptr; + char args[512] = { 0 }; +#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(7, 107, 100) + bool normalize = false; +#endif + + filter_graph = avfilter_graph_alloc(); if (!filter_graph) { fprintf(stderr, "Unable to create filter graph.\n"); - return AVERROR(ENOMEM); + err = AVERROR(ENOMEM); + goto fail; } for(size_t i = 0; i < num_sources; ++i) { const AVFilter *abuffer = avfilter_get_by_name("abuffer"); if (!abuffer) { fprintf(stderr, "Could not find the abuffer filter.\n"); - return AVERROR_FILTER_NOT_FOUND; + err = AVERROR_FILTER_NOT_FOUND; + goto fail; } AVFilterContext *abuffer_ctx = avfilter_graph_alloc_filter(filter_graph, abuffer, NULL); if (!abuffer_ctx) { fprintf(stderr, "Could not allocate the abuffer instance.\n"); - return AVERROR(ENOMEM); + err = AVERROR(ENOMEM); + goto fail; } #if LIBAVCODEC_VERSION_MAJOR < 60 @@ -1755,51 +1815,50 @@ err = avfilter_init_str(abuffer_ctx, NULL); if (err < 0) { fprintf(stderr, "Could not initialize the abuffer filter.\n"); - return err; + goto fail; } src_filter_ctx.push_back(abuffer_ctx); } - const AVFilter *mix_filter = avfilter_get_by_name("amix"); + mix_filter = avfilter_get_by_name("amix"); if (!mix_filter) { av_log(NULL, AV_LOG_ERROR, "Could not find the mix filter.\n"); - return AVERROR_FILTER_NOT_FOUND; + err = AVERROR_FILTER_NOT_FOUND; + goto fail; } #if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(7, 107, 100) - bool normalize = false; - char args[512]; snprintf(args, sizeof(args), "inputs=%d:normalize=%s", (int)num_sources, normalize ? "true" : "false"); #else - char args[512]; snprintf(args, sizeof(args), "inputs=%d", (int)num_sources); fprintf(stderr, "Warning: your ffmpeg version doesn't support disabling normalizing of mixed audio. Volume might be lower than expected\n"); #endif - AVFilterContext *mix_ctx; err = avfilter_graph_create_filter(&mix_ctx, mix_filter, "amix", args, NULL, filter_graph); if (err < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot create audio amix filter\n"); - return err; + goto fail; } - const AVFilter *abuffersink = avfilter_get_by_name("abuffersink"); + abuffersink = avfilter_get_by_name("abuffersink"); if (!abuffersink) { fprintf(stderr, "Could not find the abuffersink filter.\n"); - return AVERROR_FILTER_NOT_FOUND; + err = AVERROR_FILTER_NOT_FOUND; + goto fail; } - AVFilterContext *abuffersink_ctx = avfilter_graph_alloc_filter(filter_graph, abuffersink, "sink"); + abuffersink_ctx = avfilter_graph_alloc_filter(filter_graph, abuffersink, "sink"); if (!abuffersink_ctx) { fprintf(stderr, "Could not allocate the abuffersink instance.\n"); - return AVERROR(ENOMEM); + err = AVERROR(ENOMEM); + goto fail; } err = avfilter_init_str(abuffersink_ctx, NULL); if (err < 0) { fprintf(stderr, "Could not initialize the abuffersink instance.\n"); - return err; + goto fail; } err = 0; @@ -1812,24 +1871,37 @@ err = avfilter_link(mix_ctx, 0, abuffersink_ctx, 0); if (err < 0) { av_log(NULL, AV_LOG_ERROR, "Error connecting filters\n"); - return err; + goto fail; } err = avfilter_graph_config(filter_graph, NULL); if (err < 0) { av_log(NULL, AV_LOG_ERROR, "Error configuring the filter graph\n"); - return err; + goto fail; } *graph = filter_graph; - *sink = abuffersink_ctx; + *sink = abuffersink_ctx; return 0; + +fail: + avfilter_graph_free(&filter_graph); + src_filter_ctx.clear(); // possibly unnecessary? + return err; } static gsr_video_encoder* create_video_encoder(gsr_egl *egl, bool overclock, gsr_color_depth color_depth, bool use_software_video_encoder, VideoCodec video_codec) { gsr_video_encoder *video_encoder = nullptr; + if(video_codec_is_image(video_codec)) { + gsr_video_encoder_image_params params; + params.egl = egl; + params.color_depth = color_depth; + video_encoder = gsr_video_encoder_image_create(¶ms); + return video_encoder; + } + if(use_software_video_encoder) { gsr_video_encoder_software_params params; params.egl = egl; @@ -1979,6 +2051,10 @@ return avcodec_find_encoder_by_name("h264_vulkan"); case VideoCodec::HEVC_VULKAN: return avcodec_find_encoder_by_name("hevc_vulkan"); + case VideoCodec::JPEG: + return avcodec_find_encoder_by_name("libopenjpeg"); + case VideoCodec::PNG: + return avcodec_find_encoder_by_name("png"); } return nullptr; } @@ -2049,6 +2125,10 @@ puts("vp8"); if(supported_video_codecs.vp9.supported) puts("vp9"); + if(avcodec_find_encoder_by_name("libopenjpeg")) + puts("jpeg"); + if(avcodec_find_encoder_by_name("png")) + puts("png"); //if(supported_video_codecs_vulkan.h264.supported) // puts("h264_vulkan"); //if(supported_video_codecs_vulkan.hevc.supported) @@ -2324,7 +2404,7 @@ } static gsr_capture* create_capture_impl(std::string &window_str, vec2i output_resolution, bool wayland, gsr_egl *egl, int fps, VideoCodec video_codec, gsr_color_range color_range, - bool record_cursor, bool use_software_video_encoder, bool restore_portal_session, const char *portal_session_token_filepath, + bool record_cursor, bool restore_portal_session, const char *portal_session_token_filepath, gsr_color_depth color_depth) { Window src_window_id = None; @@ -2386,7 +2466,6 @@ nvfbc_params.color_depth = color_depth; nvfbc_params.color_range = color_range; nvfbc_params.record_cursor = record_cursor; - nvfbc_params.use_software_video_encoder = use_software_video_encoder; nvfbc_params.output_resolution = output_resolution; capture = gsr_capture_nvfbc_create(&nvfbc_params); if(!capture) @@ -2437,7 +2516,10 @@ } static AVPixelFormat get_pixel_format(VideoCodec video_codec, gsr_gpu_vendor vendor, bool use_software_video_encoder) { - if(use_software_video_encoder) { + if(video_codec_is_image(video_codec)) { + // TODO: hdr + return AV_PIX_FMT_RGB24; + } else if(use_software_video_encoder) { return AV_PIX_FMT_NV12; } else { if(video_codec_is_vulkan(video_codec)) @@ -2447,10 +2529,19 @@ } } +enum class ArgType { + STRING, + BOOLEAN +}; + struct Arg { std::vector<const char*> values; bool optional = false; bool list = false; + ArgType arg_type = ArgType::STRING; + union { + bool boolean = false; + } typed_value; const char* value() const { if(values.empty()) @@ -2652,6 +2743,8 @@ case VideoCodec::VP9: return "vp9"; case VideoCodec::H264_VULKAN: return "h264_vulkan"; case VideoCodec::HEVC_VULKAN: return "hevc_vulkan"; + case VideoCodec::JPEG: return "jpeg"; + case VideoCodec::PNG: return "png"; } return ""; } @@ -2669,6 +2762,8 @@ case VideoCodec::VP9: return supported_video_codecs.vp9.low_power; case VideoCodec::H264_VULKAN: return supported_video_codecs.h264.low_power; case VideoCodec::HEVC_VULKAN: return supported_video_codecs.hevc.low_power; // TODO: hdr, 10 bit + case VideoCodec::JPEG: return false; + case VideoCodec::PNG: return false; } return false; } @@ -2744,6 +2839,11 @@ video_codec_f = get_ffmpeg_video_codec(*video_codec, egl->gpu_info.vendor); break; } + case VideoCodec::JPEG: + case VideoCodec::PNG: { + video_codec_f = get_ffmpeg_video_codec(*video_codec, egl->gpu_info.vendor); + break; + } } if(!video_codec_auto && !video_codec_f && !is_flv) { @@ -2805,6 +2905,12 @@ video_codec_f = get_ffmpeg_video_codec(*video_codec, egl->gpu_info.vendor); break; } + case VideoCodec::JPEG: + case VideoCodec::PNG: { + // TODO: + //assert(false); + break; + } } } @@ -2978,6 +3084,31 @@ } #endif +static void set_video_codec_for_image_output(const char *filename, VideoCodec *video_codec, const char **video_codec_to_use) { + const bool video_codec_auto = strcmp(*video_codec_to_use, "auto") == 0; + if(string_ends_with(filename, ".jpg") || string_ends_with(filename, ".jpeg")) { + if(!video_codec_auto) + fprintf(stderr, "Warning: expected -k option to be set to 'auto' (or not specified) for jpeg output\n"); + *video_codec = VideoCodec::JPEG; + *video_codec_to_use = "jpeg"; + } else if(string_ends_with(filename, ".png")) { + if(!video_codec_auto) + fprintf(stderr, "Warning: expected -k option to be set to 'auto' (or not specified) for png output\n"); + *video_codec = VideoCodec::PNG; + *video_codec_to_use = "png"; + } +} + +static bool arg_get_boolean_value(std::map<std::string, Arg> &args, const char *arg_name, bool default_value) { + auto it = args.find(arg_name); + if(it == args.end() || !it->second.value()) { + return default_value; + } else { + assert(it->second.arg_type == ArgType::BOOLEAN); + return it->second.typed_value.boolean; + } +} + int main(int argc, char **argv) { setlocale(LC_ALL, "C"); // Sigh... stupid C @@ -3060,53 +3191,68 @@ //av_log_set_level(AV_LOG_TRACE); + const bool is_optional = true; + const bool is_list = true; std::map<std::string, Arg> args = { - { "-w", Arg { {}, false, false } }, - { "-c", Arg { {}, true, false } }, - { "-f", Arg { {}, false, false } }, - { "-s", Arg { {}, true, false } }, - { "-a", Arg { {}, true, true } }, - { "-q", Arg { {}, true, false } }, - { "-o", Arg { {}, true, false } }, - { "-r", Arg { {}, true, false } }, - { "-restart-replay-on-save", Arg { {}, true, false } }, - { "-k", Arg { {}, true, false } }, - { "-ac", Arg { {}, true, false } }, - { "-ab", Arg { {}, true, false } }, - { "-oc", Arg { {}, true, false } }, - { "-fm", Arg { {}, true, false } }, - { "-bm", Arg { {}, true, false } }, - { "-pixfmt", Arg { {}, true, false } }, - { "-v", Arg { {}, true, false } }, - { "-gl-debug", Arg { {}, true, false } }, - { "-df", Arg { {}, true, false } }, - { "-sc", Arg { {}, true, false } }, - { "-cr", Arg { {}, true, false } }, - { "-cursor", Arg { {}, true, false } }, - { "-keyint", Arg { {}, true, false } }, - { "-restore-portal-session", Arg { {}, true, false } }, - { "-portal-session-token-filepath", Arg { {}, true, false } }, - { "-encoder", Arg { {}, true, false } }, + { "-w", Arg { {}, !is_optional, !is_list, ArgType::STRING, {false} } }, + { "-c", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-f", Arg { {}, !is_optional, !is_list, ArgType::STRING, {false} } }, + { "-s", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-a", Arg { {}, is_optional, is_list, ArgType::STRING, {false} } }, + { "-q", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-o", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-r", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-restart-replay-on-save", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-k", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-ac", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-ab", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-oc", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-fm", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-bm", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-pixfmt", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-v", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-gl-debug", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-df", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-sc", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-cr", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-cursor", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-keyint", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, + { "-restore-portal-session", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-portal-session-token-filepath", Arg { {}, is_optional, !is_list, ArgType::BOOLEAN, {false} } }, + { "-encoder", Arg { {}, is_optional, !is_list, ArgType::STRING, {false} } }, }; for(int i = 1; i < argc; i += 2) { - auto it = args.find(argv[i]); + const char *arg_name = argv[i]; + auto it = args.find(arg_name); if(it == args.end()) { - fprintf(stderr, "Error: invalid argument '%s'\n", argv[i]); + fprintf(stderr, "Error: invalid argument '%s'\n", arg_name); usage(); } if(!it->second.values.empty() && !it->second.list) { - fprintf(stderr, "Error: expected argument '%s' to only be specified once\n", argv[i]); + fprintf(stderr, "Error: expected argument '%s' to only be specified once\n", arg_name); usage(); } if(i + 1 >= argc) { - fprintf(stderr, "Error: missing value for argument '%s'\n", argv[i]); + fprintf(stderr, "Error: missing value for argument '%s'\n", arg_name); usage(); } - it->second.values.push_back(argv[i + 1]); + const char *arg_value = argv[i + 1]; + if(it->second.arg_type == ArgType::BOOLEAN) { + if(strcmp(arg_value, "yes") == 0) { + it->second.typed_value.boolean = true; + } else if(strcmp(arg_value, "no") == 0) { + it->second.typed_value.boolean = false; + } else { + fprintf(stderr, "Error: %s should either be 'yes' or 'no', got: '%s'\n", arg_name, arg_value); + usage(); + } + } + + it->second.values.push_back(arg_value); } for(auto &it : args) { @@ -3218,89 +3364,13 @@ } } - bool overclock = false; - const char *overclock_str = args["-oc"].value(); - if(!overclock_str) - overclock_str = "no"; - - if(strcmp(overclock_str, "yes") == 0) { - overclock = true; - } else if(strcmp(overclock_str, "no") == 0) { - overclock = false; - } else { - fprintf(stderr, "Error: -oc should either be either 'yes' or 'no', got: '%s'\n", overclock_str); - usage(); - } - - bool verbose = true; - const char *verbose_str = args["-v"].value(); - if(!verbose_str) - verbose_str = "yes"; - - if(strcmp(verbose_str, "yes") == 0) { - verbose = true; - } else if(strcmp(verbose_str, "no") == 0) { - verbose = false; - } else { - fprintf(stderr, "Error: -v should either be either 'yes' or 'no', got: '%s'\n", verbose_str); - usage(); - } - - bool gl_debug = false; - const char *gl_debug_str = args["-gl-debug"].value(); - if(!gl_debug_str) - gl_debug_str = "no"; - - if(strcmp(gl_debug_str, "yes") == 0) { - gl_debug = true; - } else if(strcmp(gl_debug_str, "no") == 0) { - gl_debug = false; - } else { - fprintf(stderr, "Error: -gl-debug should either be either 'yes' or 'no', got: '%s'\n", gl_debug_str); - usage(); - } - - bool record_cursor = true; - const char *record_cursor_str = args["-cursor"].value(); - if(!record_cursor_str) - record_cursor_str = "yes"; - - if(strcmp(record_cursor_str, "yes") == 0) { - record_cursor = true; - } else if(strcmp(record_cursor_str, "no") == 0) { - record_cursor = false; - } else { - fprintf(stderr, "Error: -cursor should either be either 'yes' or 'no', got: '%s'\n", record_cursor_str); - usage(); - } - - bool date_folders = false; - const char *date_folders_str = args["-df"].value(); - if(!date_folders_str) - date_folders_str = "no"; - - if(strcmp(date_folders_str, "yes") == 0) { - date_folders = true; - } else if(strcmp(date_folders_str, "no") == 0) { - date_folders = false; - } else { - fprintf(stderr, "Error: -df should either be either 'yes' or 'no', got: '%s'\n", date_folders_str); - usage(); - } - - bool restore_portal_session = false; - const char *restore_portal_session_str = args["-restore-portal-session"].value(); - if(!restore_portal_session_str) - restore_portal_session_str = "no"; - - if(strcmp(restore_portal_session_str, "yes") == 0) { - restore_portal_session = true; - } else if(strcmp(restore_portal_session_str, "no") == 0) { - restore_portal_session = false; - } else { - fprintf(stderr, "Error: -restore-portal-session should either be either 'yes' or 'no', got: '%s'\n", restore_portal_session_str); - usage(); - } + bool overclock = arg_get_boolean_value(args, "-oc", false); + const bool verbose = arg_get_boolean_value(args, "-v", true); + const bool gl_debug = arg_get_boolean_value(args, "-gl-debug", false); + const bool record_cursor = arg_get_boolean_value(args, "-cursor", true); + const bool date_folders = arg_get_boolean_value(args, "-df", false); + const bool restore_portal_session = arg_get_boolean_value(args, "-restore-portal-session", false); + const bool restart_replay_on_save = arg_get_boolean_value(args, "-restart-replay-on-save", false); const char *portal_session_token_filepath = args["-portal-session-token-filepath"].value(); if(portal_session_token_filepath) { @@ -3389,27 +3459,13 @@ const char *replay_buffer_size_secs_str = args["-r"].value(); if(replay_buffer_size_secs_str) { replay_buffer_size_secs = atoi(replay_buffer_size_secs_str); - if(replay_buffer_size_secs < 5 || replay_buffer_size_secs > 1200) { - fprintf(stderr, "Error: option -r has to be between 5 and 1200, was: %s\n", replay_buffer_size_secs_str); + if(replay_buffer_size_secs < 2 || replay_buffer_size_secs > 10800) { + fprintf(stderr, "Error: option -r has to be between 2 and 10800, was: %s\n", replay_buffer_size_secs_str); _exit(1); } replay_buffer_size_secs += std::ceil(keyint); // Add a few seconds to account of lost packets because of non-keyframe packets skipped } - bool restart_replay_on_save = false; - const char *restart_replay_on_save_str = args["-restart-replay-on-save"].value(); - if(!restart_replay_on_save_str) - restart_replay_on_save_str = "no"; - - if(strcmp(restart_replay_on_save_str, "yes") == 0) { - restart_replay_on_save = true; - } else if(strcmp(restart_replay_on_save_str, "no") == 0) { - restart_replay_on_save = false; - } else { - fprintf(stderr, "Error: -restart-replay-on-save should either be either 'yes' or 'no', got: '%s'\n", restart_replay_on_save_str); - usage(); - } - std::string window_str = args["-w"].value(); const bool is_portal_capture = strcmp(window_str.c_str(), "portal") == 0; @@ -3454,6 +3510,11 @@ _exit(1); } + if(video_codec_is_hdr(video_codec) && is_portal_capture) { + fprintf(stderr, "Warning: portal capture option doesn't support hdr yet (PipeWire doesn't support hdr), the video will be tonemapped from hdr to sdr\n"); + video_codec = hdr_video_codec_to_sdr_video_codec(video_codec); + } + const bool is_monitor_capture = strcmp(window_str.c_str(), "focused") != 0 && !is_portal_capture && contains_non_hex_number(window_str.c_str()); gsr_egl egl; if(!gsr_egl_load(&egl, window, is_monitor_capture, gl_debug)) { @@ -3673,6 +3734,12 @@ const bool is_output_piped = strcmp(filename, "/dev/stdout") == 0; + set_video_codec_for_image_output(filename, &video_codec, &video_codec_to_use); + if(video_codec_is_image(video_codec) && !audio_input_arg.values.empty()) { + fprintf(stderr, "Error: can't record audio (-a) when taking a screenshot\n"); + _exit(1); + } + AVFormatContext *av_format_context; // The output format is automatically guessed by the file extension avformat_alloc_output_context2(&av_format_context, nullptr, container_format, filename); @@ -3698,18 +3765,14 @@ const bool force_no_audio_offset = is_livestream || is_output_piped || (file_extension != "mp4" && file_extension != "mkv" && file_extension != "webm"); const double target_fps = 1.0 / (double)fps; - if(video_codec_is_hdr(video_codec) && is_portal_capture) { - fprintf(stderr, "Warning: portal capture option doesn't support hdr yet (PipeWire doesn't support hdr), the video will be tonemapped from hdr to sdr\n"); - video_codec = hdr_video_codec_to_sdr_video_codec(video_codec); - } - const bool uses_amix = merged_audio_inputs_should_use_amix(requested_audio_inputs); - audio_codec = select_audio_codec_with_fallback(audio_codec, file_extension, uses_amix); + if(!video_codec_is_image(video_codec)) + audio_codec = select_audio_codec_with_fallback(audio_codec, file_extension, uses_amix); bool low_power = false; const AVCodec *video_codec_f = select_video_codec_with_fallback(&video_codec, video_codec_to_use, file_extension.c_str(), use_software_video_encoder, &egl, &low_power); const gsr_color_depth color_depth = video_codec_to_bit_depth(video_codec); - gsr_capture *capture = create_capture_impl(window_str, output_resolution, wayland, &egl, fps, video_codec, color_range, record_cursor, use_software_video_encoder, restore_portal_session, portal_session_token_filepath, color_depth); + gsr_capture *capture = create_capture_impl(window_str, output_resolution, wayland, &egl, fps, video_codec, color_range, record_cursor, restore_portal_session, portal_session_token_filepath, color_depth); // (Some?) livestreaming services require at least one audio track to work. // If not audio is provided then create one silent audio track. @@ -3781,7 +3844,9 @@ gsr_color_conversion_clear(&color_conversion); - if(use_software_video_encoder) { + if(video_codec_is_image(video_codec)) { + open_video_image(video_codec_context); + } else if(use_software_video_encoder) { open_video_software(video_codec_context, quality, pixel_format, hdr, color_depth, bitrate_mode); } else { open_video_hardware(video_codec_context, quality, very_old_gpu, egl.gpu_info.vendor, pixel_format, hdr, color_depth, bitrate_mode, video_codec, low_power); @@ -3871,6 +3936,8 @@ if(replay_buffer_size_secs == -1) { AVDictionary *options = nullptr; av_dict_set(&options, "strict", "experimental", 0); + if(video_codec_is_image(video_codec)) + av_dict_set(&options, "update", "true", 0); //av_dict_set_int(&av_format_context->metadata, "video_full_range_flag", 1, 0); int ret = avformat_write_header(av_format_context, &options); @@ -4120,6 +4187,7 @@ double last_capture_seconds = record_start_time; bool wait_until_frame_time_elapsed = false; + const bool is_image_output = video_codec_is_image(video_codec); while(running) { const double frame_start = clock_get_monotonic_seconds(); @@ -4227,6 +4295,10 @@ // TODO: Move to separate thread because this could write to network (for example when livestreaming) receive_frames(video_codec_context, VIDEO_STREAM_INDEX, video_stream, video_frame->pts, av_format_context, replay_start_time, frame_data_queue, replay_buffer_size_secs, frames_erased, write_output_mutex, paused_time_offset); + if(is_image_output) { + running = 0; + break; + } } else { fprintf(stderr, "Error: avcodec_send_frame failed, error: %s\n", av_error_to_string(ret)); } @@ -4258,16 +4330,18 @@ std::lock_guard<std::mutex> lock(write_output_mutex); save_replay_packets.clear(); - if(restart_replay_on_save) { - frame_data_queue.clear(); - frames_erased = true; - replay_start_time = clock_get_monotonic_seconds() - paused_time_offset; - } } if(save_replay == 1 && !save_replay_thread.valid() && replay_buffer_size_secs != -1) { save_replay = 0; save_replay_async(video_codec_context, VIDEO_STREAM_INDEX, audio_tracks, frame_data_queue, frames_erased, filename, container_format, file_extension, write_output_mutex, date_folders, hdr, capture); + + std::lock_guard<std::mutex> lock(write_output_mutex); + if(restart_replay_on_save) { + frame_data_queue.clear(); + frames_erased = true; + replay_start_time = clock_get_monotonic_seconds() - paused_time_offset; + } } const double frame_end = clock_get_monotonic_seconds(); @@ -4322,8 +4396,10 @@ fprintf(stderr, "Failed to write trailer\n"); } - if(replay_buffer_size_secs == -1 && !(output_format->flags & AVFMT_NOFILE)) + if(replay_buffer_size_secs == -1 && !(output_format->flags & AVFMT_NOFILE)) { avio_close(av_format_context->pb); + avformat_free_context(av_format_context); + } gsr_damage_deinit(&damage); gsr_color_conversion_deinit(&color_conversion); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/src/pipewire_video.c new/gpu-screen-recorder-20250217/src/pipewire_video.c --- old/gpu-screen-recorder-20250125/src/pipewire_video.c 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/src/pipewire_video.c 2025-02-17 19:23:54.000000000 +0100 @@ -14,7 +14,7 @@ /* This code is partially based on xr-video-player pipewire implementation which is based on obs-studio's pipewire implementation */ /* TODO: Make gsr_pipewire_video_init asynchronous */ -/* TODO: Support 10-bit capture (hdr) when pipewire supports it */ +/* TODO: Support hdr when pipewire supports it */ /* TODO: Test all of the image formats */ #ifndef SPA_POD_PROP_FLAG_DONT_FIXATE @@ -65,14 +65,20 @@ static bool is_cursor_format_supported(const enum spa_video_format format) { switch(format) { - case SPA_VIDEO_FORMAT_RGBx: return true; - case SPA_VIDEO_FORMAT_BGRx: return true; - case SPA_VIDEO_FORMAT_xRGB: return true; - case SPA_VIDEO_FORMAT_xBGR: return true; - case SPA_VIDEO_FORMAT_RGBA: return true; - case SPA_VIDEO_FORMAT_BGRA: return true; - case SPA_VIDEO_FORMAT_ARGB: return true; - case SPA_VIDEO_FORMAT_ABGR: return true; + case SPA_VIDEO_FORMAT_RGBx: return true; + case SPA_VIDEO_FORMAT_BGRx: return true; + case SPA_VIDEO_FORMAT_RGBA: return true; + case SPA_VIDEO_FORMAT_BGRA: return true; + case SPA_VIDEO_FORMAT_RGB: return true; + case SPA_VIDEO_FORMAT_BGR: return true; + case SPA_VIDEO_FORMAT_ARGB: return true; + case SPA_VIDEO_FORMAT_ABGR: return true; +#if PW_CHECK_VERSION(0, 3, 41) + case SPA_VIDEO_FORMAT_xRGB_210LE: return true; + case SPA_VIDEO_FORMAT_xBGR_210LE: return true; + case SPA_VIDEO_FORMAT_ARGB_210LE: return true; + case SPA_VIDEO_FORMAT_ABGR_210LE: return true; +#endif default: break; } return false; @@ -338,24 +344,46 @@ /* For some reason gstreamer formats are in opposite order to drm formats */ static int64_t spa_video_format_to_drm_format(const enum spa_video_format format) { switch(format) { - case SPA_VIDEO_FORMAT_RGBx: return DRM_FORMAT_XBGR8888; - case SPA_VIDEO_FORMAT_BGRx: return DRM_FORMAT_XRGB8888; - case SPA_VIDEO_FORMAT_RGBA: return DRM_FORMAT_ABGR8888; - case SPA_VIDEO_FORMAT_BGRA: return DRM_FORMAT_ARGB8888; - case SPA_VIDEO_FORMAT_RGB: return DRM_FORMAT_XBGR8888; - case SPA_VIDEO_FORMAT_BGR: return DRM_FORMAT_XRGB8888; + case SPA_VIDEO_FORMAT_RGBx: return DRM_FORMAT_XBGR8888; + case SPA_VIDEO_FORMAT_BGRx: return DRM_FORMAT_XRGB8888; + case SPA_VIDEO_FORMAT_RGBA: return DRM_FORMAT_ABGR8888; + case SPA_VIDEO_FORMAT_BGRA: return DRM_FORMAT_ARGB8888; + case SPA_VIDEO_FORMAT_RGB: return DRM_FORMAT_XBGR8888; + case SPA_VIDEO_FORMAT_BGR: return DRM_FORMAT_XRGB8888; + case SPA_VIDEO_FORMAT_ARGB: return DRM_FORMAT_XRGB8888; + case SPA_VIDEO_FORMAT_ABGR: return DRM_FORMAT_XRGB8888; +#if PW_CHECK_VERSION(0, 3, 41) + case SPA_VIDEO_FORMAT_xRGB_210LE: return DRM_FORMAT_XRGB2101010; + case SPA_VIDEO_FORMAT_xBGR_210LE: return DRM_FORMAT_XBGR2101010; + case SPA_VIDEO_FORMAT_ARGB_210LE: return DRM_FORMAT_ARGB2101010; + case SPA_VIDEO_FORMAT_ABGR_210LE: return DRM_FORMAT_ABGR2101010; +#endif default: break; } return DRM_FORMAT_INVALID; } -static const enum spa_video_format video_formats[] = { +#if PW_CHECK_VERSION(0, 3, 41) +#define GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS GSR_PIPEWIRE_VIDEO_MAX_VIDEO_FORMATS +#else +#define GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS 8 +#endif + +static const enum spa_video_format video_formats[GSR_PIPEWIRE_VIDEO_MAX_VIDEO_FORMATS] = { SPA_VIDEO_FORMAT_BGRA, SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_BGR, SPA_VIDEO_FORMAT_RGBx, SPA_VIDEO_FORMAT_RGBA, SPA_VIDEO_FORMAT_RGB, + SPA_VIDEO_FORMAT_ARGB, + SPA_VIDEO_FORMAT_ABGR, +#if PW_CHECK_VERSION(0, 3, 41) + SPA_VIDEO_FORMAT_xRGB_210LE, + SPA_VIDEO_FORMAT_xBGR_210LE, + SPA_VIDEO_FORMAT_ARGB_210LE, + SPA_VIDEO_FORMAT_ABGR_210LE +#endif }; static bool gsr_pipewire_video_build_format_params(gsr_pipewire_video *self, struct spa_pod_builder *pod_builder, struct spa_pod **params, uint32_t *num_params) { @@ -367,7 +395,7 @@ for(size_t i = 0; i < GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS; i++) { if(self->supported_video_formats[i].modifiers_size == 0) continue; - params[i] = build_format(pod_builder, &self->video_info, self->supported_video_formats[i].format, self->modifiers + self->supported_video_formats[i].modifiers_index, self->supported_video_formats[i].modifiers_size); + params[*num_params] = build_format(pod_builder, &self->video_info, self->supported_video_formats[i].format, self->modifiers + self->supported_video_formats[i].modifiers_index, self->supported_video_formats[i].modifiers_size); ++(*num_params); } @@ -382,7 +410,7 @@ struct spa_pod *params[GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS]; uint32_t num_video_formats = 0; - uint8_t params_buffer[2048]; + uint8_t params_buffer[4096]; struct spa_pod_builder pod_builder = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); if (!gsr_pipewire_video_build_format_params(self, &pod_builder, params, &num_video_formats)) { pw_thread_loop_unlock(self->thread_loop); @@ -413,6 +441,11 @@ } const int64_t drm_format = spa_video_format_to_drm_format(format); + if(drm_format == DRM_FORMAT_INVALID) { + fprintf(stderr, "gsr error: spa_video_format_get_modifiers: unsupported format: %d\n", (int)format); + return false; + } + if(!self->egl->eglQueryDmaBufModifiersEXT(self->egl->egl_display, drm_format, max_modifiers, modifiers, NULL, num_modifiers)) { fprintf(stderr, "gsr error: spa_video_format_get_modifiers: eglQueryDmaBufModifiersEXT failed with drm format %d, %" PRIi64 "\n", (int)format, drm_format); //modifiers[0] = DRM_FORMAT_MOD_LINEAR; @@ -443,7 +476,7 @@ static bool gsr_pipewire_video_setup_stream(gsr_pipewire_video *self) { struct spa_pod *params[GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS]; uint32_t num_video_formats = 0; - uint8_t params_buffer[2048]; + uint8_t params_buffer[4096]; struct spa_pod_builder pod_builder = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); self->thread_loop = pw_thread_loop_new("gsr screen capture", NULL); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gpu-screen-recorder-20250125/src/utils.c new/gpu-screen-recorder-20250217/src/utils.c --- old/gpu-screen-recorder-20250125/src/utils.c 2025-01-25 19:56:43.000000000 +0100 +++ new/gpu-screen-recorder-20250217/src/utils.c 2025-02-17 19:23:54.000000000 +0100 @@ -413,7 +413,7 @@ return supported; } -static bool version_greater_than(int major, int minor, int patch, int other_major, int other_minor, int other_patch) { +bool version_greater_than(int major, int minor, int patch, int other_major, int other_minor, int other_patch) { return (major > other_major) || (major == other_major && minor > other_minor) || (major == other_major && minor == other_minor && patch > other_patch); }