fix: video / audio pts of output
authoryu.dongliang <18588496441@163.com>
Wed, 12 Apr 2023 06:13:40 +0000 (14:13 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 12 Apr 2023 06:13:40 +0000 (14:13 +0800)
simp_ffmpeg_output.c
simp_filter.c

index ab38f256e8b7344ed2a74dac132e82583d1d9156..7ab5ba8228bf181de5682e357bc8bc91a872b18f 100644 (file)
@@ -25,7 +25,7 @@ static int _video_init(simp_ffmpeg_t* priv)
        priv->vcodec_ctx->bit_rate     = 1024 * 1024;
        priv->vcodec_ctx->width        = 1920;
        priv->vcodec_ctx->height       = 1080;
-       priv->vcodec_ctx->time_base    = (AVRational){1, 25};
+       priv->vcodec_ctx->time_base    = (AVRational){1, 24};
        priv->vcodec_ctx->gop_size     = 30;
        priv->vcodec_ctx->max_b_frames = 1;
        priv->vcodec_ctx->pix_fmt      = AV_PIX_FMT_YUV420P;
@@ -250,7 +250,11 @@ static int _ffmpeg_output_close(simp_avio_t* io)
 static int __ffmpeg_encode(simp_avio_t* io, AVCodecContext* c, AVPacket* pkt, AVFrame* frame, int idx)
 {
        simp_ffmpeg_t* priv = io->priv;
-       AVStream*      s    = NULL;
+       AVStream*      s    = priv->fmt_ctx->streams[idx];
+
+       int64_t pts = frame->pts;
+
+       frame->pts = frame->pts * av_q2d(c->time_base) / av_q2d(s->time_base);
 
        int ret = avcodec_send_frame(c, frame);
        if (ret < 0) {
@@ -268,14 +272,8 @@ static int __ffmpeg_encode(simp_avio_t* io, AVCodecContext* c, AVPacket* pkt, AV
                        return ret;
                }
 
-               int64_t pts = pkt->pts;
-
-               s = priv->fmt_ctx->streams[idx];
-
                pkt->stream_index = idx;
 
-//             pkt->pts = pkt->pts * 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);
 
index 91fe4e8a622415e6eac896a1f3e3b0eac3286fbc..490f30dc1f37326ad031f38b46b9c7b32361aef0 100644 (file)
@@ -75,6 +75,8 @@ static int _init_filters(simp_filter_t* f)
                                        av_get_sample_fmt_name(io->sample_fmt),
                                        av_get_default_channel_layout(io->channels));
 
+                       printf("%s\n", args);
+
                        ret = avfilter_graph_create_filter(&io->abuffersrc_ctx, abuffersrc, "in", args, NULL, f->agraph);
                        if (ret < 0)
                                goto end;