ffmpegencoder: fixed bug that failed to flush the audio encoder

For some reason, when the encoder closed it only flushed the video encoder and
not the audio encoder. Now it does both.
This commit is contained in:
itsmattkc
2020-03-31 12:09:43 +11:00
parent 26d02e82ad
commit 7328a813f9
2 changed files with 28 additions and 18 deletions
+14 -5
View File
@@ -422,25 +422,34 @@ bool FFmpegEncoder::SetupCodecContext(AVStream* stream, AVCodecContext* codec_ct
void FFmpegEncoder::FlushEncoders()
{
if (video_codec_ctx_) {
avcodec_send_frame(video_codec_ctx_, nullptr);
FlushCodecCtx(video_codec_ctx_, video_stream_);
}
if (audio_codec_ctx_) {
FlushCodecCtx(audio_codec_ctx_, audio_stream_);
}
}
void FFmpegEncoder::FlushCodecCtx(AVCodecContext *codec_ctx, AVStream* stream)
{
avcodec_send_frame(codec_ctx, nullptr);
AVPacket* pkt = av_packet_alloc();
int error_code;
do {
error_code = avcodec_receive_packet(video_codec_ctx_, pkt);
error_code = avcodec_receive_packet(codec_ctx, pkt);
if (error_code < 0) {
break;
}
pkt->stream_index = video_stream_->index;
av_packet_rescale_ts(pkt, video_codec_ctx_->time_base, video_stream_->time_base);
pkt->stream_index = stream->index;
av_packet_rescale_ts(pkt, codec_ctx->time_base, stream->time_base);
av_interleaved_write_frame(fmt_ctx_, pkt);
av_packet_unref(pkt);
} while (error_code >= 0);
av_packet_free(&pkt);
}
}
void FFmpegEncoder::Error(const QString &s)
+1
View File
@@ -51,6 +51,7 @@ private:
bool SetupCodecContext(AVStream *stream, AVCodecContext *codec_ctx, AVCodec *codec);
void FlushEncoders();
void FlushCodecCtx(AVCodecContext* codec_ctx, AVStream *stream);
AVFormatContext* fmt_ctx_;