}
if (got_packet) {
- if (pkt.pts != AV_NOPTS_VALUE)
- pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);
- if (pkt.dts != AV_NOPTS_VALUE)
- pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
- if (pkt.duration > 0)
- pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base);
-
+ av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
write_frame(s, &pkt, ost);
}
}
in_picture->top_field_first = !!ost->top_field_first;
in_picture->quality = enc->global_quality;
- if (!enc->me_threshold)
- in_picture->pict_type = 0;
+ in_picture->pict_type = 0;
if (ost->forced_kf_index < ost->forced_kf_count &&
in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
in_picture->pict_type = AV_PICTURE_TYPE_I;
}
if (got_packet) {
- if (pkt.pts != AV_NOPTS_VALUE)
- pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);
- if (pkt.dts != AV_NOPTS_VALUE)
- pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
-
+ av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
write_frame(s, &pkt, ost);
*frame_size = pkt.size;
return 0;
}
+static void finish_output_stream(OutputStream *ost)
+{
+ OutputFile *of = output_files[ost->file_index];
+ int i;
+
+ ost->finished = 1;
+
+ if (of->shortest) {
+ for (i = 0; i < of->ctx->nb_streams; i++)
+ output_streams[of->ost_index + i]->finished = 1;
+ }
+}
+
/*
* Read as many frames from possible from lavfi and encode them.
*
*/
static int poll_filters(void)
{
- int i, j, ret = 0;
+ int i, ret = 0;
while (ret >= 0 && !received_sigterm) {
OutputStream *ost = NULL;
ret = poll_filter(ost);
if (ret == AVERROR_EOF) {
- OutputFile *of = output_files[ost->file_index];
-
- ost->finished = 1;
-
- if (of->shortest) {
- for (j = 0; j < of->ctx->nb_streams; j++)
- output_streams[of->ost_index + j]->finished = 1;
- }
-
+ finish_output_stream(ost);
ret = 0;
} else if (ret == AVERROR(EAGAIN))
return 0;
if (!is_last_report) {
int64_t cur_time;
/* display the report every 0.5 seconds */
- cur_time = av_gettime();
+ cur_time = av_gettime_relative();
if (last_time == -1) {
last_time = cur_time;
return;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q);
}
if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
- float t = (av_gettime() - timer_start) / 1000000.0;
+ float t = (av_gettime_relative() - timer_start) / 1000000.0;
frame_number = ost->frame_number;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ",
stop_encoding = 1;
break;
}
- if (pkt.pts != AV_NOPTS_VALUE)
- pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);
- if (pkt.dts != AV_NOPTS_VALUE)
- pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
- if (pkt.duration > 0)
- pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base);
+ av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
write_frame(os, &pkt, ost);
}
}
/* pkt = NULL means EOF (needed to flush decoder buffers) */
-static int output_packet(InputStream *ist, const AVPacket *pkt)
+static int process_input_packet(InputStream *ist, const AVPacket *pkt)
{
int i;
int got_output;
if (ist->next_dts == AV_NOPTS_VALUE)
ist->next_dts = ist->last_dts;
- if (pkt == NULL) {
+ if (!pkt) {
/* EOF handling */
av_init_packet(&avpkt);
avpkt.data = NULL;
else if (ist->st->avg_frame_rate.num)
ist->next_dts += av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate),
AV_TIME_BASE_Q);
- else if (ist->dec_ctx->time_base.num != 0) {
+ else if (ist->dec_ctx->framerate.num != 0) {
int ticks = ist->st->parser ? ist->st->parser->repeat_pict + 1 :
ist->dec_ctx->ticks_per_frame;
- ist->next_dts += av_rescale_q(ticks, ist->dec_ctx->time_base, AV_TIME_BASE_Q);
+ ist->next_dts += av_rescale_q(ticks, ist->dec_ctx->framerate, AV_TIME_BASE_Q);
}
break;
case AVMEDIA_TYPE_SUBTITLE:
ist->dec_ctx->sample_rate;
break;
case AVMEDIA_TYPE_VIDEO:
- if (ist->dec_ctx->time_base.num != 0) {
+ if (ist->dec_ctx->framerate.num != 0) {
int ticks = ist->st->parser ? ist->st->parser->repeat_pict + 1 : ist->dec_ctx->ticks_per_frame;
ist->next_dts += ((int64_t)AV_TIME_BASE *
- ist->dec_ctx->time_base.num * ticks) /
- ist->dec_ctx->time_base.den;
+ ist->dec_ctx->framerate.den * ticks) /
+ ist->dec_ctx->framerate.num;
}
break;
}
InputFile *ifile = input_files[i];
if (ifile->rate_emu)
for (j = 0; j < ifile->nb_streams; j++)
- input_streams[j + ifile->ist_index]->start = av_gettime();
+ input_streams[j + ifile->ist_index]->start = av_gettime_relative();
}
/* output stream init */
} else
enc_ctx->time_base = ist->st->time_base;
+ if (ist->st->nb_side_data) {
+ ost->st->side_data = av_realloc_array(NULL, ist->st->nb_side_data,
+ sizeof(*ist->st->side_data));
+ if (!ost->st->side_data)
+ return AVERROR(ENOMEM);
+
+ for (j = 0; j < ist->st->nb_side_data; j++) {
+ const AVPacketSideData *sd_src = &ist->st->side_data[j];
+ AVPacketSideData *sd_dst = &ost->st->side_data[j];
+
+ sd_dst->data = av_malloc(sd_src->size);
+ if (!sd_dst->data)
+ return AVERROR(ENOMEM);
+ memcpy(sd_dst->data, sd_src->data, sd_src->size);
+ sd_dst->size = sd_src->size;
+ sd_dst->type = sd_src->type;
+ ost->st->nb_side_data++;
+ }
+ }
+
ost->parser = av_parser_init(enc_ctx->codec_id);
switch (enc_ctx->codec_type) {
av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
"It takes bits/s as argument, not kbits/s\n");
} else {
- av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts);
+ ret = av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts);
+ if (ret < 0)
+ return ret;
}
ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx);
"Error initializing the output stream codec context.\n");
exit_program(1);
}
+
+ ost->st->time_base = ost->enc_ctx->time_base;
}
/* init input streams */
if (out_codec) {
encoder_name = out_codec->name;
out_codec_name = avcodec_descriptor_get(out_codec->id)->name;
- if (!strcmp(encoder_name, in_codec_name))
+ if (!strcmp(encoder_name, out_codec_name))
encoder_name = "native";
}
for (i = 0; i < f->nb_streams; i++) {
InputStream *ist = input_streams[f->ist_index + i];
int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);
- int64_t now = av_gettime() - ist->start;
+ int64_t now = av_gettime_relative() - ist->start;
if (pts > now)
return AVERROR(EAGAIN);
}
for (i = 0; i < ifile->nb_streams; i++) {
ist = input_streams[ifile->ist_index + i];
if (ist->decoding_needed)
- output_packet(ist, NULL);
+ process_input_packet(ist, NULL);
/* mark all outputs that don't go through lavfi as finished */
for (j = 0; j < nb_output_streams; j++) {
if (ost->source_index == ifile->ist_index + i &&
(ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE))
- ost->finished= 1;
+ finish_output_stream(ost);
}
}
if (pkt.dts != AV_NOPTS_VALUE)
pkt.dts *= ist->ts_scale;
- if (pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
+ if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||
+ ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
+ pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
(is->iformat->flags & AVFMT_TS_DISCONT)) {
int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
int64_t delta = pkt_dts - ist->next_dts;
}
}
- ret = output_packet(ist, &pkt);
+ ret = process_input_packet(ist, &pkt);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d\n",
ist->file_index, ist->st->index);
av_log(NULL, AV_LOG_INFO, "Press ctrl-c to stop encoding\n");
term_init();
- timer_start = av_gettime();
+ timer_start = av_gettime_relative();
#if HAVE_PTHREADS
if ((ret = init_input_threads()) < 0)
for (i = 0; i < nb_input_streams; i++) {
ist = input_streams[i];
if (!input_files[ist->file_index]->eof_reached && ist->decoding_needed) {
- output_packet(ist, NULL);
+ process_input_packet(ist, NULL);
}
}
poll_filters();
GetProcessTimes(proc, &c, &e, &k, &u);
return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
#else
- return av_gettime();
+ return av_gettime_relative();
#endif
}