Fix black video when resizing to smaller window size

This commit is contained in:
dec05eba 2020-08-31 06:49:25 +02:00
parent c622d2d799
commit c94ce44dbe
2 changed files with 17 additions and 2 deletions

View File

@ -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.

View File

@ -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;