tmp
authoryu.dongliang <18588496441@163.com>
Wed, 12 Apr 2023 07:11:15 +0000 (15:11 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 12 Apr 2023 07:11:15 +0000 (15:11 +0800)
simp_ffmpeg_input.c

index 496326e803152ccf6a114bbb61e0d781eb7b3ab9..baa55ee8975b1c55ca27c2cbb54ac30380cc84ca 100644 (file)
@@ -121,6 +121,8 @@ static int _ffmpeg_input_open(simp_avio_t* io, const char* path)
        }
 
        if (priv->vidx >= 0) {
+               s   = priv->fmt_ctx->streams[priv->vidx];
+
                ret = _video_init(priv);
                if (ret < 0)
                        goto error;
@@ -128,12 +130,15 @@ static int _ffmpeg_input_open(simp_avio_t* io, const char* path)
                io->width               = priv->vcodec_ctx->width;
                io->height              = priv->vcodec_ctx->height;
                io->pix_fmt             = priv->vcodec_ctx->pix_fmt;
-               io->frame_rate          = priv-> fmt_ctx->streams[priv->vidx]->r_frame_rate;
+               io->frame_rate.num      = s->r_frame_rate.den;
+               io->frame_rate.den      = s->r_frame_rate.num;
                io->sample_aspect_ratio = priv->vcodec_ctx->sample_aspect_ratio;
 
                io->x     = 0;
                io->y     = 0;
                io->vopen = 1;
+
+               scf_loge("io->frame_rate: %d:%d\n", io->frame_rate.num, io->frame_rate.den);
        }
 
        if (priv->aidx >= 0) {
@@ -145,6 +150,8 @@ static int _ffmpeg_input_open(simp_avio_t* io, const char* path)
                io->sample_rate = priv->acodec_ctx->time_base;
                io->channels    = priv->acodec_ctx->channels;
                io->aopen       = 1;
+
+               scf_loge("io->sample_rate: %d:%d\n", io->sample_rate.num, io->sample_rate.den);
        }
 
        io->priv = priv;
@@ -248,20 +255,18 @@ static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* p
                if (nb_vframes) {
                        (*nb_vframes)++;
 
-                       io->frame_rate.num = s->r_frame_rate.den;
-                       io->frame_rate.den = s->r_frame_rate.num;
-
                        f->frame->pts = f->frame->pts * av_q2d(s->time_base) / av_q2d(io->frame_rate);
 
-                       scf_logd("frame->pts: %ld, stream_index: %d, s->r_frame_rate: %d:%d, s->time_base: %d:%d\n",
+                       scf_logi("frame->pts: %ld, stream_index: %d, io->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,
+                                       io->frame_rate.num, io->frame_rate.den,
                                        s->time_base.num, s->time_base.den);
                } else {
-                       io->sample_rate = s->time_base;
+                       f->frame->pts = f->frame->pts * av_q2d(s->time_base) / av_q2d(io->sample_rate);
 
-                       scf_logd("frame->pts: %ld, stream_index: %d, s->time_base: %d:%d\n",
+                       scf_logi("frame->pts: %ld, stream_index: %d, io->sample_rate: %d:%d, s->time_base: %d:%d\n",
                                        frame->pts, pkt->stream_index,
+                                       io->sample_rate.num, io->sample_rate.den,
                                        s->time_base.num, s->time_base.den);
                }