flush audio / video in encoder
authoryu.dongliang <18588496441@163.com>
Wed, 12 Apr 2023 07:41:00 +0000 (15:41 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 12 Apr 2023 07:41:00 +0000 (15:41 +0800)
simp_ffmpeg_output.c

index 9991892b170cbcb28aa5b5efe0c6e0b4661cfda9..70e0be839cb6ed5c044b3b69874f274620169bb8 100644 (file)
@@ -252,8 +252,6 @@ static int __ffmpeg_encode(simp_avio_t* io, AVCodecContext* c, AVPacket* pkt, AV
        simp_ffmpeg_t* priv = io->priv;
        AVStream*      s    = priv->fmt_ctx->streams[idx];
 
-       int64_t pts = frame->pts;
-
        int ret = avcodec_send_frame(c, frame);
        if (ret < 0) {
                scf_loge("avcodec_send_frame error, ret: %s\n", av_err2str(ret));
@@ -275,8 +273,8 @@ static int __ffmpeg_encode(simp_avio_t* io, AVCodecContext* c, AVPacket* pkt, AV
                pkt->pts = pkt->pts * av_q2d(c->time_base) / av_q2d(s->time_base);
                pkt->dts = pkt->dts * av_q2d(c->time_base) / av_q2d(s->time_base);
 
-               scf_logw("idx: %d, frame->pts: %ld, pkt->stream_index: %d, pkt->pts: %ld, pts: %ld, c->time_base: %d:%d, s->time_base: %d:%d\n",
-                               idx, frame->pts, pkt->stream_index, pkt->pts, pts, c->time_base.num, c->time_base.den, s->time_base.num, s->time_base.den);
+               scf_logw("idx: %d, pkt->stream_index: %d, pkt->pts: %ld, c->time_base: %d:%d, s->time_base: %d:%d\n",
+                               idx, pkt->stream_index, pkt->pts, c->time_base.num, c->time_base.den, s->time_base.num, s->time_base.den);
 
                ret = av_write_frame(priv->fmt_ctx, pkt);
                av_packet_unref(pkt);
@@ -413,6 +411,11 @@ static void* __ffmpeg_output_run(void* arg)
                f = NULL;
        }
 
+       ret = __ffmpeg_encode(io, priv->vcodec_ctx, priv->vpkt, NULL, priv->vidx);
+       if (ret < 0)
+               scf_loge("ret: %d\n", ret);
+       io->error = ret;
+
        while (!scf_list_empty(&io->aout)) {
                l = scf_list_head(&io->aout);
                f = scf_list_data(l, simp_frame_t, list);
@@ -456,6 +459,12 @@ static void* __ffmpeg_output_run(void* arg)
                        }
                }
        }
+
+       ret = __ffmpeg_encode(io, priv->acodec_ctx, priv->apkt, NULL, priv->aidx);
+       if (ret < 0)
+               scf_loge("ret: %d\n", ret);
+       io->error = ret;
+
        pthread_mutex_unlock(&io->mutex);
 
 end: