aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-08-31 06:49:25 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-31 06:49:25 +0200
commitc94ce44dbeb1156cd9c9ac1ae9d40248ce6c491e (patch)
tree8d647bcbd98aa6bca568e1028f4c08f98557cee2
parentc622d2d799820b90dc624c5f869b79607c62f1ae (diff)
Fix black video when resizing to smaller window size
-rw-r--r--README.md1
-rw-r--r--src/main.cpp18
2 files changed, 17 insertions, 2 deletions
diff --git a/README.md b/README.md
index 750b8af..55fb67f 100644
--- a/README.md
+++ b/README.md
@@ -38,5 +38,4 @@ FFMPEG only uses the GPU with CUDA when doing transcoding from an input video to
libraries at compile-time.
* Clean up the code!
* Fix segfault in debug mode (happens because audio codec becomes NULL?)
-* Fix blackscreen at start that appears until the second keyframe, which can be several seconds on a non-moving screen. Why does this happen? ffmpeg says the first frame should always be a keyframe!
* Dynamically change bitrate to match desired fps. This would be helpful when streaming for example, where the encode output speed also depends on upload speed to the stream service.
diff --git a/src/main.cpp b/src/main.cpp
index e19fa3e..74e61f9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -897,6 +897,9 @@ int main(int argc, char **argv) {
int window_width = xwa.width;
int window_height = xwa.height;
+ int original_window_width = window_width;
+ int original_window_height = window_height;
+
std::mutex write_output_mutex;
std::thread audio_thread;
@@ -1026,6 +1029,7 @@ int main(int argc, char **argv) {
"Error: cuGraphicsGLRegisterImage failed, error %s, texture "
"id: %u\n",
err_str, window_pixmap.target_texture_id);
+ running = false;
break;
}
@@ -1037,8 +1041,21 @@ int main(int argc, char **argv) {
av_frame_unref(frame);
if (av_hwframe_get_buffer(video_stream->codec->hw_frames_ctx, frame, 0) < 0) {
fprintf(stderr, "Error: av_hwframe_get_buffer failed\n");
+ running = false;
break;
}
+
+ frame->pts = frame_count;
+
+ if(window_width < original_window_width)
+ frame->width = window_pixmap.texture_width & ~1;
+ else
+ frame->width = original_window_width;
+
+ if(window_height < original_window_height)
+ frame->height = window_pixmap.texture_height & ~1;
+ else
+ frame->height = original_window_height;
}
++fps_counter;
@@ -1085,7 +1102,6 @@ int main(int argc, char **argv) {
cuMemcpy2D(&memcpy_struct);
// res = cuCtxPopCurrent(&old_ctx);
glfwSwapBuffers(window);
-
}
frame->pts = frame_count;