__ffmpeg_decode
authoryu.dongliang <18588496441@163.com>
Sun, 9 Apr 2023 07:46:34 +0000 (15:46 +0800)
committeryu.dongliang <18588496441@163.com>
Sun, 9 Apr 2023 07:46:34 +0000 (15:46 +0800)
simp_ffmpeg_input.c

index 670f8cb976fd187be383c509d65ddb2a48d5a867..a1fb0ee99c45463e309000bb9ba37b076fb33734 100644 (file)
@@ -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);
        }