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);
+ f->frame->pts = f->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",
+ scf_logd("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",
+ scf_logd("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);
}
AVStream* s;
AVCodec* c;
- c = avcodec_find_encoder(priv->fmt_ctx->oformat->video_codec);
+ c = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!c)
return -EINVAL;
priv->vcodec_ctx->gop_size = 30;
priv->vcodec_ctx->max_b_frames = 2;
priv->vcodec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
+ priv->vcodec_ctx->sample_aspect_ratio = (AVRational){16, 9};
s->time_base = priv->vcodec_ctx->time_base;
if (priv->fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
int ret = avcodec_open2(priv->vcodec_ctx, c, NULL);
if (ret < 0) {
- printf("avcodec_parameters_to_context error, ret: %d, %s\n", ret, av_err2str(ret));
+ scf_loge("avcodec_open2 error, ret: %d, %s\n", ret, av_err2str(ret));
+ return ret;
+ }
+
+ ret = avcodec_parameters_from_context(s->codecpar, priv->vcodec_ctx);
+ if (ret < 0) {
+ scf_loge("avcodec_parameters_from_context error, ret: %d, %s\n", ret, av_err2str(ret));
return ret;
}
AVStream* s;
AVCodec* c;
- c = avcodec_find_encoder(priv->fmt_ctx->oformat->audio_codec);
+ c = avcodec_find_encoder(AV_CODEC_ID_AAC);
if (!c)
return -EINVAL;
int ret = avcodec_open2(priv->acodec_ctx, c, NULL);
if (ret < 0) {
- printf("avcodec_parameters_to_context error, ret: %d, %s\n", ret, av_err2str(ret));
+ scf_loge("avcodec_parameters_to_context error, ret: %d, %s\n", ret, av_err2str(ret));
+ return ret;
+ }
+
+ ret = avcodec_parameters_from_context(s->codecpar, priv->acodec_ctx);
+ if (ret < 0) {
+ scf_loge("avcodec_parameters_from_context error, ret: %d, %s\n", ret, av_err2str(ret));
return ret;
}
simp_frame_t* f;
scf_list_t* l;
+ int ret = 0;
+
+ av_dump_format(priv->fmt_ctx, 0, priv->fmt_ctx->url, 1);
+
+ if (!(priv->fmt_ctx->oformat->flags & AVFMT_NOFILE)) {
+
+ ret = avio_open(&priv->fmt_ctx->pb, priv->fmt_ctx->url, AVIO_FLAG_WRITE);
+ if (ret < 0) {
+ scf_loge("Could not open output file '%s'", priv->fmt_ctx->url);
+ goto end;
+ }
+ }
+
+ ret = avformat_write_header(priv->fmt_ctx, NULL);
+ if (ret < 0) {
+ scf_loge("avformat_write_header error, ret: %s\n", av_err2str(ret));
+ goto end;
+ }
+
while (!io->exit) {
pthread_mutex_lock(&io->mutex);
scf_list_del(&f->list);
pthread_mutex_unlock(&io->mutex);
- int ret = __ffmpeg_encode(io, priv->vcodec_ctx, priv->vpkt, f->frame);
+ scf_logw("frame->pts: %ld\n", f->frame->pts);
+
+ ret = __ffmpeg_encode(io, priv->vcodec_ctx, priv->vpkt, f->frame);
simp_frame_free(f);
f = NULL;
scf_list_del(&f->list);
pthread_mutex_unlock(&io->mutex);
- int ret = av_audio_fifo_write(priv->afifo, (void**)f->frame->data, f->frame->nb_samples);
+ scf_logw("frame->pts: %ld\n", f->frame->pts);
+
+ ret = av_audio_fifo_write(priv->afifo, (void**)f->frame->data, f->frame->nb_samples);
simp_frame_free(f);
f = NULL;
}
const enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE};
- const enum AVSampleFormat sample_fmts[] = {AV_SAMPLE_FMT_S16, -1};
+ const enum AVSampleFormat sample_fmts[] = {AV_SAMPLE_FMT_FLTP, -1};
const int sample_rates[] = {44100, -1 };
const int64_t layouts[] = {AV_CH_LAYOUT_STEREO, -1};
io->nb_vframes--;
pthread_mutex_unlock(&io->mutex);
- scf_logi("vf->pts: %ld, vtime: %ld, time: %ld, nb_vframes: %d\n", vf->frame->pts, vtime, time, io->nb_vframes);
+ scf_logw("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_logi("af->pts: %ld, atime: %ld, time: %ld\n", af->frame->pts, atime, time);
+ scf_logw("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);
int vn = 0;
int an = 0;
- for (l = scf_list_head(&f->inputs); l != scf_list_sentinel(&f->inputs); l != scf_list_next(l)) {
+ sleep(2);
+
+ for (l = scf_list_head(&f->inputs); l != scf_list_sentinel(&f->inputs); l = scf_list_next(l)) {
io = scf_list_data(l, simp_avio_t, list);
if (io->start_time == 0)
int ret = av_buffersink_get_frame(f->vbuffersink_ctx, f->vframe);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
+ scf_loge("\n");
break;
} else if (ret < 0) {
scf_loge("av_buffersink_get_frame error, ret: %s\n", av_err2str(ret));
goto error;
}
+ scf_logw("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)) {
io = scf_list_data(l, simp_avio_t, list);
int ret = av_buffersink_get_frame(f->abuffersink_ctx, f->aframe);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
+ scf_loge("\n");
break;
} else if (ret < 0) {
scf_loge("av_buffersink_get_frame error, ret: %s\n", av_err2str(ret));
goto error;
}
+ scf_logw("af->frame->pts: %ld\n", af->frame->pts);
+
pthread_mutex_lock(&io->mutex);
scf_list_add_tail(&io->aout, &af->list);
pthread_cond_signal(&io->cond);