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;
int ret = avcodec_send_frame(c, frame);
if (ret < 0) {
while (ret >= 0) {
ret = avcodec_receive_packet(c, pkt);
- if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
+ if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
break;
- else if (ret < 0) {
+ } else if (ret < 0) {
scf_loge("avcodec_receive_packet error, ret: %s\n", av_err2str(ret));
return ret;
}
- scf_logw("idx: %d, frame->pts: %ld, pkt->stream_index: %d, pkt->pts: %ld\n", idx, frame->pts, pkt->stream_index, pkt->pts);
+ 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);
ret = av_write_frame(priv->fmt_ctx, pkt);
av_packet_unref(pkt);
scf_list_del(&f->list);
pthread_mutex_unlock(&io->mutex);
+ scf_logd("priv->vidx: %d, frame->pts: %ld\n", priv->vidx, f->frame->pts);
+
ret = __ffmpeg_encode(io, priv->vcodec_ctx, priv->vpkt, f->frame, priv->vidx);
simp_frame_free(f);
ret = av_audio_fifo_write(priv->afifo, (void**)f->frame->data, f->frame->nb_samples);
+ scf_logd("priv->aidx: %d, frame->pts: %ld, frame->nb_samples: %d, afifo->size: %d\n",
+ priv->aidx, f->frame->pts, f->frame->nb_samples, av_audio_fifo_size(priv->afifo));
+
simp_frame_free(f);
f = NULL;
goto end;
}
+ priv->nb_samples += priv->aframe->nb_samples;
+ priv->aframe->pts = priv->nb_samples;
+
+ scf_logd("aframe->pts: %ld\n", priv->aframe->pts);
+
ret = __ffmpeg_encode(io, priv->acodec_ctx, priv->apkt, priv->aframe, priv->aidx);
if (ret < 0) {
io->error = ret;
io->nb_vframes--;
pthread_mutex_unlock(&io->mutex);
- scf_logw("vf->pts: %ld, vtime: %ld, time: %ld, nb_vframes: %d\n", vf->frame->pts, vtime, time, io->nb_vframes);
+ scf_logd("vf->pts: %ld, vtime: %ld, time: %ld, nb_vframes: %d\n", vf->frame->pts, vtime, time, io->nb_vframes);
int ret = av_buffersrc_add_frame_flags(io->vbuffersrc_ctx, vf->frame, AV_BUFFERSRC_FLAG_KEEP_REF);
scf_list_del(&af->list);
pthread_mutex_unlock(&io->mutex);
- scf_logw("af->pts: %ld, atime: %ld, time: %ld\n", af->frame->pts, atime, time);
+ scf_logd("af->pts: %ld, atime: %ld, time: %ld\n", af->frame->pts, atime, time);
int ret = av_buffersrc_add_frame_flags(io->abuffersrc_ctx, af->frame, AV_BUFFERSRC_FLAG_KEEP_REF);
simp_frame_free(af);
goto error;
}
- scf_loge("f->frame->pts: %ld\n", f->vframe->pts);
-
- for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); l != scf_list_next(l)) {
+ for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); l = scf_list_next(l)) {
io = scf_list_data(l, simp_avio_t, list);
vf = calloc(1, sizeof(simp_frame_t));
goto error;
}
+ scf_logd("vf->frame->pts: %ld\n", vf->frame->pts);
+
pthread_mutex_lock(&io->mutex);
scf_list_add_tail(&io->vout, &vf->list);
pthread_cond_signal(&io->cond);
goto error;
}
- for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); l != scf_list_next(l)) {
+ for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); l = scf_list_next(l)) {
io = scf_list_data(l, simp_avio_t, list);
af = calloc(1, sizeof(simp_frame_t));
goto error;
}
- scf_logw("af->frame->pts: %ld\n", af->frame->pts);
+ scf_logd("af->frame->pts: %ld\n", af->frame->pts);
pthread_mutex_lock(&io->mutex);
scf_list_add_tail(&io->aout, &af->list);