}
ost->bitstream_filters = NULL;
av_frame_free(&ost->filtered_frame);
+ av_frame_free(&ost->last_frame);
av_parser_close(ost->parser);
while (bsfc) {
AVPacket new_pkt = *pkt;
- int a = av_bitstream_filter_filter(bsfc, avctx, NULL,
+ AVDictionaryEntry *bsf_arg = av_dict_get(ost->bsf_args,
+ bsfc->filter->name,
+ NULL, 0);
+ int a = av_bitstream_filter_filter(bsfc, avctx,
+ bsf_arg ? bsf_arg->value : NULL,
&new_pkt.data, &new_pkt.size,
pkt->data, pkt->size,
pkt->flags & AV_PKT_FLAG_KEY);
if (!subtitle_out) {
subtitle_out = av_malloc(subtitle_out_max_size);
+ if (!subtitle_out) {
+ av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n");
+ exit_program(1);
+ }
}
/* Note: DVB subtitle need one packet to draw them and one other
static void do_video_out(AVFormatContext *s,
OutputStream *ost,
- AVFrame *in_picture)
+ AVFrame *next_picture)
{
int ret, format_video_sync;
AVPacket pkt;
AVCodecContext *enc = ost->enc_ctx;
AVCodecContext *mux_enc = ost->st->codec;
- int nb_frames, i;
- double sync_ipts, delta;
+ int nb_frames, nb0_frames, i;
+ double sync_ipts, delta, delta0;
double duration = 0;
int frame_size = 0;
InputStream *ist = NULL;
if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
duration = 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base));
- sync_ipts = in_picture->pts;
- delta = sync_ipts - ost->sync_opts + duration;
+ if (!ost->filters_script &&
+ !ost->filters &&
+ next_picture &&
+ ist &&
+ lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)) > 0) {
+ duration = lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base));
+ }
+
+ sync_ipts = next_picture->pts;
+ delta0 = sync_ipts - ost->sync_opts;
+ delta = delta0 + duration;
/* by default, we output a single frame */
+ nb0_frames = 0;
nb_frames = 1;
format_video_sync = video_sync_method;
}
}
+ if (delta0 < 0 &&
+ delta > 0 &&
+ format_video_sync != VSYNC_PASSTHROUGH &&
+ format_video_sync != VSYNC_DROP) {
+ double cor = FFMIN(-delta0, duration);
+ av_log(NULL, AV_LOG_WARNING, "Past duration %f too large\n", -delta0);
+ sync_ipts += cor;
+ duration -= cor;
+ delta0 += cor;
+ }
+
switch (format_video_sync) {
case VSYNC_VSCFR:
if (ost->frame_number == 0 && delta - duration >= 0.5) {
av_log(NULL, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta - duration));
delta = duration;
+ delta0 = 0;
ost->sync_opts = lrint(sync_ipts);
}
case VSYNC_CFR:
// FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
if (delta < -1.1)
nb_frames = 0;
- else if (delta > 1.1)
+ else if (delta > 1.1) {
nb_frames = lrintf(delta);
+ if (delta0 > 1.1)
+ nb0_frames = lrintf(delta0 - 0.6);
+ }
break;
case VSYNC_VFR:
if (delta <= -0.6)
}
nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number);
- if (nb_frames == 0) {
+ nb0_frames = FFMIN(nb0_frames, nb_frames);
+ if (nb0_frames == 0 && ost->last_droped) {
nb_frames_drop++;
av_log(NULL, AV_LOG_VERBOSE,
"*** dropping frame %d from stream %d at ts %"PRId64"\n",
- ost->frame_number, ost->st->index, in_picture->pts);
- return;
- } else if (nb_frames > 1) {
+ ost->frame_number, ost->st->index, ost->last_frame->pts);
+ }
+ if (nb_frames > (nb0_frames && ost->last_droped) + (nb_frames > nb0_frames)) {
if (nb_frames > dts_error_threshold * 30) {
av_log(NULL, AV_LOG_ERROR, "%d frame duplication too large, skipping\n", nb_frames - 1);
nb_frames_drop++;
return;
}
- nb_frames_dup += nb_frames - 1;
+ nb_frames_dup += nb_frames - (nb0_frames && ost->last_droped) - (nb_frames > nb0_frames);
av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1);
}
+ ost->last_droped = nb_frames == nb0_frames;
/* duplicates frame if needed */
for (i = 0; i < nb_frames; i++) {
+ AVFrame *in_picture;
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
+ if (i < nb0_frames && ost->last_frame) {
+ in_picture = ost->last_frame;
+ } else
+ in_picture = next_picture;
+
in_picture->pts = ost->sync_opts;
#if 1
/* raw pictures are written as AVPicture structure to
avoid any copies. We support temporarily the older
method. */
- mux_enc->coded_frame->interlaced_frame = in_picture->interlaced_frame;
- mux_enc->coded_frame->top_field_first = in_picture->top_field_first;
- if (mux_enc->coded_frame->interlaced_frame)
- mux_enc->field_order = mux_enc->coded_frame->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
+ if (in_picture->interlaced_frame)
+ mux_enc->field_order = in_picture->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
else
mux_enc->field_order = AV_FIELD_PROGRESSIVE;
pkt.data = (uint8_t *)in_picture;
if (vstats_filename && frame_size)
do_video_stats(ost, frame_size);
}
+
+ if (!ost->last_frame)
+ ost->last_frame = av_frame_alloc();
+ av_frame_unref(ost->last_frame);
+ av_frame_ref(ost->last_frame, next_picture);
}
static double psnr(double d)
if (data_size && total_size>0 && total_size >= data_size)
percent = 100.0 * (total_size - data_size) / data_size;
- av_log(NULL, AV_LOG_INFO, "\n");
av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
video_size / 1024.0,
audio_size / 1024.0,
if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE)
pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st),
ost->st->time_base, AV_TIME_BASE_Q));
+ if (is_last_report)
+ nb_frames_drop += ost->last_droped;
}
secs = pts / AV_TIME_BASE;
av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop);
if (print_stats || is_last_report) {
+ const char end = is_last_report ? '\n' : '\r';
if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
- fprintf(stderr, "%s \r", buf);
+ fprintf(stderr, "%s %c", buf, end);
} else
- av_log(NULL, AV_LOG_INFO, "%s \r", buf);
+ av_log(NULL, AV_LOG_INFO, "%s %c", buf, end);
fflush(stderr);
}
if (*got_output || ret<0 || pkt->size)
decode_error_stat[ret<0] ++;
+ if (*got_output && ret >= 0) {
+ if (ist->dec_ctx->width != decoded_frame->width ||
+ ist->dec_ctx->height != decoded_frame->height ||
+ ist->dec_ctx->pix_fmt != decoded_frame->format) {
+ av_log(NULL, AV_LOG_DEBUG, "Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n",
+ decoded_frame->width,
+ decoded_frame->height,
+ decoded_frame->format,
+ ist->dec_ctx->width,
+ ist->dec_ctx->height,
+ ist->dec_ctx->pix_fmt);
+ }
+ }
+
if (!*got_output || ret < 0) {
if (!pkt->size) {
for (i = 0; i < ist->nb_filters; i++)
sar = dec_ctx->sample_aspect_ratio;
ost->st->sample_aspect_ratio = enc_ctx->sample_aspect_ratio = sar;
ost->st->avg_frame_rate = ist->st->avg_frame_rate;
+ ost->st->r_frame_rate = ist->st->r_frame_rate;
break;
case AVMEDIA_TYPE_SUBTITLE:
enc_ctx->width = dec_ctx->width;
av_dict_free(&ost->encoder_opts);
av_dict_free(&ost->swr_opts);
av_dict_free(&ost->resample_opts);
+ av_dict_free(&ost->bsf_args);
}
}
}