From 937bc533ef16b17ee4744619596f129567d9d4b2 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sun, 9 Apr 2023 15:46:34 +0800 Subject: [PATCH] __ffmpeg_decode --- simp_ffmpeg_input.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/simp_ffmpeg_input.c b/simp_ffmpeg_input.c index 670f8cb..a1fb0ee 100644 --- a/simp_ffmpeg_input.c +++ b/simp_ffmpeg_input.c @@ -196,6 +196,10 @@ static int _ffmpeg_close(simp_avio_t* io) static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame, scf_list_t* h, int* nb_vframes) { + simp_ffmpeg_t* priv = io->priv; + simp_frame_t* f; + AVStream* s; + int ret = avcodec_send_packet(dec_ctx, pkt); if (ret < 0) { scf_loge("avcodec_send_packet error, ret: %s\n", av_err2str(ret)); @@ -214,9 +218,9 @@ static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* p frame->pts = frame->best_effort_timestamp; - scf_logi("frame->pts: %ld, stream_index: %d\n", frame->pts, pkt->stream_index); + s = priv->fmt_ctx->streams[pkt->stream_index]; - simp_frame_t* f = calloc(1, sizeof(simp_frame_t)); + f = calloc(1, sizeof(simp_frame_t)); if (!f) return -ENOMEM; @@ -227,9 +231,26 @@ static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* p pthread_mutex_lock(&io->mutex); scf_list_add_tail(h, &f->list); - if (nb_vframes) + if (nb_vframes) { (*nb_vframes)++; + io->frame_rate.num = s->r_frame_rate.den; + io->frame_rate.den = s->r_frame_rate.num; + + frame->pts = frame->pts * av_q2d(s->time_base) / av_q2d(io->frame_rate); + + scf_logi("frame->pts: %ld, stream_index: %d, s->r_frame_rate: %d:%d, s->time_base: %d:%d\n", + frame->pts, pkt->stream_index, + s->r_frame_rate.num, s->r_frame_rate.den, + s->time_base.num, s->time_base.den); + } else { + io->sample_rate = s->time_base; + + scf_logi("frame->pts: %ld, stream_index: %d, s->time_base: %d:%d\n", + frame->pts, pkt->stream_index, + s->time_base.num, s->time_base.den); + } + pthread_cond_signal(&io->cond); pthread_mutex_unlock(&io->mutex); } -- 2.25.1