extern "C" { #include "../include/capture/nvfbc.h" #include "../include/capture/xcomposite.h" #include "../include/capture/kms.h" #ifdef GSR_PORTAL #include "../include/capture/portal.h" #include "../include/dbus.h" #endif #ifdef GSR_APP_AUDIO #include "../include/pipewire_audio.h" #endif #include "../include/encoder/video/nvenc.h" #include "../include/encoder/video/vaapi.h" #include "../include/encoder/video/vulkan.h" #include "../include/encoder/video/software.h" #include "../include/codec_query/nvenc.h" #include "../include/codec_query/vaapi.h" #include "../include/codec_query/vulkan.h" #include "../include/egl.h" #include "../include/utils.h" #include "../include/damage.h" #include "../include/color_conversion.h" } #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../include/sound.hpp" extern "C" { #include #include #include #include #include #include #include #include #include #include #include } #include #include #ifndef GSR_VERSION #define GSR_VERSION "unknown" #endif // TODO: If options are not supported then they are returned (allocated) in the options. This should be free'd. // TODO: Remove LIBAVUTIL_VERSION_MAJOR checks in the future when ubuntu, pop os LTS etc update ffmpeg to >= 5.0 static const int AUDIO_SAMPLE_RATE = 48000; static const int VIDEO_STREAM_INDEX = 0; static thread_local char av_error_buffer[AV_ERROR_MAX_STRING_SIZE]; static void monitor_output_callback_print(const gsr_monitor *monitor, void *userdata) { (void)userdata; fprintf(stderr, " \"%.*s\" (%dx%d+%d+%d)\n", monitor->name_len, monitor->name, monitor->size.x, monitor->size.y, monitor->pos.x, monitor->pos.y); } typedef struct { const char *output_name; } FirstOutputCallback; static void get_first_output(const gsr_monitor *monitor, void *userdata) { FirstOutputCallback *first_output = (FirstOutputCallback*)userdata; if(!first_output->output_name) first_output->output_name = strndup(monitor->name, monitor->name_len + 1); } static char* av_error_to_string(int err) { if(av_strerror(err, av_error_buffer, sizeof(av_error_buffer)) < 0) strcpy(av_error_buffer, "Unknown error"); return av_error_buffer; } enum class VideoQuality { MEDIUM, HIGH, VERY_HIGH, ULTRA }; enum class VideoCodec { H264, HEVC, HEVC_HDR, HEVC_10BIT, AV1, AV1_HDR, AV1_10BIT, VP8, VP9, H264_VULKAN, HEVC_VULKAN }; enum class AudioCodec { AAC, OPUS, FLAC }; enum class PixelFormat { YUV420, YUV444 }; enum class FramerateMode { CONSTANT, VARIABLE, CONTENT }; enum class BitrateMode { QP, VBR, CBR }; static int x11_error_handler(Display*, XErrorEvent*) { return 0; } static int x11_io_error_handler(Display*) { return 0; } static bool video_codec_is_hdr(VideoCodec video_codec) { // TODO: Vulkan switch(video_codec) { case VideoCodec::HEVC_HDR: case VideoCodec::AV1_HDR: return true; default: return false; } } static VideoCodec hdr_video_codec_to_sdr_video_codec(VideoCodec video_codec) { // TODO: Vulkan switch(video_codec) { case VideoCodec::HEVC_HDR: return VideoCodec::HEVC; case VideoCodec::AV1_HDR: return VideoCodec::AV1; default: return video_codec; } } static gsr_color_depth video_codec_to_bit_depth(VideoCodec video_codec) { // TODO: Vulkan switch(video_codec) { case VideoCodec::HEVC_HDR: case VideoCodec::HEVC_10BIT: case VideoCodec::AV1_HDR: case VideoCodec::AV1_10BIT: return GSR_COLOR_DEPTH_10_BITS; default: return GSR_COLOR_DEPTH_8_BITS; } } // static bool video_codec_is_hevc(VideoCodec video_codec) { // TODO: Vulkan // switch(video_codec) { // case VideoCodec::HEVC: // case VideoCodec::HEVC_HDR: // case VideoCodec::HEVC_10BIT: // return true; // default: // return false; // } // } static bool video_codec_is_av1(VideoCodec video_codec) { // TODO: Vulkan switch(video_codec) { case VideoCodec::AV1: case VideoCodec::AV1_HDR: case VideoCodec::AV1_10BIT: return true; default: return false; } } static bool video_codec_is_vulkan(VideoCodec video_codec) { switch(video_codec) { case VideoCodec::H264_VULKAN: case VideoCodec::HEVC_VULKAN: return true; default: return false; } } struct PacketData { PacketData() {} PacketData(const PacketData&) = delete; PacketData& operator=(const PacketData&) = delete; ~PacketData() { av_free(data.data); } AVPacket data; }; // |stream| is only required for non-replay mode static void receive_frames(AVCodecContext *av_codec_context, int stream_index, AVStream *stream, int64_t pts, AVFormatContext *av_format_context, double replay_start_time, std::deque> &frame_data_queue, int replay_buffer_size_secs, bool &frames_erased, std::mutex &write_output_mutex, double paused_time_offset) { for (;;) { AVPacket *av_packet = av_packet_alloc(); if(!av_packet) break; av_packet->data = NULL; av_packet->size = 0; int res = avcodec_receive_packet(av_codec_context, av_packet); if (res == 0) { // we have a packet, send the packet to the muxer av_packet->stream_index = stream_index; av_packet->pts = pts; av_packet->dts = pts; std::lock_guard lock(write_output_mutex); if(replay_buffer_size_secs != -1) { // TODO: Preallocate all frames data and use those instead. // Why are we doing this you ask? there is a new ffmpeg bug that causes cpu usage to increase over time when you have // packets that are not being free'd until later. So we copy the packet data, free the packet and then reconstruct // the packet later on when we need it, to keep packets alive only for a short period. auto new_packet = std::make_shared(); new_packet->data = *av_packet; new_packet->data.data = (uint8_t*)av_malloc(av_packet->size); memcpy(new_packet->data.data, av_packet->data, av_packet->size); double time_now = clock_get_monotonic_seconds() - paused_time_offset; double replay_time_elapsed = time_now - replay_start_time; frame_data_queue.push_back(std::move(new_packet)); if(replay_time_elapsed >= replay_buffer_size_secs) { frame_data_queue.pop_front(); frames_erased = true; } } else { av_packet_rescale_ts(av_packet, av_codec_context->time_base, stream->time_base); av_packet->stream_index = stream->index; // TODO: Is av_interleaved_write_frame needed?. Answer: might be needed for mkv but dont use it! it causes frames to be inconsistent, skipping frames and duplicating frames int ret = av_write_frame(av_format_context, av_packet); if(ret < 0) { fprintf(stderr, "Error: Failed to write frame index %d to muxer, reason: %s (%d)\n", av_packet->stream_index, av_error_to_string(ret), ret); } } av_packet_free(&av_packet); } else if (res == AVERROR(EAGAIN)) { // we have no packet // fprintf(stderr, "No packet!\n"); av_packet_free(&av_packet); break; } else if (res == AVERROR_EOF) { // this is the end of the stream av_packet_free(&av_packet); fprintf(stderr, "End of stream!\n"); break; } else { av_packet_free(&av_packet); fprintf(stderr, "Unexpected error: %d\n", res); break; } } } static const char* audio_codec_get_name(AudioCodec audio_codec) { switch(audio_codec) { case AudioCodec::AAC: return "aac"; case AudioCodec::OPUS: return "opus"; case AudioCodec::FLAC: return "flac"; } assert(false); return ""; } static AVCodecID audio_codec_get_id(AudioCodec audio_codec) { switch(audio_codec) { case AudioCodec::AAC: return AV_CODEC_ID_AAC; case AudioCodec::OPUS: return AV_CODEC_ID_OPUS; case AudioCodec::FLAC: return AV_CODEC_ID_FLAC; } assert(false); return AV_CODEC_ID_AAC; } static AVSampleFormat audio_codec_get_sample_format(AVCodecContext *audio_codec_context, AudioCodec audio_codec, const AVCodec *codec, bool mix_audio) { (void)audio_codec_context; switch(audio_codec) { case AudioCodec::AAC: { return AV_SAMPLE_FMT_FLTP; } case AudioCodec::OPUS: { bool supports_s16 = false; bool supports_flt = false; #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 15, 0) for(size_t i = 0; codec->sample_fmts && codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; ++i) { if(codec->sample_fmts[i] == AV_SAMPLE_FMT_S16) { supports_s16 = true; } else if(codec->sample_fmts[i] == AV_SAMPLE_FMT_FLT) { supports_flt = true; } } #else const enum AVSampleFormat *sample_fmts = NULL; if(avcodec_get_supported_config(audio_codec_context, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void**)&sample_fmts, NULL) >= 0) { if(sample_fmts) { for(size_t i = 0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; ++i) { if(sample_fmts[i] == AV_SAMPLE_FMT_S16) { supports_s16 = true; } else if(sample_fmts[i] == AV_SAMPLE_FMT_FLT) { supports_flt = true; } } } else { // What a dumb API. It returns NULL if all formats are supported supports_s16 = true; supports_flt = true; } } #endif // Amix only works with float audio if(mix_audio) supports_s16 = false; if(!supports_s16 && !supports_flt) { fprintf(stderr, "Warning: opus audio codec is chosen but your ffmpeg version does not support s16/flt sample format and performance might be slightly worse.\n"); fprintf(stderr, " You can either rebuild ffmpeg with libopus instead of the built-in opus, use the flatpak version of gpu screen recorder or record with aac audio codec instead (-ac aac).\n"); fprintf(stderr, " Falling back to fltp audio sample format instead.\n"); } if(supports_s16) return AV_SAMPLE_FMT_S16; else if(supports_flt) return AV_SAMPLE_FMT_FLT; else return AV_SAMPLE_FMT_FLTP; } case AudioCodec::FLAC: { return AV_SAMPLE_FMT_S32; } } assert(false); return AV_SAMPLE_FMT_FLTP; } static int64_t audio_codec_get_get_bitrate(AudioCodec audio_codec) { switch(audio_codec) { case AudioCodec::AAC: return 160000; case AudioCodec::OPUS: return 128000; case AudioCodec::FLAC: return 128000; } assert(false); return 128000; } static AudioFormat audio_codec_context_get_audio_format(const AVCodecContext *audio_codec_context) { switch(audio_codec_context->sample_fmt) { case AV_SAMPLE_FMT_FLT: return F32; case AV_SAMPLE_FMT_FLTP: return S32; case AV_SAMPLE_FMT_S16: return S16; case AV_SAMPLE_FMT_S32: return S32; default: return S16; } } static AVSampleFormat audio_format_to_sample_format(const AudioFormat audio_format) { switch(audio_format) { case S16: return AV_SAMPLE_FMT_S16; case S32: return AV_SAMPLE_FMT_S32; case F32: return AV_SAMPLE_FMT_FLT; } assert(false); return AV_SAMPLE_FMT_S16; } static AVCodecContext* create_audio_codec_context(int fps, AudioCodec audio_codec, bool mix_audio, int64_t audio_bitrate) { (void)fps; const AVCodec *codec = avcodec_find_encoder(audio_codec_get_id(audio_codec)); if (!codec) { fprintf(stderr, "Error: Could not find %s audio encoder\n", audio_codec_get_name(audio_codec)); _exit(1); } AVCodecContext *codec_context = avcodec_alloc_context3(codec); assert(codec->type == AVMEDIA_TYPE_AUDIO); codec_context->codec_id = codec->id; codec_context->sample_fmt = audio_codec_get_sample_format(codec_context, audio_codec, codec, mix_audio); codec_context->bit_rate = audio_bitrate == 0 ? audio_codec_get_get_bitrate(audio_codec) : audio_bitrate; codec_context->sample_rate = AUDIO_SAMPLE_RATE; if(audio_codec == AudioCodec::AAC) codec_context->profile = FF_PROFILE_AAC_LOW; #if LIBAVCODEC_VERSION_MAJOR < 60 codec_context->channel_layout = AV_CH_LAYOUT_STEREO; codec_context->channels = 2; #else av_channel_layout_default(&codec_context->ch_layout, 2); #endif codec_context->time_base.num = 1; codec_context->time_base.den = codec_context->sample_rate; codec_context->thread_count = 1; codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; return codec_context; } static int vbr_get_quality_parameter(AVCodecContext *codec_context, VideoQuality video_quality, bool hdr) { // 8 bit / 10 bit = 80% const float qp_multiply = hdr ? 8.0f/10.0f : 1.0f; if(codec_context->codec_id == AV_CODEC_ID_AV1) { switch(video_quality) { case VideoQuality::MEDIUM: return 160 * qp_multiply; case VideoQuality::HIGH: return 130 * qp_multiply; case VideoQuality::VERY_HIGH: return 110 * qp_multiply; case VideoQuality::ULTRA: return 90 * qp_multiply; } } else if(codec_context->codec_id == AV_CODEC_ID_H264) { switch(video_quality) { case VideoQuality::MEDIUM: return 35 * qp_multiply; case VideoQuality::HIGH: return 30 * qp_multiply; case VideoQuality::VERY_HIGH: return 25 * qp_multiply; case VideoQuality::ULTRA: return 22 * qp_multiply; } } else if(codec_context->codec_id == AV_CODEC_ID_HEVC) { switch(video_quality) { case VideoQuality::MEDIUM: return 35 * qp_multiply; case VideoQuality::HIGH: return 30 * qp_multiply; case VideoQuality::VERY_HIGH: return 25 * qp_multiply; case VideoQuality::ULTRA: return 22 * qp_multiply; } } else if(codec_context->codec_id == AV_CODEC_ID_VP8 || codec_context->codec_id == AV_CODEC_ID_VP9) { switch(video_quality) { case VideoQuality::MEDIUM: return 35 * qp_multiply; case VideoQuality::HIGH: return 30 * qp_multiply; case VideoQuality::VERY_HIGH: return 25 * qp_multiply; case VideoQuality::ULTRA: return 22 * qp_multiply; } } assert(false); return 22 * qp_multiply; } static AVCodecContext *create_video_codec_context(AVPixelFormat pix_fmt, VideoQuality video_quality, int fps, const AVCodec *codec, bool low_latency, gsr_gpu_vendor vendor, FramerateMode framerate_mode, bool hdr, gsr_color_range color_range, float keyint, bool use_software_video_encoder, BitrateMode bitrate_mode, VideoCodec video_codec, int64_t bitrate) { AVCodecContext *codec_context = avcodec_alloc_context3(codec); //double fps_ratio = (double)fps / 30.0; assert(codec->type == AVMEDIA_TYPE_VIDEO); codec_context->codec_id = codec->id; // Timebase: This is the fundamental unit of time (in seconds) in terms // of which frame timestamps are represented. For fixed-fps content, // timebase should be 1/framerate and timestamp increments should be // identical to 1 codec_context->time_base.num = 1; codec_context->time_base.den = framerate_mode == FramerateMode::CONSTANT ? fps : AV_TIME_BASE; codec_context->framerate.num = fps; codec_context->framerate.den = 1; codec_context->sample_aspect_ratio.num = 0; codec_context->sample_aspect_ratio.den = 0; if(low_latency) { codec_context->flags |= (AV_CODEC_FLAG_CLOSED_GOP | AV_CODEC_FLAG_LOW_DELAY); codec_context->flags2 |= AV_CODEC_FLAG2_FAST; //codec_context->gop_size = std::numeric_limits::max(); //codec_context->keyint_min = std::numeric_limits::max(); codec_context->gop_size = fps * keyint; } else { // High values reduce file size but increases time it takes to seek codec_context->gop_size = fps * keyint; } codec_context->max_b_frames = 0; codec_context->pix_fmt = pix_fmt; codec_context->color_range = color_range == GSR_COLOR_RANGE_LIMITED ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; if(hdr) { codec_context->color_primaries = AVCOL_PRI_BT2020; codec_context->color_trc = AVCOL_TRC_SMPTE2084; codec_context->colorspace = AVCOL_SPC_BT2020_NCL; } else { codec_context->color_primaries = AVCOL_PRI_BT709; codec_context->color_trc = AVCOL_TRC_BT709; codec_context->colorspace = AVCOL_SPC_BT709; } //codec_context->chroma_sample_location = AVCHROMA_LOC_CENTER; if(codec->id == AV_CODEC_ID_HEVC) codec_context->codec_tag = MKTAG('h', 'v', 'c', '1'); // QuickTime on MacOS requires this or the video wont be playable if(bitrate_mode == BitrateMode::CBR) { codec_context->bit_rate = bitrate; codec_context->rc_max_rate = codec_context->bit_rate; //codec_context->rc_min_rate = codec_context->bit_rate; codec_context->rc_buffer_size = codec_context->bit_rate;//codec_context->bit_rate / 10; codec_context->rc_initial_buffer_occupancy = 0;//codec_context->bit_rate;//codec_context->bit_rate * 1000; } else if(bitrate_mode == BitrateMode::VBR) { const int quality = vbr_get_quality_parameter(codec_context, video_quality, hdr); switch(video_quality) { case VideoQuality::MEDIUM: codec_context->qmin = quality; codec_context->qmax = quality; codec_context->bit_rate = 100000;//4500000 + (codec_context->width * codec_context->height)*0.75; break; case VideoQuality::HIGH: codec_context->qmin = quality; codec_context->qmax = quality; codec_context->bit_rate = 100000;//10000000-9000000 + (codec_context->width * codec_context->height)*0.75; break; case VideoQuality::VERY_HIGH: codec_context->qmin = quality; codec_context->qmax = quality; codec_context->bit_rate = 100000;//10000000-9000000 + (codec_context->width * codec_context->height)*0.75; break; case VideoQuality::ULTRA: codec_context->qmin = quality; codec_context->qmax = quality; codec_context->bit_rate = 100000;//10000000-9000000 + (codec_context->width * codec_context->height)*0.75; break; } codec_context->rc_max_rate = codec_context->bit_rate; //codec_context->rc_min_rate = codec_context->bit_rate; codec_context->rc_buffer_size = codec_context->bit_rate;//codec_context->bit_rate / 10; codec_context->rc_initial_buffer_occupancy = codec_context->bit_rate;//codec_context->bit_rate * 1000; } else { //codec_context->rc_buffer_size = 50000 * 1000; } //codec_context->profile = FF_PROFILE_H264_MAIN; 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) { // 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) { switch(video_quality) { case VideoQuality::MEDIUM: codec_context->global_quality = 150 * quality_multiply; break; case VideoQuality::HIGH: codec_context->global_quality = 120 * quality_multiply; break; case VideoQuality::VERY_HIGH: codec_context->global_quality = 115 * quality_multiply; break; case VideoQuality::ULTRA: codec_context->global_quality = 90 * quality_multiply; break; } } else if(codec_context->codec_id == AV_CODEC_ID_VP8) { switch(video_quality) { case VideoQuality::MEDIUM: codec_context->global_quality = 35 * quality_multiply; break; case VideoQuality::HIGH: codec_context->global_quality = 30 * quality_multiply; break; case VideoQuality::VERY_HIGH: codec_context->global_quality = 25 * quality_multiply; break; case VideoQuality::ULTRA: codec_context->global_quality = 10 * quality_multiply; break; } } else if(codec_context->codec_id == AV_CODEC_ID_VP9) { switch(video_quality) { case VideoQuality::MEDIUM: codec_context->global_quality = 35 * quality_multiply; break; case VideoQuality::HIGH: codec_context->global_quality = 30 * quality_multiply; break; case VideoQuality::VERY_HIGH: codec_context->global_quality = 25 * quality_multiply; break; case VideoQuality::ULTRA: codec_context->global_quality = 10 * quality_multiply; break; } } } av_opt_set_int(codec_context->priv_data, "b_ref_mode", 0, 0); //av_opt_set_int(codec_context->priv_data, "cbr", true, 0); if(vendor != GSR_GPU_VENDOR_NVIDIA) { // TODO: More options, better options //codec_context->bit_rate = codec_context->width * codec_context->height; switch(bitrate_mode) { case BitrateMode::QP: { if(video_codec_is_vulkan(video_codec)) av_opt_set(codec_context->priv_data, "rc_mode", "cqp", 0); else if(vendor == GSR_GPU_VENDOR_NVIDIA) av_opt_set(codec_context->priv_data, "rc", "constqp", 0); else av_opt_set(codec_context->priv_data, "rc_mode", "CQP", 0); break; } case BitrateMode::VBR: { if(video_codec_is_vulkan(video_codec)) av_opt_set(codec_context->priv_data, "rc_mode", "vbr", 0); else if(vendor == GSR_GPU_VENDOR_NVIDIA) av_opt_set(codec_context->priv_data, "rc", "vbr", 0); else av_opt_set(codec_context->priv_data, "rc_mode", "VBR", 0); break; } case BitrateMode::CBR: { if(video_codec_is_vulkan(video_codec)) av_opt_set(codec_context->priv_data, "rc_mode", "cbr", 0); else if(vendor == GSR_GPU_VENDOR_NVIDIA) av_opt_set(codec_context->priv_data, "rc", "cbr", 0); else av_opt_set(codec_context->priv_data, "rc_mode", "CBR", 0); break; } } //codec_context->global_quality = 4; //codec_context->compression_level = 2; } //av_opt_set(codec_context->priv_data, "bsf", "hevc_metadata=colour_primaries=9:transfer_characteristics=16:matrix_coefficients=9", 0); codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; return codec_context; } static void open_audio(AVCodecContext *audio_codec_context) { AVDictionary *options = nullptr; av_dict_set(&options, "strict", "experimental", 0); int ret; ret = avcodec_open2(audio_codec_context, audio_codec_context->codec, &options); if(ret < 0) { fprintf(stderr, "failed to open codec, reason: %s\n", av_error_to_string(ret)); _exit(1); } } static AVFrame* create_audio_frame(AVCodecContext *audio_codec_context) { AVFrame *frame = av_frame_alloc(); if(!frame) { fprintf(stderr, "failed to allocate audio frame\n"); _exit(1); } frame->sample_rate = audio_codec_context->sample_rate; frame->nb_samples = audio_codec_context->frame_size; frame->format = audio_codec_context->sample_fmt; #if LIBAVCODEC_VERSION_MAJOR < 60 frame->channels = audio_codec_context->channels; frame->channel_layout = audio_codec_context->channel_layout; #else av_channel_layout_copy(&frame->ch_layout, &audio_codec_context->ch_layout); #endif int ret = av_frame_get_buffer(frame, 0); if(ret < 0) { fprintf(stderr, "failed to allocate audio data buffers, reason: %s\n", av_error_to_string(ret)); _exit(1); } return frame; } 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) { // TODO: Only for vaapi //if(color_depth == GSR_COLOR_DEPTH_10_BITS) // av_dict_set(options, "profile", "high10", 0); //else av_dict_set(options, "profile", "high", 0); } else if(codec_context->codec_id == AV_CODEC_ID_AV1) { if(vendor == GSR_GPU_VENDOR_NVIDIA) { if(color_depth == GSR_COLOR_DEPTH_10_BITS) av_dict_set_int(options, "highbitdepth", 1, 0); } else { av_dict_set(options, "profile", "main", 0); // TODO: use professional instead? } } else if(codec_context->codec_id == AV_CODEC_ID_HEVC) { if(color_depth == GSR_COLOR_DEPTH_10_BITS) av_dict_set(options, "profile", "main10", 0); else av_dict_set(options, "profile", "main", 0); } #else if(codec_context->codec_id == AV_CODEC_ID_H264) { // TODO: Only for vaapi //if(color_depth == GSR_COLOR_DEPTH_10_BITS) // av_dict_set_int(options, "profile", AV_PROFILE_H264_HIGH_10, 0); //else av_dict_set_int(options, "profile", AV_PROFILE_H264_HIGH, 0); } else if(codec_context->codec_id == AV_CODEC_ID_AV1) { if(vendor == GSR_GPU_VENDOR_NVIDIA) { if(color_depth == GSR_COLOR_DEPTH_10_BITS) av_dict_set_int(options, "highbitdepth", 1, 0); } else { av_dict_set_int(options, "profile", AV_PROFILE_AV1_MAIN, 0); // TODO: use professional instead? } } else if(codec_context->codec_id == AV_CODEC_ID_HEVC) { if(color_depth == GSR_COLOR_DEPTH_10_BITS) av_dict_set_int(options, "profile", AV_PROFILE_HEVC_MAIN_10, 0); else av_dict_set_int(options, "profile", AV_PROFILE_HEVC_MAIN, 0); } #endif } static void video_software_set_qp(AVCodecContext *codec_context, VideoQuality video_quality, bool hdr, AVDictionary **options) { // 8 bit / 10 bit = 80% const float qp_multiply = hdr ? 8.0f/10.0f : 1.0f; if(codec_context->codec_id == AV_CODEC_ID_AV1) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 25 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } else if(codec_context->codec_id == AV_CODEC_ID_H264) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 34 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 25 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } else { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 25 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } } static void open_video_software(AVCodecContext *codec_context, VideoQuality video_quality, PixelFormat pixel_format, bool hdr, gsr_color_depth color_depth, BitrateMode bitrate_mode) { (void)pixel_format; // TODO: AVDictionary *options = nullptr; if(bitrate_mode == BitrateMode::QP) video_software_set_qp(codec_context, video_quality, hdr, &options); av_dict_set(&options, "preset", "veryfast", 0); av_dict_set(&options, "tune", "film", 0); dict_set_profile(codec_context, GSR_GPU_VENDOR_INTEL, color_depth, &options); if(codec_context->codec_id == AV_CODEC_ID_H264) { av_dict_set(&options, "coder", "cabac", 0); // TODO: cavlc is faster than cabac but worse compression. Which to use? } av_dict_set(&options, "strict", "experimental", 0); 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 video_set_rc(VideoCodec video_codec, gsr_gpu_vendor vendor, BitrateMode bitrate_mode, AVDictionary **options) { switch(bitrate_mode) { case BitrateMode::QP: { if(video_codec_is_vulkan(video_codec)) av_dict_set(options, "rc_mode", "cqp", 0); else if(vendor == GSR_GPU_VENDOR_NVIDIA) av_dict_set(options, "rc", "constqp", 0); else av_dict_set(options, "rc_mode", "CQP", 0); break; } case BitrateMode::VBR: { if(video_codec_is_vulkan(video_codec)) av_dict_set(options, "rc_mode", "vbr", 0); else if(vendor == GSR_GPU_VENDOR_NVIDIA) av_dict_set(options, "rc", "vbr", 0); else av_dict_set(options, "rc_mode", "VBR", 0); break; } case BitrateMode::CBR: { if(video_codec_is_vulkan(video_codec)) av_dict_set(options, "rc_mode", "cbr", 0); else if(vendor == GSR_GPU_VENDOR_NVIDIA) av_dict_set(options, "rc", "cbr", 0); else av_dict_set(options, "rc_mode", "CBR", 0); break; } } } static void video_hardware_set_qp(AVCodecContext *codec_context, VideoQuality video_quality, gsr_gpu_vendor vendor, bool hdr, AVDictionary **options) { // 8 bit / 10 bit = 80% const float qp_multiply = hdr ? 8.0f/10.0f : 1.0f; if(vendor == GSR_GPU_VENDOR_NVIDIA) { // TODO: Test if these should be in the same range as vaapi if(codec_context->codec_id == AV_CODEC_ID_AV1) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 27 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } else if(codec_context->codec_id == AV_CODEC_ID_H264) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 27 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } else if(codec_context->codec_id == AV_CODEC_ID_HEVC) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 27 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } else if(codec_context->codec_id == AV_CODEC_ID_VP8 || codec_context->codec_id == AV_CODEC_ID_VP9) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 27 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } } else { if(codec_context->codec_id == AV_CODEC_ID_AV1) { // Using global_quality option } else if(codec_context->codec_id == AV_CODEC_ID_H264) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 27 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } else if(codec_context->codec_id == AV_CODEC_ID_HEVC) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 27 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } else if(codec_context->codec_id == AV_CODEC_ID_VP8 || codec_context->codec_id == AV_CODEC_ID_VP9) { switch(video_quality) { case VideoQuality::MEDIUM: av_dict_set_int(options, "qp", 35 * qp_multiply, 0); break; case VideoQuality::HIGH: av_dict_set_int(options, "qp", 30 * qp_multiply, 0); break; case VideoQuality::VERY_HIGH: av_dict_set_int(options, "qp", 27 * qp_multiply, 0); break; case VideoQuality::ULTRA: av_dict_set_int(options, "qp", 22 * qp_multiply, 0); break; } } } } static void open_video_hardware(AVCodecContext *codec_context, VideoQuality video_quality, bool very_old_gpu, gsr_gpu_vendor vendor, PixelFormat pixel_format, bool hdr, gsr_color_depth color_depth, BitrateMode bitrate_mode, VideoCodec video_codec, bool low_power) { (void)very_old_gpu; AVDictionary *options = nullptr; if(bitrate_mode == BitrateMode::QP) video_hardware_set_qp(codec_context, video_quality, vendor, hdr, &options); video_set_rc(video_codec, vendor, bitrate_mode, &options); // TODO: Enable multipass // TODO: Set "usage" option to "record"/"stream" and "content" option to "rendered" for vulkan encoding if(vendor == GSR_GPU_VENDOR_NVIDIA) { // TODO: These dont seem to be necessary // av_dict_set_int(&options, "zerolatency", 1, 0); // if(codec_context->codec_id == AV_CODEC_ID_AV1) { // av_dict_set(&options, "tune", "ll", 0); // } else if(codec_context->codec_id == AV_CODEC_ID_H264 || codec_context->codec_id == AV_CODEC_ID_HEVC) { // av_dict_set(&options, "preset", "llhq", 0); // av_dict_set(&options, "tune", "ll", 0); // } av_dict_set(&options, "tune", "hq", 0); dict_set_profile(codec_context, vendor, color_depth, &options); if(codec_context->codec_id == AV_CODEC_ID_H264) { // TODO: h264 10bit? // TODO: // switch(pixel_format) { // case PixelFormat::YUV420: // av_dict_set_int(&options, "profile", AV_PROFILE_H264_HIGH, 0); // break; // case PixelFormat::YUV444: // av_dict_set_int(&options, "profile", AV_PROFILE_H264_HIGH_444, 0); // break; // } } else if(codec_context->codec_id == AV_CODEC_ID_AV1) { switch(pixel_format) { case PixelFormat::YUV420: av_dict_set(&options, "rgb_mode", "yuv420", 0); break; case PixelFormat::YUV444: av_dict_set(&options, "rgb_mode", "yuv444", 0); break; } } else if(codec_context->codec_id == AV_CODEC_ID_HEVC) { //av_dict_set(&options, "pix_fmt", "yuv420p16le", 0); } } else { // TODO: More quality options if(low_power) av_dict_set_int(&options, "low_power", 1, 0); // Improves performance but increases vram //av_dict_set_int(&options, "async_depth", 8, 0); if(codec_context->codec_id == AV_CODEC_ID_H264) { // Removed because it causes stutter in games for some people //av_dict_set_int(&options, "quality", 5, 0); // quality preset } else if(codec_context->codec_id == AV_CODEC_ID_AV1) { av_dict_set(&options, "tier", "main", 0); } else if(codec_context->codec_id == AV_CODEC_ID_HEVC) { if(hdr) av_dict_set(&options, "sei", "hdr", 0); } // TODO: vp8/vp9 10bit } if(codec_context->codec_id == AV_CODEC_ID_H264) { av_dict_set(&options, "coder", "cabac", 0); // TODO: cavlc is faster than cabac but worse compression. Which to use? } av_dict_set(&options, "strict", "experimental", 0); 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 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 [-c ] [-s WxH] -f [-a ] [-q ] [-r ] [-k h264|hevc|av1|vp8|vp9|hevc_hdr|av1_hdr|hevc_10bit|av1_10bit] [-ac aac|opus|flac] [-ab ] [-oc yes|no] [-fm cfr|vfr|content] [-bm auto|qp|vbr|cbr] [-cr limited|full] [-df yes|no] [-sc ] [-cursor yes|no] [-keyint ] [-restore-portal-session yes|no] [-portal-session-token-filepath filepath] [-encoder gpu|cpu] [-o ] [-v yes|no] [--version] [-h|--help]\n", program_name); } // TODO: Update with portal info 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 /, 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"); 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"); 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, "