From de4fb3643aa02b6052d62635e9000850d887cc7a Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Wed, 12 Apr 2023 14:13:40 +0800 Subject: [PATCH] fix: video / audio pts of output --- simp_ffmpeg_output.c | 14 ++++++-------- simp_filter.c | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/simp_ffmpeg_output.c b/simp_ffmpeg_output.c index ab38f25..7ab5ba8 100644 --- a/simp_ffmpeg_output.c +++ b/simp_ffmpeg_output.c @@ -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); diff --git a/simp_filter.c b/simp_filter.c index 91fe4e8..490f30d 100644 --- a/simp_filter.c +++ b/simp_filter.c @@ -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; -- 2.25.1