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));
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;
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);
}