diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 572 |
1 files changed, 276 insertions, 296 deletions
diff --git a/src/main.cpp b/src/main.cpp index 81b325c..1375fa1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1067,7 +1067,8 @@ static void open_video_hardware(AVCodecContext *codec_context, VideoQuality vide static void usage_header() { const bool inside_flatpak = getenv("FLATPAK_ID") != NULL; const char *program_name = inside_flatpak ? "flatpak run --command=gpu-screen-recorder com.dec05eba.gpu_screen_recorder" : "gpu-screen-recorder"; - fprintf(stderr, "usage: %s -w <window_id|monitor|focused|portal> [-c <container_format>] [-s WxH] -f <fps> [-a <audio_input>] [-q <quality>] [-r <replay_buffer_size_sec>] [-k h264|hevc|av1|vp8|vp9|hevc_hdr|av1_hdr|hevc_10bit|av1_10bit] [-ac aac|opus|flac] [-ab <bitrate>] [-oc yes|no] [-fm cfr|vfr|content] [-bm auto|qp|vbr|cbr] [-cr limited|full] [-df yes|no] [-sc <script_path>] [-cursor yes|no] [-keyint <value>] [-restore-portal-session yes|no] [-portal-session-token-filepath filepath] [-encoder gpu|cpu] [-o <output_file>] [-v yes|no] [--version] [-h|--help]\n", program_name); + printf("usage: %s -w <window_id|monitor|focused|portal> [-c <container_format>] [-s WxH] -f <fps> [-a <audio_input>] [-q <quality>] [-r <replay_buffer_size_sec>] [-k h264|hevc|av1|vp8|vp9|hevc_hdr|av1_hdr|hevc_10bit|av1_10bit] [-ac aac|opus|flac] [-ab <bitrate>] [-oc yes|no] [-fm cfr|vfr|content] [-bm auto|qp|vbr|cbr] [-cr limited|full] [-df yes|no] [-sc <script_path>] [-cursor yes|no] [-keyint <value>] [-restore-portal-session yes|no] [-portal-session-token-filepath filepath] [-encoder gpu|cpu] [-o <output_file>] [-v yes|no] [--version] [-h|--help]\n", program_name); + fflush(stdout); } // TODO: Update with portal info @@ -1075,182 +1076,178 @@ static void usage_full() { const bool inside_flatpak = getenv("FLATPAK_ID") != NULL; const char *program_name = inside_flatpak ? "flatpak run --command=gpu-screen-recorder com.dec05eba.gpu_screen_recorder" : "gpu-screen-recorder"; usage_header(); - fprintf(stderr, "\n"); - fprintf(stderr, "OPTIONS:\n"); - fprintf(stderr, " -w Window id to record, a display (monitor name), \"screen\", \"screen-direct-force\", \"focused\" or \"portal\".\n"); - fprintf(stderr, " If this is \"portal\" then xdg desktop screencast portal with PipeWire will be used. Portal option is only available on Wayland.\n"); - fprintf(stderr, " If you select to save the session (token) in the desktop portal capture popup then the session will be saved for the next time you use \"portal\",\n"); - fprintf(stderr, " but the session will be ignored unless you run GPU Screen Recorder with the '-restore-portal-session yes' option.\n"); - fprintf(stderr, " If this is \"screen\" or \"screen-direct-force\" then all monitors are recorded on Nvidia X11.\n"); - fprintf(stderr, " On AMD/Intel or wayland \"screen\" will record the first monitor found.\n"); - fprintf(stderr, " \"screen-direct-force\" is not recommended unless you use a VRR (G-SYNC) monitor on Nvidia X11 and you are aware that using this option can cause\n"); - fprintf(stderr, " games to freeze/crash or other issues because of Nvidia driver issues.\n"); - fprintf(stderr, " \"screen-direct-force\" option is only available on Nvidia X11. VRR works without this option on other systems.\n"); - fprintf(stderr, " Run GPU Screen Recorder with the --list-capture-options option to list valid values for this option.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -c Container format for output file, for example mp4, or flv. Only required if no output file is specified or if recording in replay buffer mode.\n"); - fprintf(stderr, " If an output file is specified and -c is not used then the container format is determined from the output filename extension.\n"); - fprintf(stderr, " Only containers that support h264, hevc, av1, vp8 or vp9 are supported, which means that only mp4, mkv, flv, webm (and some others) are supported.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -s The output resolution limit of the video in the format WxH, for example 1920x1080. If this is 0x0 then the original resolution is used. Optional, except when -w is \"focused\".\n"); - fprintf(stderr, " Note: the captured content is scaled to this size. The output resolution might not be exactly as specified by this option. The original aspect ratio is respected so the resolution will match that.\n"); - fprintf(stderr, " The video encoder might also need to add padding, which will result in black bars on the sides of the video. This is especially an issue on AMD.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -f Frame rate to record at. Recording will only capture frames at this target frame rate.\n"); - fprintf(stderr, " For constant frame rate mode this option is the frame rate every frame will be captured at and if the capture frame rate is below this target frame rate then the frames will be duplicated.\n"); - fprintf(stderr, " For variable frame rate mode this option is the max frame rate and if the capture frame rate is below this target frame rate then frames will not be duplicated.\n"); - fprintf(stderr, " Content frame rate is similar to variable frame rate mode, except the frame rate will match the frame rate of the captured content when possible, but not capturing above the frame rate set in this -f option.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -a Audio device or application to record from (pulse audio device). Can be specified multiple times. Each time this is specified a new audio track is added for the specified audio device or application.\n"); - fprintf(stderr, " A name can be given to the audio input device by prefixing the audio input with <name>/, for example \"dummy/alsa_output.pci-0000_00_1b.0.analog-stereo.monitor\".\n"); - fprintf(stderr, " Multiple audio sources can be merged into one audio track by using \"|\" as a separator into one -a argument, for example: -a \"alsa_output1|alsa_output2\".\n"); - fprintf(stderr, " The audio device can also be \"default_output\" in which case the default output device is used, or \"default_input\" in which case the default input device is used.\n"); - fprintf(stderr, " The audio name can also be prefixed with \"device:\", for example: -a \"device:alsa_output.pci-0000_00_1b.0.analog-stereo.monitor\".\n"); -#ifdef GSR_APP_AUDIO - fprintf(stderr, " To record audio from an application then prefix the audio name with \"app:\", for example: -a \"app:Brave\".\n"); - fprintf(stderr, " To record audio from all applications except the provided use prefix the audio name with \"app-inverse:\", for example: -a \"app-inverse:Brave\".\n"); - fprintf(stderr, " \"app:\" and \"app-inverse:\" can't be mixed in one audio track.\n"); - fprintf(stderr, " One audio track can contain both audio devices and application audio, for example: -a \"default_output|device:alsa_output.pci-0000_00_1b.0.analog-stereo.monitor|app:Brave\".\n"); - fprintf(stderr, " Recording application audio is only possible when the sound server on the system is PipeWire.\n"); -#endif - fprintf(stderr, " If the audio name is an empty string then the argument is ignored.\n"); - fprintf(stderr, " Optional, no audio track is added by default.\n"); - fprintf(stderr, " Run GPU Screen Recorder with the --list-audio-devices option to list valid audio device names.\n"); - fprintf(stderr, " Run GPU Screen Recorder with the --list-application-audio option to list valid application names. It's possible to use an application name that is not listed in --list-application-audio,\n"); - fprintf(stderr, " for example when trying to record audio from an application that hasn't started yet.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -q Video quality. Should be either 'medium', 'high', 'very_high' or 'ultra' when using '-bm qp' or '-bm vbr' options, and '-bm qp' is the default option used.\n"); - fprintf(stderr, " 'high' is the recommended option when live streaming or when you have a slower harddrive.\n"); - fprintf(stderr, " When using '-bm cbr' option then this is option is instead used to specify the video bitrate in kbps.\n"); - fprintf(stderr, " Optional when using '-bm qp' or '-bm vbr' options, set to 'very_high' be default.\n"); - fprintf(stderr, " Required when using '-bm cbr' option.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -r Replay buffer size in seconds. If this is set, then only the last seconds as set by this option will be stored\n"); - fprintf(stderr, " and the video will only be saved when the gpu-screen-recorder is closed. This feature is similar to Nvidia's instant replay feature.\n"); - fprintf(stderr, " This option has be between 5 and 1200. Note that the replay buffer size will not always be precise, because of keyframes. Optional, disabled by default.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -k Video codec to use. Should be either 'auto', 'h264', 'hevc', 'av1', 'vp8', 'vp9', 'hevc_hdr', 'av1_hdr', 'hevc_10bit' or 'av1_10bit'.\n"); - fprintf(stderr, " Optional, set to 'auto' by default which defaults to 'h264'. Forcefully set to 'h264' if the file container type is 'flv'.\n"); - fprintf(stderr, " 'hevc_hdr' and 'av1_hdr' option is not available on X11 nor when using the portal capture option.\n"); - fprintf(stderr, " 'hevc_10bit' and 'av1_10bit' options allow you to select 10 bit color depth which can reduce banding and improve quality in darker areas, but not all video players support 10 bit color depth\n"); - fprintf(stderr, " and if you upload the video to a website the website might reduce 10 bit to 8 bit.\n"); - fprintf(stderr, " Note that when using 'hevc_hdr' or 'av1_hdr' the color depth is also 10 bits.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -ac Audio codec to use. Should be either 'aac', 'opus' or 'flac'. Optional, set to 'opus' for .mp4/.mkv files, otherwise set to 'aac'.\n"); - fprintf(stderr, " 'opus' and 'flac' is only supported by .mp4/.mkv files. 'opus' is recommended for best performance and smallest audio size.\n"); - fprintf(stderr, " Flac audio codec is option is disable at the moment because of a temporary issue.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -ab Audio bitrate in kbps. If this is set to 0 then it's the same as if it's absent, in which case the bitrate is determined automatically depending on the audio codec.\n"); - fprintf(stderr, " Optional, by default the bitrate is 128kbps for opus and flac and 160kbps for aac.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -oc Overclock memory transfer rate to the maximum performance level. This only applies to NVIDIA on X11 and exists to overcome a bug in NVIDIA driver where performance level\n"); - fprintf(stderr, " is dropped when you record a game. Only needed if you are recording a game that is bottlenecked by GPU. The same issue exists on Wayland but overclocking is not possible on Wayland.\n"); - fprintf(stderr, " Works only if your have \"Coolbits\" set to \"12\" in NVIDIA X settings, see README for more information. Note! use at your own risk! Optional, disabled by default.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -fm Framerate mode. Should be either 'cfr' (constant frame rate), 'vfr' (variable frame rate) or 'content'. Optional, set to 'vfr' by default.\n"); - fprintf(stderr, " 'vfr' is recommended for recording for less issue with very high system load but some applications such as video editors may not support it properly.\n"); - fprintf(stderr, " 'content' is currently only supported on X11 or when using portal capture option. The 'content' option matches the recording frame rate to the captured content.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -bm Bitrate mode. Should be either 'auto', 'qp' (constant quality), 'vbr' (variable bitrate) or 'cbr' (constant bitrate). Optional, set to 'auto' by default which defaults to 'qp' on all devices\n"); - fprintf(stderr, " except steam deck that has broken drivers and doesn't support qp.\n"); - fprintf(stderr, " Note: 'vbr' option is not supported when using '-encoder cpu' option.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -cr Color range. Should be either 'limited' (aka mpeg) or 'full' (aka jpeg). Optional, set to 'limited' by default.\n"); - fprintf(stderr, " Limited color range means that colors are in range 16-235 (4112-60395 for hdr) while full color range means that colors are in range 0-255 (0-65535 for hdr).\n"); - fprintf(stderr, " Note that some buggy video players (such as vlc) are unable to correctly display videos in full color range and when upload the video to websites the website\n"); - fprintf(stderr, " might re-encoder the video to make the video limited color range.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -df Organise replays in folders based on the current date.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -sc Run a script on the saved video file (asynchronously). The first argument to the script is the filepath to the saved video file and the second argument is the recording type (either \"regular\" or \"replay\").\n"); - fprintf(stderr, " Not applicable for live streams.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -cursor\n"); - fprintf(stderr, " Record cursor. Optional, set to 'yes' by default.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -keyint\n"); - fprintf(stderr, " Specifies the keyframe interval in seconds, the max amount of time to wait to generate a keyframe. Keyframes can be generated more often than this.\n"); - fprintf(stderr, " This also affects seeking in the video and may affect how the replay video is cut. If this is set to 10 for example then you can only seek in 10-second chunks in the video.\n"); - fprintf(stderr, " Setting this to a higher value reduces the video file size if you are ok with the previously described downside. This option is expected to be a floating point number.\n"); - fprintf(stderr, " By default this value is set to 2.0.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -restore-portal-session\n"); - fprintf(stderr, " If GPU Screen Recorder should use the same capture option as the last time. Using this option removes the popup asking what you want to record the next time you record with '-w portal' if you selected the option to save session (token) in the desktop portal screencast popup.\n"); - fprintf(stderr, " This option may not have any effect on your Wayland compositor and your systems desktop portal needs to support ScreenCast version 5 or later. Optional, set to 'no' by default.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -portal-session-token-filepath\n"); - fprintf(stderr, " This option is used together with -restore-portal-session option to specify the file path to save/restore the portal session token to/from.\n"); - fprintf(stderr, " This can be used to remember different portal capture options depending on different recording option (such as recording/replay).\n"); - fprintf(stderr, " Optional, set to \"$XDG_CONFIG_HOME/gpu-screen-recorder/restore_token\" by default ($XDG_CONFIG_HOME defaults to \"$HOME/.config\").\n"); - fprintf(stderr, " Note: the directory to the portal session token file is created automatically if it doesn't exist.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -encoder\n"); - fprintf(stderr, " Which device should be used for video encoding. Should either be 'gpu' or 'cpu'. 'cpu' option currently only work with h264 codec option (-k).\n"); - fprintf(stderr, " Optional, set to 'gpu' by default.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " --info\n"); - fprintf(stderr, " List info about the system. Lists the following information (prints them to stdout and exits):\n"); - fprintf(stderr, " Supported video codecs (h264, h264_software, hevc, hevc_hdr, hevc_10bit, av1, av1_hdr, av1_10bit, vp8, vp9 (if supported)).\n"); - fprintf(stderr, " Supported capture options (window, focused, screen, monitors and portal, if supported by the system).\n"); - fprintf(stderr, " 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"); - fprintf(stderr, "\n"); - fprintf(stderr, " --list-capture-options\n"); - fprintf(stderr, " List available capture options. Lists capture options in the following format (prints them to stdout and exits):\n"); - fprintf(stderr, " <option>\n"); - fprintf(stderr, " <monitor_name>|<resolution>\n"); - fprintf(stderr, " For example:\n"); - fprintf(stderr, " window\n"); - fprintf(stderr, " DP-1|1920x1080\n"); - fprintf(stderr, " The <option> and <monitor_name> is the name that can be passed to GPU Screen Recorder with the -w option.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " --list-audio-devices\n"); - fprintf(stderr, " List audio devices. Lists audio devices in the following format (prints them to stdout and exits):\n"); - fprintf(stderr, " <audio_device_name>|<audio_device_name_in_human_readable_format>\n"); - fprintf(stderr, " For example:\n"); - fprintf(stderr, " bluez_input.88:C9:E8:66:A2:27|WH-1000XM4\n"); - fprintf(stderr, " alsa_output.pci-0000_0c_00.4.iec958-stereo|Monitor of Starship/Matisse HD Audio Controller Digital Stereo (IEC958)\n"); - fprintf(stderr, " The <audio_device_name> is the name that can be passed to GPU Screen Recorder with the -a option.\n"); - fprintf(stderr, "\n"); -#ifdef GSR_APP_AUDIO - fprintf(stderr, " --list-application-audio\n"); - fprintf(stderr, " Lists application that you can record from (with the -aa or -aai option) (prints them to stdout and exits), for example:\n"); - fprintf(stderr, " firefox\n"); - fprintf(stderr, " csgo\n"); - fprintf(stderr, " These names are the application audio names that can be passed to GPU Screen Recorder with the -aa option.\n"); - fprintf(stderr, "\n"); -#endif - fprintf(stderr, " --version\n"); - fprintf(stderr, " Print version (%s) and exit\n", GSR_VERSION); - fprintf(stderr, "\n"); + printf("\n"); + printf("OPTIONS:\n"); + printf(" -w Window id to record, a display (monitor name), \"screen\", \"screen-direct-force\", \"focused\" or \"portal\".\n"); + printf(" If this is \"portal\" then xdg desktop screencast portal with PipeWire will be used. Portal option is only available on Wayland.\n"); + printf(" If you select to save the session (token) in the desktop portal capture popup then the session will be saved for the next time you use \"portal\",\n"); + printf(" but the session will be ignored unless you run GPU Screen Recorder with the '-restore-portal-session yes' option.\n"); + printf(" If this is \"screen\" or \"screen-direct-force\" then all monitors are recorded on Nvidia X11.\n"); + printf(" On AMD/Intel or wayland \"screen\" will record the first monitor found.\n"); + printf(" \"screen-direct-force\" is not recommended unless you use a VRR (G-SYNC) monitor on Nvidia X11 and you are aware that using this option can cause\n"); + printf(" games to freeze/crash or other issues because of Nvidia driver issues.\n"); + printf(" \"screen-direct-force\" option is only available on Nvidia X11. VRR works without this option on other systems.\n"); + printf(" Run GPU Screen Recorder with the --list-capture-options option to list valid values for this option.\n"); + printf("\n"); + printf(" -c Container format for output file, for example mp4, or flv. Only required if no output file is specified or if recording in replay buffer mode.\n"); + printf(" If an output file is specified and -c is not used then the container format is determined from the output filename extension.\n"); + printf(" Only containers that support h264, hevc, av1, vp8 or vp9 are supported, which means that only mp4, mkv, flv, webm (and some others) are supported.\n"); + printf("\n"); + printf(" -s The output resolution limit of the video in the format WxH, for example 1920x1080. If this is 0x0 then the original resolution is used. Optional, except when -w is \"focused\".\n"); + printf(" Note: the captured content is scaled to this size. The output resolution might not be exactly as specified by this option. The original aspect ratio is respected so the resolution will match that.\n"); + printf(" The video encoder might also need to add padding, which will result in black bars on the sides of the video. This is especially an issue on AMD.\n"); + printf("\n"); + printf(" -f Frame rate to record at. Recording will only capture frames at this target frame rate.\n"); + printf(" For constant frame rate mode this option is the frame rate every frame will be captured at and if the capture frame rate is below this target frame rate then the frames will be duplicated.\n"); + printf(" For variable frame rate mode this option is the max frame rate and if the capture frame rate is below this target frame rate then frames will not be duplicated.\n"); + printf(" Content frame rate is similar to variable frame rate mode, except the frame rate will match the frame rate of the captured content when possible, but not capturing above the frame rate set in this -f option.\n"); + printf("\n"); + printf(" -a Audio device or application to record from (pulse audio device). Can be specified multiple times. Each time this is specified a new audio track is added for the specified audio device or application.\n"); + printf(" The audio device can also be \"default_output\" in which case the default output device is used, or \"default_input\" in which case the default input device is used.\n"); + printf(" Multiple audio sources can be merged into one audio track by using \"|\" as a separator into one -a argument, for example: -a \"default_output|default_input\".\n"); + printf(" A name can be given to the audio track by prefixing the audio with <name>/, for example \"track name/default_output\" or \"track name/default_output|default_input\".\n"); + printf(" The audio name can also be prefixed with \"device:\", for example: -a \"device:default_output\".\n"); + printf(" To record audio from an application then prefix the audio name with \"app:\", for example: -a \"app:Brave\".\n"); + printf(" To record audio from all applications except the provided use prefix the audio name with \"app-inverse:\", for example: -a \"app-inverse:Brave\".\n"); + printf(" \"app:\" and \"app-inverse:\" can't be mixed in one audio track.\n"); + printf(" One audio track can contain both audio devices and application audio, for example: -a \"default_output|device:alsa_output.pci-0000_00_1b.0.analog-stereo.monitor|app:Brave\".\n"); + printf(" Recording application audio is only possible when the sound server on the system is PipeWire.\n"); + printf(" If the audio name is an empty string then the argument is ignored.\n"); + printf(" Optional, no audio track is added by default.\n"); + printf(" Run GPU Screen Recorder with the --list-audio-devices option to list valid audio device names.\n"); + printf(" Run GPU Screen Recorder with the --list-application-audio option to list valid application names. It's possible to use an application name that is not listed in --list-application-audio,\n"); + printf(" for example when trying to record audio from an application that hasn't started yet.\n"); + printf("\n"); + printf(" -q Video quality. Should be either 'medium', 'high', 'very_high' or 'ultra' when using '-bm qp' or '-bm vbr' options, and '-bm qp' is the default option used.\n"); + printf(" 'high' is the recommended option when live streaming or when you have a slower harddrive.\n"); + printf(" When using '-bm cbr' option then this is option is instead used to specify the video bitrate in kbps.\n"); + printf(" Optional when using '-bm qp' or '-bm vbr' options, set to 'very_high' be default.\n"); + printf(" Required when using '-bm cbr' option.\n"); + printf("\n"); + printf(" -r Replay buffer time in seconds. If this is set, then only the last seconds as set by this option will be stored\n"); + printf(" and the video will only be saved when the gpu-screen-recorder is closed. This feature is similar to Nvidia's instant replay feature This option has be between 5 and 1200.\n"); + printf(" Note that the video data is stored in RAM, so don't use too long replay buffer time and use constant bitrate option (-bm cbr) to prevent RAM usage from going too high in busy scenes.\n"); + printf(" Optional, disabled by default.\n"); + printf("\n"); + printf(" -k Video codec to use. Should be either 'auto', 'h264', 'hevc', 'av1', 'vp8', 'vp9', 'hevc_hdr', 'av1_hdr', 'hevc_10bit' or 'av1_10bit'.\n"); + printf(" Optional, set to 'auto' by default which defaults to 'h264'. Forcefully set to 'h264' if the file container type is 'flv'.\n"); + printf(" 'hevc_hdr' and 'av1_hdr' option is not available on X11 nor when using the portal capture option.\n"); + printf(" 'hevc_10bit' and 'av1_10bit' options allow you to select 10 bit color depth which can reduce banding and improve quality in darker areas, but not all video players support 10 bit color depth\n"); + printf(" and if you upload the video to a website the website might reduce 10 bit to 8 bit.\n"); + printf(" Note that when using 'hevc_hdr' or 'av1_hdr' the color depth is also 10 bits.\n"); + printf("\n"); + printf(" -ac Audio codec to use. Should be either 'aac', 'opus' or 'flac'. Optional, set to 'opus' for .mp4/.mkv files, otherwise set to 'aac'.\n"); + printf(" 'opus' and 'flac' is only supported by .mp4/.mkv files. 'opus' is recommended for best performance and smallest audio size.\n"); + printf(" Flac audio codec is option is disable at the moment because of a temporary issue.\n"); + printf("\n"); + printf(" -ab Audio bitrate in kbps. If this is set to 0 then it's the same as if it's absent, in which case the bitrate is determined automatically depending on the audio codec.\n"); + printf(" Optional, by default the bitrate is 128kbps for opus and flac and 160kbps for aac.\n"); + printf("\n"); + printf(" -oc Overclock memory transfer rate to the maximum performance level. This only applies to NVIDIA on X11 and exists to overcome a bug in NVIDIA driver where performance level\n"); + printf(" is dropped when you record a game. Only needed if you are recording a game that is bottlenecked by GPU. The same issue exists on Wayland but overclocking is not possible on Wayland.\n"); + printf(" Works only if your have \"Coolbits\" set to \"12\" in NVIDIA X settings, see README for more information. Note! use at your own risk! Optional, disabled by default.\n"); + printf("\n"); + printf(" -fm Framerate mode. Should be either 'cfr' (constant frame rate), 'vfr' (variable frame rate) or 'content'. Optional, set to 'vfr' by default.\n"); + printf(" 'vfr' is recommended for recording for less issue with very high system load but some applications such as video editors may not support it properly.\n"); + printf(" 'content' is currently only supported on X11 or when using portal capture option. The 'content' option matches the recording frame rate to the captured content.\n"); + printf("\n"); + printf(" -bm Bitrate mode. Should be either 'auto', 'qp' (constant quality), 'vbr' (variable bitrate) or 'cbr' (constant bitrate). Optional, set to 'auto' by default which defaults to 'qp' on all devices\n"); + printf(" except steam deck that has broken drivers and doesn't support qp.\n"); + printf(" Note: 'vbr' option is not supported when using '-encoder cpu' option.\n"); + printf("\n"); + printf(" -cr Color range. Should be either 'limited' (aka mpeg) or 'full' (aka jpeg). Optional, set to 'limited' by default.\n"); + printf(" Limited color range means that colors are in range 16-235 (4112-60395 for hdr) while full color range means that colors are in range 0-255 (0-65535 for hdr).\n"); + printf(" Note that some buggy video players (such as vlc) are unable to correctly display videos in full color range and when upload the video to websites the website\n"); + printf(" might re-encoder the video to make the video limited color range.\n"); + printf("\n"); + printf(" -df Organise replays in folders based on the current date.\n"); + printf("\n"); + printf(" -sc Run a script on the saved video file (asynchronously). The first argument to the script is the filepath to the saved video file and the second argument is the recording type (either \"regular\" or \"replay\").\n"); + printf(" Not applicable for live streams.\n"); + printf("\n"); + printf(" -cursor\n"); + printf(" Record cursor. Optional, set to 'yes' by default.\n"); + printf("\n"); + printf(" -keyint\n"); + printf(" Specifies the keyframe interval in seconds, the max amount of time to wait to generate a keyframe. Keyframes can be generated more often than this.\n"); + printf(" This also affects seeking in the video and may affect how the replay video is cut. If this is set to 10 for example then you can only seek in 10-second chunks in the video.\n"); + printf(" Setting this to a higher value reduces the video file size if you are ok with the previously described downside. This option is expected to be a floating point number.\n"); + printf(" By default this value is set to 2.0.\n"); + printf("\n"); + printf(" -restore-portal-session\n"); + printf(" If GPU Screen Recorder should use the same capture option as the last time. Using this option removes the popup asking what you want to record the next time you record with '-w portal' if you selected the option to save session (token) in the desktop portal screencast popup.\n"); + printf(" This option may not have any effect on your Wayland compositor and your systems desktop portal needs to support ScreenCast version 5 or later. Optional, set to 'no' by default.\n"); + printf("\n"); + printf(" -portal-session-token-filepath\n"); + printf(" This option is used together with -restore-portal-session option to specify the file path to save/restore the portal session token to/from.\n"); + printf(" This can be used to remember different portal capture options depending on different recording option (such as recording/replay).\n"); + printf(" Optional, set to \"$XDG_CONFIG_HOME/gpu-screen-recorder/restore_token\" by default ($XDG_CONFIG_HOME defaults to \"$HOME/.config\").\n"); + printf(" Note: the directory to the portal session token file is created automatically if it doesn't exist.\n"); + printf("\n"); + printf(" -encoder\n"); + printf(" Which device should be used for video encoding. Should either be 'gpu' or 'cpu'. 'cpu' option currently only work with h264 codec option (-k).\n"); + printf(" Optional, set to 'gpu' by default.\n"); + 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 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"); + printf(" --list-capture-options\n"); + printf(" List available capture options. Lists capture options in the following format (prints them to stdout and exits):\n"); + printf(" <option>\n"); + printf(" <monitor_name>|<resolution>\n"); + printf(" For example:\n"); + printf(" window\n"); + printf(" DP-1|1920x1080\n"); + printf(" The <option> and <monitor_name> is the name that can be passed to GPU Screen Recorder with the -w option.\n"); + printf("\n"); + printf(" --list-audio-devices\n"); + printf(" List audio devices. Lists audio devices in the following format (prints them to stdout and exits):\n"); + printf(" <audio_device_name>|<audio_device_name_in_human_readable_format>\n"); + printf(" For example:\n"); + printf(" bluez_input.88:C9:E8:66:A2:27|WH-1000XM4\n"); + printf(" alsa_output.pci-0000_0c_00.4.iec958-stereo|Monitor of Starship/Matisse HD Audio Controller Digital Stereo (IEC958)\n"); + printf(" The <audio_device_name> is the name that can be passed to GPU Screen Recorder with the -a option.\n"); + printf("\n"); + printf(" --list-application-audio\n"); + printf(" Lists application that you can record from (with the -aa or -aai option) (prints them to stdout and exits), for example:\n"); + printf(" firefox\n"); + printf(" csgo\n"); + printf(" These names are the application audio names that can be passed to GPU Screen Recorder with the -aa option.\n"); + printf("\n"); + printf(" --version\n"); + printf(" Print version (%s) and exit\n", GSR_VERSION); + printf("\n"); //fprintf(stderr, " -pixfmt The pixel format to use for the output video. yuv420 is the most common format and is best supported, but the color is compressed, so colors can look washed out and certain colors of text can look bad. Use yuv444 for no color compression, but the video may not work everywhere and it may not work with hardware video decoding. Optional, set to 'yuv420' by default\n"); - fprintf(stderr, " -o The output file path. If omitted then the encoded data is sent to stdout. Required in replay mode (when using -r).\n"); - fprintf(stderr, " In replay mode this has to be a directory instead of a file.\n"); - fprintf(stderr, " Note: the directory to the file is created automatically if it doesn't already exist.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -v Prints fps and damage info once per second. Optional, set to 'yes' by default.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " -h, --help\n"); - fprintf(stderr, " Show this help.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "NOTES:\n"); - fprintf(stderr, " Send signal SIGINT to gpu-screen-recorder (Ctrl+C, or killall -SIGINT gpu-screen-recorder) to stop and save the recording. When in replay mode this stops recording without saving.\n"); - fprintf(stderr, " Send signal SIGUSR1 to gpu-screen-recorder (killall -SIGUSR1 gpu-screen-recorder) to save a replay (when in replay mode).\n"); - fprintf(stderr, " Send signal SIGUSR2 to gpu-screen-recorder (killall -SIGUSR2 gpu-screen-recorder) to pause/unpause recording. Only applicable and useful when recording (not streaming nor replay).\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "EXAMPLES:\n"); - fprintf(stderr, " %s -w screen -f 60 -a default_output -o \"$HOME/Videos/video.mp4\"\n", program_name); - fprintf(stderr, " %s -w screen -f 60 -a default_output -a default_input -o \"$HOME/Videos/video.mp4\"\n", program_name); - fprintf(stderr, " %s -w screen -f 60 -a \"default_output|default_input\" -o \"$HOME/Videos/video.mp4\"\n", program_name); - fprintf(stderr, " %s -w screen -f 60 -a default_output -c mkv -r 60 -o \"$HOME/Videos\"\n", program_name); - fprintf(stderr, " %s -w screen -f 60 -a default_output -c mkv -sc script.sh -r 60 -o \"$HOME/Videos\"\n", program_name); - fprintf(stderr, " %s -w portal -f 60 -a default_output -restore-portal-session yes -o \"$HOME/Videos/video.mp4\"\n", program_name); - fprintf(stderr, " %s -w screen -f 60 -a default_output -bm cbr -q 15000 -o \"$HOME/Videos/video.mp4\"\n", program_name); -#ifdef GSR_APP_AUDIO - fprintf(stderr, " %s -w screen -f 60 -a \"app:firefox|app:csgo\" -o \"$HOME/Videos/video.mp4\"\n", program_name); - fprintf(stderr, " %s -w screen -f 60 -a \"app-inverse:firefox|app-inverse:csgo\" -o \"$HOME/Videos/video.mp4\"\n", program_name); - fprintf(stderr, " %s -w screen -f 60 -a \"default-input|app-inverse:Brave\" -o \"$HOME/Videos/video.mp4\"\n", program_name); -#endif + printf(" -o The output file path. If omitted then the encoded data is sent to stdout. Required in replay mode (when using -r).\n"); + printf(" In replay mode this has to be a directory instead of a file.\n"); + printf(" Note: the directory to the file is created automatically if it doesn't already exist.\n"); + printf("\n"); + printf(" -v Prints fps and damage info once per second. Optional, set to 'yes' by default.\n"); + printf("\n"); + printf(" -h, --help\n"); + printf(" Show this help.\n"); + printf("\n"); + printf("NOTES:\n"); + printf(" Send signal SIGINT to gpu-screen-recorder (Ctrl+C, or killall -SIGINT gpu-screen-recorder) to stop and save the recording. When in replay mode this stops recording without saving.\n"); + printf(" Send signal SIGUSR1 to gpu-screen-recorder (killall -SIGUSR1 gpu-screen-recorder) to save a replay (when in replay mode).\n"); + printf(" Send signal SIGUSR2 to gpu-screen-recorder (killall -SIGUSR2 gpu-screen-recorder) to pause/unpause recording. Only applicable and useful when recording (not streaming nor replay).\n"); + printf("\n"); + printf("EXAMPLES:\n"); + printf(" %s -w screen -f 60 -a default_output -o \"$HOME/Videos/video.mp4\"\n", program_name); + printf(" %s -w screen -f 60 -a default_output -a default_input -o \"$HOME/Videos/video.mp4\"\n", program_name); + printf(" %s -w screen -f 60 -a \"default_output|default_input\" -o \"$HOME/Videos/video.mp4\"\n", program_name); + printf(" %s -w screen -f 60 -a default_output -c mkv -r 60 -o \"$HOME/Videos\"\n", program_name); + printf(" %s -w screen -f 60 -a default_output -c mkv -sc script.sh -r 60 -o \"$HOME/Videos\"\n", program_name); + printf(" %s -w portal -f 60 -a default_output -restore-portal-session yes -o \"$HOME/Videos/video.mp4\"\n", program_name); + printf(" %s -w screen -f 60 -a default_output -bm cbr -q 15000 -o \"$HOME/Videos/video.mp4\"\n", program_name); + 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); //fprintf(stderr, " gpu-screen-recorder -w screen -f 60 -q ultra -pixfmt yuv444 -o video.mp4\n"); + fflush(stdout); _exit(1); } @@ -1400,7 +1397,7 @@ static double audio_codec_get_desired_delay(AudioCodec audio_codec, int fps) { return std::max(0.0, base - fps_inv); } -struct AudioDevice { +struct AudioDeviceData { SoundDevice sound_device; AudioInput audio_input; AVFilterContext *src_filter_ctx = nullptr; @@ -1411,10 +1408,11 @@ struct AudioDevice { // TODO: Cleanup struct AudioTrack { + std::string name; AVCodecContext *codec_context = nullptr; AVStream *stream = nullptr; - std::vector<AudioDevice> audio_devices; + std::vector<AudioDeviceData> audio_devices; AVFilterGraph *graph = nullptr; AVFilterContext *sink = nullptr; int stream_index = 0; @@ -1538,6 +1536,8 @@ static void save_replay_async(AVCodecContext *video_codec_context, int video_str for(AudioTrack &audio_track : audio_tracks) { stream_index_to_audio_track_map[audio_track.stream_index] = &audio_track; AVStream *audio_stream = create_stream(av_format_context, audio_track.codec_context); + if(!audio_track.name.empty()) + av_dict_set(&audio_stream->metadata, "title", audio_track.name.c_str(), 0); avcodec_parameters_from_context(audio_stream->codecpar, audio_track.codec_context); audio_track.stream = audio_stream; } @@ -1634,65 +1634,57 @@ static bool string_starts_with(const std::string &str, const char *substr) { return (int)str.size() >= len && memcmp(str.data(), substr, len) == 0; } -static const AudioInput* get_audio_device_by_name(const std::vector<AudioInput> &audio_inputs, const std::string &name) { - for(const auto &audio_input : audio_inputs) { - if(audio_input.name == name) - return &audio_input; +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) + return &audio_device; } return nullptr; } -static std::vector<AudioInput> parse_audio_input_arg(const char *str, const AudioDevices &audio_devices) { - std::vector<AudioInput> audio_inputs; +static MergedAudioInputs parse_audio_input_arg(const char *str, const AudioDevices &audio_devices) { + MergedAudioInputs result; + const bool name_is_existing_audio_device = get_audio_device_by_name(audio_devices.audio_inputs, str) != nullptr; + if(name_is_existing_audio_device) { + result.audio_inputs.push_back({str, AudioInputType::DEVICE, false}); + return result; + } + + const char *track_name_sep_ptr = strchr(str, '/'); + if(track_name_sep_ptr) { + result.track_name.assign(str, track_name_sep_ptr - str); + str = track_name_sep_ptr + 1; + } + split_string(str, '|', [&](const char *sub, size_t size) { AudioInput audio_input; audio_input.name.assign(sub, size); if(string_starts_with(audio_input.name.c_str(), "app:")) { audio_input.name.erase(audio_input.name.begin(), audio_input.name.begin() + 4); - audio_input.description = audio_input.name; audio_input.type = AudioInputType::APPLICATION; audio_input.inverted = false; - audio_inputs.push_back(std::move(audio_input)); + result.audio_inputs.push_back(std::move(audio_input)); return true; } else if(string_starts_with(audio_input.name.c_str(), "app-inverse:")) { audio_input.name.erase(audio_input.name.begin(), audio_input.name.begin() + 12); - audio_input.description = audio_input.name; audio_input.type = AudioInputType::APPLICATION; audio_input.inverted = true; - audio_inputs.push_back(std::move(audio_input)); + result.audio_inputs.push_back(std::move(audio_input)); return true; } else if(string_starts_with(audio_input.name.c_str(), "device:")) { audio_input.name.erase(audio_input.name.begin(), audio_input.name.begin() + 7); audio_input.type = AudioInputType::DEVICE; - audio_inputs.push_back(std::move(audio_input)); + result.audio_inputs.push_back(std::move(audio_input)); return true; } else { - const bool name_is_existing_audio_device = get_audio_device_by_name(audio_devices.audio_inputs, audio_input.name); - const size_t index = audio_input.name.find('/'); - if(!name_is_existing_audio_device && index != std::string::npos) { - audio_input.description = audio_input.name.substr(0, index); - audio_input.name.erase(audio_input.name.begin(), audio_input.name.begin() + index + 1); - } audio_input.type = AudioInputType::DEVICE; - audio_inputs.push_back(std::move(audio_input)); + result.audio_inputs.push_back(std::move(audio_input)); return true; } }); - return audio_inputs; -} -static std::vector<AudioInput> parse_app_audio_input_arg(const char *str) { - std::vector<AudioInput> audio_inputs; - split_string(str, '|', [&](const char *sub, size_t size) { - AudioInput audio_input; - audio_input.name.assign(sub, size); - audio_input.description = audio_input.name; - audio_input.type = AudioInputType::APPLICATION; - audio_inputs.push_back(std::move(audio_input)); - return true; - }); - return audio_inputs; + return result; } // TODO: Does this match all livestreaming cases? @@ -1916,11 +1908,13 @@ static void list_system_info(bool wayland) { bool supports_app_audio = false; #ifdef GSR_APP_AUDIO supports_app_audio = pulseaudio_server_is_pipewire(); - gsr_pipewire_audio audio; - if(gsr_pipewire_audio_init(&audio)) - gsr_pipewire_audio_deinit(&audio); - else - supports_app_audio = false; + if(supports_app_audio) { + gsr_pipewire_audio audio; + if(gsr_pipewire_audio_init(&audio)) + gsr_pipewire_audio_deinit(&audio); + else + supports_app_audio = false; + } #endif printf("supports_app_audio|%s\n", supports_app_audio ? "yes" : "no"); } @@ -2057,22 +2051,24 @@ static void output_monitor_info(const gsr_monitor *monitor, void *userdata) { } } -static void list_supported_capture_options(gsr_egl *egl, bool wayland) { +static void list_supported_capture_options(gsr_egl *egl, bool wayland, bool list_monitors) { if(!wayland) { puts("window"); puts("focused"); } - capture_options_callback options; - options.wayland = wayland; - options.egl = egl; - if(monitor_capture_use_drm(egl, wayland)) { - const bool is_x11 = gsr_egl_get_display_server(egl) == GSR_DISPLAY_SERVER_X11; - const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_DRM; - for_each_active_monitor_output(egl, connection_type, output_monitor_info, &options); - } else { - puts("screen"); // All monitors in one, only available on Nvidia X11 - for_each_active_monitor_output(egl, GSR_CONNECTION_X11, output_monitor_info, &options); + if(list_monitors) { + capture_options_callback options; + options.wayland = wayland; + options.egl = egl; + if(monitor_capture_use_drm(egl, wayland)) { + const bool is_x11 = gsr_egl_get_display_server(egl) == GSR_DISPLAY_SERVER_X11; + const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_DRM; + for_each_active_monitor_output(egl, connection_type, output_monitor_info, &options); + } else { + puts("screen"); // All monitors in one, only available on Nvidia X11 + for_each_active_monitor_output(egl, GSR_CONNECTION_X11, output_monitor_info, &options); + } } #ifdef GSR_PORTAL @@ -2121,12 +2117,13 @@ static void info_command() { _exit(22); } + bool list_monitors = true; egl.card_path[0] = '\0'; if(monitor_capture_use_drm(&egl, wayland)) { // TODO: Allow specifying another card, and in other places - if(!gsr_get_valid_card_path(&egl, egl.card_path, false)) { + if(!gsr_get_valid_card_path(&egl, egl.card_path, true)) { fprintf(stderr, "Error: no /dev/dri/cardX device found. Make sure that you have at least one monitor connected\n"); - _exit(23); + list_monitors = false; } } @@ -2143,7 +2140,7 @@ static void info_command() { puts("section=video_codecs"); list_supported_video_codecs(&egl, wayland); puts("section=capture_options"); - list_supported_capture_options(&egl, wayland); + list_supported_capture_options(&egl, wayland, list_monitors); fflush(stdout); @@ -2179,10 +2176,12 @@ static bool app_audio_query_callback(const char *app_name, void*) { static void list_application_audio_command() { #ifdef GSR_APP_AUDIO - gsr_pipewire_audio audio; - if(gsr_pipewire_audio_init(&audio)) { - gsr_pipewire_audio_for_each_app(&audio, app_audio_query_callback, NULL); - gsr_pipewire_audio_deinit(&audio); + if(pulseaudio_server_is_pipewire()) { + gsr_pipewire_audio audio; + if(gsr_pipewire_audio_init(&audio)) { + gsr_pipewire_audio_for_each_app(&audio, app_audio_query_callback, NULL); + gsr_pipewire_audio_deinit(&audio); + } } #endif @@ -2218,17 +2217,18 @@ static void list_capture_options_command() { _exit(1); } + bool list_monitors = true; egl.card_path[0] = '\0'; if(monitor_capture_use_drm(&egl, wayland)) { // TODO: Allow specifying another card, and in other places - if(!gsr_get_valid_card_path(&egl, egl.card_path, false)) { + if(!gsr_get_valid_card_path(&egl, egl.card_path, true)) { fprintf(stderr, "Error: no /dev/dri/cardX device found. Make sure that you have at least one monitor connected\n"); - _exit(23); + list_monitors = false; } } av_log_set_level(AV_LOG_FATAL); - list_supported_capture_options(&egl, wayland); + list_supported_capture_options(&egl, wayland, list_monitors); fflush(stdout); @@ -2448,43 +2448,42 @@ static void match_app_audio_input_to_available_apps(const std::vector<AudioInput // Manually check if the audio inputs we give exist. This is only needed for pipewire, not pulseaudio. // Pipewire instead DEFAULTS TO THE DEFAULT AUDIO INPUT. THAT'S RETARDED. // OH, YOU MISSPELLED THE AUDIO INPUT? FUCK YOU -static std::vector<MergedAudioInputs> parse_audio_inputs(const AudioDevices &audio_devices, const Arg &audio_input_arg, const Arg &app_audio_input_arg, const Arg &app_audio_input_inverted_arg) { +static std::vector<MergedAudioInputs> parse_audio_inputs(const AudioDevices &audio_devices, const Arg &audio_input_arg) { std::vector<MergedAudioInputs> requested_audio_inputs; for(const char *audio_input : audio_input_arg.values) { if(!audio_input || audio_input[0] == '\0') continue; - requested_audio_inputs.push_back({parse_audio_input_arg(audio_input, audio_devices)}); + requested_audio_inputs.push_back(parse_audio_input_arg(audio_input, audio_devices)); for(AudioInput &request_audio_input : requested_audio_inputs.back().audio_inputs) { if(request_audio_input.type != AudioInputType::DEVICE) continue; bool match = false; - if(!audio_devices.default_output.empty() && request_audio_input.name == "default_output") { + if(request_audio_input.name == "default_output") { + if(audio_devices.default_output.empty()) { + fprintf(stderr, "Error: -a default_output was specified but no default audio output is specified in the audio server\n"); + _exit(2); + } request_audio_input.name = audio_devices.default_output; - if(request_audio_input.description.empty()) - request_audio_input.description = "gsr-Default output"; match = true; - } - - if(!audio_devices.default_input.empty() && request_audio_input.name == "default_input") { + } else if(request_audio_input.name == "default_input") { + if(audio_devices.default_input.empty()) { + fprintf(stderr, "Error: -a default_input was specified but no default audio input is specified in the audio server\n"); + _exit(2); + } request_audio_input.name = audio_devices.default_input; - if(request_audio_input.description.empty()) - request_audio_input.description = "gsr-Default input"; - match = true; - } - - const AudioInput* existing_audio_input = get_audio_device_by_name(audio_devices.audio_inputs, request_audio_input.name); - if(existing_audio_input) { - if(request_audio_input.description.empty()) - request_audio_input.description = "gsr-" + existing_audio_input->description; match = true; + } else { + const bool name_is_existing_audio_device = get_audio_device_by_name(audio_devices.audio_inputs, request_audio_input.name.c_str()) != nullptr; + if(name_is_existing_audio_device) + match = true; } if(!match) { - fprintf(stderr, "Error: Audio input device '%s' is not a valid audio device, expected one of:\n", request_audio_input.name.c_str()); + fprintf(stderr, "Error: Audio device '%s' is not a valid audio device, expected one of:\n", request_audio_input.name.c_str()); if(!audio_devices.default_output.empty()) fprintf(stderr, " default_output (Default output)\n"); if(!audio_devices.default_input.empty()) @@ -2497,23 +2496,6 @@ static std::vector<MergedAudioInputs> parse_audio_inputs(const AudioDevices &aud } } - for(const char *app_audio_input : app_audio_input_arg.values) { - if(!app_audio_input || app_audio_input[0] == '\0') - continue; - - requested_audio_inputs.push_back({parse_app_audio_input_arg(app_audio_input)}); - } - - for(const char *app_audio_input : app_audio_input_inverted_arg.values) { - if(!app_audio_input || app_audio_input[0] == '\0') - continue; - - requested_audio_inputs.push_back({parse_app_audio_input_arg(app_audio_input)}); - for(auto &audio_input : requested_audio_inputs.back().audio_inputs) { - audio_input.inverted = true; - } - } - return requested_audio_inputs; } @@ -2864,15 +2846,15 @@ static const AVCodec* select_video_codec_with_fallback(VideoCodec *video_codec, return pick_video_codec(video_codec, egl, use_software_video_encoder, video_codec_auto, video_codec_to_use, is_flv, low_power); } -static std::vector<AudioDevice> create_device_audio_inputs(const std::vector<AudioInput> &audio_inputs, AVCodecContext *audio_codec_context, int num_channels, double num_audio_frames_shift, std::vector<AVFilterContext*> &src_filter_ctx, bool use_amix) { - std::vector<AudioDevice> audio_track_audio_devices; +static std::vector<AudioDeviceData> create_device_audio_inputs(const std::vector<AudioInput> &audio_inputs, AVCodecContext *audio_codec_context, int num_channels, double num_audio_frames_shift, std::vector<AVFilterContext*> &src_filter_ctx, bool use_amix) { + std::vector<AudioDeviceData> audio_track_audio_devices; for(size_t i = 0; i < audio_inputs.size(); ++i) { const auto &audio_input = audio_inputs[i]; AVFilterContext *src_ctx = nullptr; if(use_amix) src_ctx = src_filter_ctx[i]; - AudioDevice audio_device; + AudioDeviceData audio_device; audio_device.audio_input = audio_input; audio_device.src_filter_ctx = src_ctx; @@ -2880,7 +2862,8 @@ static std::vector<AudioDevice> create_device_audio_inputs(const std::vector<Aud audio_device.sound_device.handle = NULL; audio_device.sound_device.frames = 0; } else { - if(sound_device_get_by_name(&audio_device.sound_device, audio_input.name.c_str(), audio_input.description.c_str(), num_channels, audio_codec_context->frame_size, audio_codec_context_get_audio_format(audio_codec_context)) != 0) { + const std::string description = "gsr-" + audio_input.name; + if(sound_device_get_by_name(&audio_device.sound_device, audio_input.name.c_str(), description.c_str(), num_channels, audio_codec_context->frame_size, audio_codec_context_get_audio_format(audio_codec_context)) != 0) { fprintf(stderr, "Error: failed to get \"%s\" audio device\n", audio_input.name.c_str()); _exit(1); } @@ -2895,8 +2878,8 @@ static std::vector<AudioDevice> create_device_audio_inputs(const std::vector<Aud } #ifdef GSR_APP_AUDIO -static AudioDevice create_application_audio_audio_input(const MergedAudioInputs &merged_audio_inputs, AVCodecContext *audio_codec_context, int num_channels, double num_audio_frames_shift, gsr_pipewire_audio *pipewire_audio) { - AudioDevice audio_device; +static AudioDeviceData create_application_audio_audio_input(const MergedAudioInputs &merged_audio_inputs, AVCodecContext *audio_codec_context, int num_channels, double num_audio_frames_shift, gsr_pipewire_audio *pipewire_audio) { + AudioDeviceData audio_device; audio_device.frame = create_audio_frame(audio_codec_context); audio_device.frame->pts = -audio_codec_context->frame_size * num_audio_frames_shift; @@ -2979,6 +2962,11 @@ int main(int argc, char **argv) { // Same as above, but for amd/intel unsetenv("vblank_mode"); + if(geteuid() == 0) { + fprintf(stderr, "Error: don't run gpu-screen-recorder as the root user\n"); + _exit(1); + } + if(argc <= 1) usage_full(); @@ -3018,10 +3006,6 @@ int main(int argc, char **argv) { { "-f", Arg { {}, false, false } }, { "-s", Arg { {}, true, false } }, { "-a", Arg { {}, true, true } }, -#ifdef GSR_APP_AUDIO - { "-aa", Arg { {}, true, true } }, // TODO: Remove soon since this is deprecated. User should use -a with app: instead - { "-aai", Arg { {}, true, true } }, // TODO: Remove soon since this is deprecated. User should use -a with app-inverse: instead -#endif { "-q", Arg { {}, true, false } }, { "-o", Arg { {}, true, false } }, { "-r", Arg { {}, true, false } }, @@ -3280,20 +3264,12 @@ int main(int argc, char **argv) { } const Arg &audio_input_arg = args["-a"]; - const Arg &app_audio_input_arg = args["-aa"]; - const Arg &app_audio_input_inverted_arg = args["-aai"]; AudioDevices audio_devices; if(!audio_input_arg.values.empty()) audio_devices = get_pulseaudio_inputs(); - - if(!app_audio_input_arg.values.empty()) - fprintf(stderr, "gsr warning: argument -aa is deprecated, use -a with app: prefix instead, for example: -a \"app:Brave\"\n"); - - if(!app_audio_input_inverted_arg.values.empty()) - fprintf(stderr, "gsr warning: argument -aai is deprecated, use -a with app-inverse: prefix instead, for example: -a \"app-inverse:Brave\"\n"); - std::vector<MergedAudioInputs> requested_audio_inputs = parse_audio_inputs(audio_devices, audio_input_arg, app_audio_input_arg, app_audio_input_inverted_arg); + std::vector<MergedAudioInputs> requested_audio_inputs = parse_audio_inputs(audio_devices, audio_input_arg); const bool uses_app_audio = merged_audio_inputs_has_app_audio(requested_audio_inputs); std::vector<std::string> app_audio_names; @@ -3301,13 +3277,13 @@ int main(int argc, char **argv) { gsr_pipewire_audio pipewire_audio; memset(&pipewire_audio, 0, sizeof(pipewire_audio)); if(uses_app_audio) { - if(!gsr_pipewire_audio_init(&pipewire_audio)) { - fprintf(stderr, "gsr error: failed to setup PipeWire audio for application audio capture. The likely reason for this failure is that your sound server is not PipeWire. Application audio is only available when running PipeWire audio server.\n"); + if(!pulseaudio_server_is_pipewire()) { + fprintf(stderr, "gsr error: your sound server is not PipeWire. Application audio is only available when running PipeWire audio server\n"); _exit(2); } - if(!pulseaudio_server_is_pipewire()) { - fprintf(stderr, "gsr error: your sound server is not PipeWire. Application audio is only available when running PipeWire audio server.\n"); + if(!gsr_pipewire_audio_init(&pipewire_audio)) { + fprintf(stderr, "gsr error: failed to setup PipeWire audio for application audio capture\n"); _exit(2); } @@ -3644,7 +3620,7 @@ int main(int argc, char **argv) { if(is_livestream && requested_audio_inputs.empty()) { fprintf(stderr, "Info: live streaming but no audio track was added. Adding a silent audio track\n"); MergedAudioInputs mai; - mai.audio_inputs.push_back({ "", "gsr-silent" }); + mai.audio_inputs.push_back({""}); requested_audio_inputs.push_back(std::move(mai)); } @@ -3727,6 +3703,9 @@ int main(int argc, char **argv) { if(replay_buffer_size_secs == -1) audio_stream = create_stream(av_format_context, audio_codec_context); + if(audio_stream && !merged_audio_inputs.track_name.empty()) + av_dict_set(&audio_stream->metadata, "title", merged_audio_inputs.track_name.c_str(), 0); + open_audio(audio_codec_context); if(audio_stream) avcodec_parameters_from_context(audio_stream->codecpar, audio_codec_context); @@ -3758,7 +3737,7 @@ int main(int argc, char **argv) { const double audio_startup_time_seconds = force_no_audio_offset ? 0 : audio_codec_get_desired_delay(audio_codec, fps);// * ((double)audio_codec_context->frame_size / 1024.0); const double num_audio_frames_shift = audio_startup_time_seconds / timeout_sec; - std::vector<AudioDevice> audio_track_audio_devices; + std::vector<AudioDeviceData> audio_track_audio_devices; if(audio_inputs_has_app_audio(merged_audio_inputs.audio_inputs)) { assert(!use_amix); #ifdef GSR_APP_AUDIO @@ -3769,6 +3748,7 @@ int main(int argc, char **argv) { } AudioTrack audio_track; + audio_track.name = merged_audio_inputs.track_name; audio_track.codec_context = audio_codec_context; audio_track.stream = audio_stream; audio_track.audio_devices = std::move(audio_track_audio_devices); @@ -3831,7 +3811,7 @@ int main(int argc, char **argv) { memset(empty_audio, 0, audio_buffer_size); for(AudioTrack &audio_track : audio_tracks) { - for(AudioDevice &audio_device : audio_track.audio_devices) { + for(AudioDeviceData &audio_device : audio_track.audio_devices) { audio_device.thread = std::thread([&]() mutable { const AVSampleFormat sound_device_sample_format = audio_format_to_sample_format(audio_codec_context_get_audio_format(audio_track.codec_context)); // TODO: Always do conversion for now. This fixes issue with stuttering audio on pulseaudio with opus + multiple audio sources merged @@ -4226,7 +4206,7 @@ int main(int argc, char **argv) { } for(AudioTrack &audio_track : audio_tracks) { - for(AudioDevice &audio_device : audio_track.audio_devices) { + for(auto &audio_device : audio_track.audio_devices) { audio_device.thread.join(); sound_device_close(&audio_device.sound_device); } |