encoder: Ensure that delayed encoders are flushed properly

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-07-24 21:22:14 +02:00
parent 11cc88deb6
commit 24bc913f53
+8
View File
@@ -610,6 +610,14 @@ obsffmpeg::encoder::~encoder()
this->swscale.finalize();
if (this->context) {
// Flush encoders that require it.
if ((this->codec->capabilities & AV_CODEC_CAP_DELAY) != 0) {
avcodec_send_frame(this->context, nullptr);
while (avcodec_receive_packet(this->context, &this->current_packet) != AVERROR(EOF)) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
avcodec_close(this->context);
avcodec_free_context(&this->context);
}