aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-04-29 20:47:08 +0200
committerdec05eba <dec05eba@protonmail.com>2024-05-03 19:38:36 +0200
commitf90b2747206ab2d50db47e510727980f5129e2f6 (patch)
tree4991e11513432f3dce7c3df5866b2fdd59f8155d
parent3143358c3bfc882fb94c1ea906630fc0aa7fd061 (diff)
Cleanup, clear bg on init
-rw-r--r--TODO4
-rw-r--r--src/capture/capture.c4
-rw-r--r--src/main.cpp29
3 files changed, 23 insertions, 14 deletions
diff --git a/TODO b/TODO
index 5211e9f..dd374ee 100644
--- a/TODO
+++ b/TODO
@@ -121,3 +121,7 @@ Investigate if there is a way to do gpu->gpu copy directly without touching syst
Fix opus/flac ( variable framerate audio :( ). Going back to constant framerate audio should fix the issue with skipped frames when recording for some people (issue only reproducable with pulseaudio, and only for some users?).
Go back to using pure vaapi without opengl for video encoding? rotation (transpose) can be done if its done after (rgb to yuv) color conversion.
+
+Implement scaling and use lanczos resampling for better quality. Lanczos resampling can also be used for YUV chroma for better color quality on small text.
+
+Try fixing HDR by passing HDR+10 data as well, and in the packet. Run "ffprobe -loglevel quiet -read_intervals "%+#2" -select_streams v:0 -show_entries side_data video.mp4" to test if the file has correct metadata.
diff --git a/src/capture/capture.c b/src/capture/capture.c
index cec0b0d..670114e 100644
--- a/src/capture/capture.c
+++ b/src/capture/capture.c
@@ -180,6 +180,8 @@ bool gsr_capture_base_setup_vaapi_textures(gsr_capture_base *self, AVFrame *fram
return false;
}
+ gsr_color_conversion_clear(&self->color_conversion);
+
return true;
} else {
fprintf(stderr, "gsr error: gsr_capture_kms_setup_vaapi_textures: unexpected fourcc %u for output drm fd, expected nv12 or p010\n", prime->fourcc);
@@ -279,6 +281,8 @@ bool gsr_capture_base_setup_cuda_textures(gsr_capture_base *self, AVFrame *frame
return false;
}
+ gsr_color_conversion_clear(&self->color_conversion);
+
return true;
}
diff --git a/src/main.cpp b/src/main.cpp
index d00a9be..a673d3d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -543,7 +543,7 @@ static const AVCodec* find_h264_encoder(gsr_gpu_vendor vendor, const char *card_
return checked_success ? codec : nullptr;
}
-static const AVCodec* find_h265_encoder(gsr_gpu_vendor vendor, const char *card_path) {
+static const AVCodec* find_hevc_encoder(gsr_gpu_vendor vendor, const char *card_path) {
const AVCodec *codec = avcodec_find_encoder_by_name(vendor == GSR_GPU_VENDOR_NVIDIA ? "hevc_nvenc" : "hevc_vaapi");
if(!codec)
codec = avcodec_find_encoder_by_name(vendor == GSR_GPU_VENDOR_NVIDIA ? "nvenc_hevc" : "vaapi_hevc");
@@ -1422,7 +1422,7 @@ static void list_supported_video_codecs() {
// TODO: Output hdr
if(find_h264_encoder(egl.gpu_info.vendor, card_path))
puts("h264");
- if(find_h265_encoder(egl.gpu_info.vendor, card_path))
+ if(find_hevc_encoder(egl.gpu_info.vendor, card_path))
puts("hevc");
if(find_av1_encoder(egl.gpu_info.vendor, card_path))
puts("av1");
@@ -2114,16 +2114,18 @@ int main(int argc, char **argv) {
video_codec = VideoCodec::H264;
}
} else {
- const AVCodec *h265_codec = find_h265_encoder(egl.gpu_info.vendor, egl.card_path);
+ const AVCodec *hevc_codec = find_hevc_encoder(egl.gpu_info.vendor, egl.card_path);
- if(h265_codec && fps > 60) {
+ if(hevc_codec && fps > 60) {
fprintf(stderr, "Warning: recording at higher fps than 60 with hevc might result in recording at a very low fps. If this happens, switch to h264 or av1\n");
}
+ // TODO: Default to h264 if resolution is around 1366x768 on AMD
+
// hevc generally allows recording at a higher resolution than h264 on nvidia cards. On a gtx 1080 4k is the max resolution for h264 but for hevc it's 8k.
// Another important info is that when recording at a higher fps than.. 60? hevc has very bad performance. For example when recording at 144 fps the fps drops to 1
// while with h264 the fps doesn't drop.
- if(!h265_codec) {
+ if(!hevc_codec) {
fprintf(stderr, "Info: using h264 encoder because a codec was not specified and your gpu does not support hevc\n");
video_codec_to_use = "h264";
video_codec = VideoCodec::H264;
@@ -2150,7 +2152,7 @@ int main(int argc, char **argv) {
break;
case VideoCodec::HEVC:
case VideoCodec::HEVC_HDR:
- video_codec_f = find_h265_encoder(egl.gpu_info.vendor, egl.card_path);
+ video_codec_f = find_hevc_encoder(egl.gpu_info.vendor, egl.card_path);
break;
case VideoCodec::AV1:
case VideoCodec::AV1_HDR:
@@ -2164,7 +2166,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Warning: selected video codec h264 is not supported, trying hevc instead\n");
video_codec_to_use = "hevc";
video_codec = VideoCodec::HEVC;
- video_codec_f = find_h265_encoder(egl.gpu_info.vendor, egl.card_path);
+ video_codec_f = find_hevc_encoder(egl.gpu_info.vendor, egl.card_path);
break;
}
case VideoCodec::HEVC:
@@ -2367,10 +2369,8 @@ int main(int argc, char **argv) {
av_dict_free(&options);
}
- const double start_time_pts = clock_get_monotonic_seconds();
-
- double start_time = clock_get_monotonic_seconds();
- double frame_timer_start = start_time - target_fps; // We want to capture the first frame immediately
+ double fps_start_time = clock_get_monotonic_seconds();
+ double frame_timer_start = fps_start_time - target_fps; // We want to capture the first frame immediately
int fps_counter = 0;
bool paused = false;
@@ -2570,6 +2570,7 @@ int main(int argc, char **argv) {
}
++fps_counter;
+ // TODO: Move to another thread, since this shouldn't be locked to video encoding fps
{
std::lock_guard<std::mutex> lock(audio_filter_mutex);
for(AudioTrack &audio_track : audio_tracks) {
@@ -2597,12 +2598,12 @@ int main(int argc, char **argv) {
double time_now = clock_get_monotonic_seconds();
double frame_timer_elapsed = time_now - frame_timer_start;
- double elapsed = time_now - start_time;
+ double elapsed = time_now - fps_start_time;
if (elapsed >= 1.0) {
if(verbose) {
fprintf(stderr, "update fps: %d\n", fps_counter);
}
- start_time = time_now;
+ fps_start_time = time_now;
fps_counter = 0;
}
@@ -2612,7 +2613,7 @@ int main(int argc, char **argv) {
frame_timer_start = time_now - frame_time_overflow;
const double this_video_frame_time = clock_get_monotonic_seconds() - paused_time_offset;
- const int64_t expected_frames = std::round((this_video_frame_time - start_time_pts) / target_fps);
+ const int64_t expected_frames = std::round((this_video_frame_time - record_start_time) / target_fps);
const int num_frames = framerate_mode == FramerateMode::CONSTANT ? std::max((int64_t)0LL, expected_frames - video_pts_counter) : 1;
if(num_frames > 0 && !paused) {