From 5c5a696910b909f82a47ed352337092debab09e4 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sat, 10 Sep 2022 15:48:13 +0000 Subject: [PATCH] h264-encoder: Set async_depth=1 This fixes stalling during encoding. The FFmpeg devs seem to think that it's normal to change the default behaviour or their code, so this needs to be fixed here instead. Fixes #73 --- src/h264-encoder.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/h264-encoder.c b/src/h264-encoder.c index d9ef49b..2c75647 100644 --- a/src/h264-encoder.c +++ b/src/h264-encoder.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -417,7 +418,9 @@ static void h264_encoder__do_work(void* handle) int rc = h264_encoder__encode(self, frame); if (rc != 0) { - // TODO: log failure + char err[256]; + av_strerror(rc, err, sizeof(err)); + nvnc_log(NVNC_LOG_ERROR, "Failed to encode packet: %s", err); goto failure; } @@ -443,8 +446,10 @@ static void h264_encoder__on_work_done(void* handle) return; } - if (self->current_packet.len == 0) + if (self->current_packet.len == 0) { + nvnc_log(NVNC_LOG_WARNING, "Whoops, encoded packet length is 0"); return; + } void* userdata = self->userdata; @@ -536,7 +541,12 @@ struct h264_encoder* h264_encoder_create(uint32_t width, uint32_t height, self->codec_ctx->hw_frames_ctx = av_buffer_ref(self->filter_out->inputs[0]->hw_frames_ctx); - rc = avcodec_open2(self->codec_ctx, codec, NULL); + AVDictionary *opts = NULL; + av_dict_set_int(&opts, "async_depth", 1, 0); + + rc = avcodec_open2(self->codec_ctx, codec, &opts); + av_dict_free(&opts); + if (rc != 0) goto avcodec_open_failure;