encoder: Properly flush delayed encoders
This commit is contained in:
+15
-13
@@ -603,24 +603,26 @@ obsffmpeg::encoder::encoder(obs_data_t* settings, obs_encoder_t* encoder)
|
|||||||
|
|
||||||
obsffmpeg::encoder::~encoder()
|
obsffmpeg::encoder::~encoder()
|
||||||
{
|
{
|
||||||
|
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) >= 0) {
|
||||||
|
avcodec_send_frame(this->context, nullptr);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close and free context.
|
||||||
|
avcodec_close(this->context);
|
||||||
|
avcodec_free_context(&this->context);
|
||||||
|
}
|
||||||
|
|
||||||
av_packet_unref(&this->current_packet);
|
av_packet_unref(&this->current_packet);
|
||||||
|
|
||||||
this->frame_queue.clear();
|
this->frame_queue.clear();
|
||||||
this->frame_queue_used.clear();
|
this->frame_queue_used.clear();
|
||||||
this->swscale.finalize();
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void obsffmpeg::encoder::get_properties(obs_properties_t* props)
|
void obsffmpeg::encoder::get_properties(obs_properties_t* props)
|
||||||
|
|||||||
Reference in New Issue
Block a user