static int debug_ts = 0;
static int current_time;
+static uint8_t *subtitle_out;
+
#if HAVE_PTHREADS
/* signal to input threads that they should exit; set by the main thread */
static int transcoding_finished;
int64_t *forced_kf_pts;
int forced_kf_count;
int forced_kf_index;
+ char *forced_keyframes;
/* audio only */
int audio_channels_map[SWR_CH_MAX]; /* list of the channels id to pick from the source stream */
memset(o, 0, sizeof(*o));
- if(is_input) o->recording_time = bak.recording_time;
- else o->recording_time = INT64_MAX;
+ if (is_input) {
+ o->recording_time = bak.recording_time;
+ if (o->recording_time != INT64_MAX)
+ av_log(NULL, AV_LOG_WARNING,
+ "-t is not an input option, keeping it for the next output;"
+ " consider fixing your command line.\n");
+ } else
+ o->recording_time = INT64_MAX;
o->mux_max_delay = 0.7;
o->limit_filesize = UINT64_MAX;
o->chapters_input_file = INT_MAX;
exit_program(1);
}
}
+ av_assert0(ist);
+
ist->discard = 0;
ist->decoding_needed = 1;
ist->st->discard = AVDISCARD_NONE;
snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);
ret = avfilter_graph_create_filter(&ofilter->filter,
- avfilter_get_by_name("abuffersink_old"),
+ avfilter_get_by_name("abuffersink"),
name, NULL, NULL, fg->graph);
if (ret < 0)
return ret;
snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s"
":channel_layout=0x%"PRIx64,
- ist->st->time_base.num, ist->st->time_base.den,
+ 1, ist->st->codec->sample_rate,
ist->st->codec->sample_rate,
av_get_sample_fmt_name(ist->st->codec->sample_fmt),
ist->st->codec->channel_layout);
}
av_freep(&filtergraphs);
+ av_freep(&subtitle_out);
+
/* close files */
for (i = 0; i < nb_output_files; i++) {
AVFormatContext *s = output_files[i]->ctx;
}
output_streams[i]->bitstream_filters = NULL;
+ av_freep(&output_streams[i]->forced_keyframes);
av_freep(&output_streams[i]->filtered_frame);
av_freep(&output_streams[i]->avfilter);
av_freep(&output_streams[i]);
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
-#if 0
+
if (!check_recording_time(ost))
return;
-#endif
+
if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
frame->pts = ost->sync_opts;
ost->sync_opts = frame->pts + frame->nb_samples;
AVSubtitle *sub,
int64_t pts)
{
- static uint8_t *subtitle_out = NULL;
int subtitle_out_max_size = 1024 * 1024;
int subtitle_out_size, nb, i;
AVCodecContext *enc;
for (i = 0; i < nb; i++) {
ost->sync_opts = av_rescale_q(pts, ist->st->time_base, enc->time_base);
+ if (!check_recording_time(ost))
+ return;
sub->pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q);
// start_display_time is required to be 0
av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n");
return;
} else if (nb_frames > 1) {
+ if (nb_frames > dts_error_threshold * 30) {
+ av_log(NULL, AV_LOG_ERROR, "%d frame duplication too large, skiping\n", nb_frames - 1);
+ nb_frames_drop++;
+ return;
+ }
nb_frames_dup += nb_frames - 1;
av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1);
}
in_picture->pts = ost->sync_opts;
+ if (!check_recording_time(ost))
+ return;
+
if (s->oformat->flags & AVFMT_RAWPICTURE &&
enc->codec->id == CODEC_ID_RAWVIDEO) {
/* raw pictures are written as AVPicture structure to
avcodec_get_frame_defaults(ost->filtered_frame);
filtered_frame = ost->filtered_frame;
- while (!ost->is_past_recording_time) {
- if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
- !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
- ret = av_buffersink_read_samples(ost->filter->filter, &picref,
- ost->st->codec->frame_size);
- else if(ost->enc->type == AVMEDIA_TYPE_AUDIO)
- ret = av_buffersink_read(ost->filter->filter, &picref);
- else
- ret = av_buffersink_get_buffer_ref(ost->filter->filter, &picref,
- AV_BUFFERSINK_FLAG_NO_REQUEST);
+ while (1) {
+ ret = av_buffersink_get_buffer_ref(ost->filter->filter, &picref,
+ AV_BUFFERSINK_FLAG_NO_REQUEST);
if (ret < 0) {
if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
char buf[256];
switch (ost->filter->filter->inputs[0]->type) {
case AVMEDIA_TYPE_VIDEO:
- avfilter_fill_frame_from_video_buffer_ref(filtered_frame, picref);
+ avfilter_copy_buf_props(filtered_frame, picref);
filtered_frame->pts = frame_pts;
if (!ost->frame_aspect_ratio)
ost->st->codec->sample_aspect_ratio = picref->video->sample_aspect_ratio;
if (of->start_time && ist->pts < of->start_time)
return 0;
- if (of->recording_time != INT64_MAX &&
- av_compare_ts(ist->pts, AV_TIME_BASE_Q, of->recording_time + of->start_time,
- (AVRational){ 1, 1000000 }) >= 0) {
- ost->is_past_recording_time = 1;
- return 0;
- }
-
return 1;
}
!ost->copy_initial_nonkeyframes)
return;
+ if (of->recording_time != INT64_MAX &&
+ ist->pts >= of->recording_time + of->start_time) {
+ ost->is_past_recording_time = 1;
+ return;
+ }
+
/* force the input stream PTS */
if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
audio_size += pkt->size;
ist->resample_channels = avctx->channels;
for (i = 0; i < nb_filtergraphs; i++)
- if (ist_in_filtergraph(filtergraphs[i], ist) &&
- configure_filtergraph(filtergraphs[i]) < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n");
- exit_program(1);
+ if (ist_in_filtergraph(filtergraphs[i], ist)) {
+ FilterGraph *fg = filtergraphs[i];
+ int j;
+ if (configure_filtergraph(fg) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n");
+ exit_program(1);
+ }
+ for (j = 0; j < fg->nb_outputs; j++) {
+ OutputStream *ost = fg->outputs[j]->ost;
+ if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
+ !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
+ av_buffersink_set_frame_size(ost->filter->filter,
+ ost->st->codec->frame_size);
+ }
}
}
+ if (decoded_frame->pts != AV_NOPTS_VALUE)
+ decoded_frame->pts = av_rescale_q(decoded_frame->pts,
+ ist->st->time_base,
+ (AVRational){1, ist->st->codec->sample_rate});
for (i = 0; i < ist->nb_filters; i++)
av_buffersrc_add_frame(ist->filters[i]->filter, decoded_frame, 0);
return NULL;
}
+static void parse_forced_key_frames(char *kf, OutputStream *ost,
+ AVCodecContext *avctx)
+{
+ char *p;
+ int n = 1, i;
+ int64_t t;
+
+ for (p = kf; *p; p++)
+ if (*p == ',')
+ n++;
+ ost->forced_kf_count = n;
+ ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n);
+ if (!ost->forced_kf_pts) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
+ exit_program(1);
+ }
+
+ p = kf;
+ for (i = 0; i < n; i++) {
+ char *next = strchr(p, ',');
+
+ if (next)
+ *next++ = 0;
+
+ t = parse_time_or_die("force_key_frames", p, 1);
+ ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
+
+ p = next;
+ }
+}
+
static int transcode_init(void)
{
int ret = 0, i, j, k;
codec->bits_per_raw_sample = frame_bits_per_raw_sample;
}
+ if (ost->forced_keyframes)
+ parse_forced_key_frames(ost->forced_keyframes, ost,
+ ost->st->codec);
break;
case AVMEDIA_TYPE_SUBTITLE:
codec->time_base = (AVRational){1, 1000};
ret = AVERROR(EINVAL);
goto dump_format;
}
+ if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
+ !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
+ av_buffersink_set_frame_size(ost->filter->filter,
+ ost->st->codec->frame_size);
assert_codec_experimental(ost->st->codec, 1);
assert_avoptions(ost->opts);
if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000)
METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
meta = &context->programs[index]->metadata;\
break;\
+ default: av_assert0(0);\
}\
SET_DICT(type_in, meta_in, ic, idx_in);
ist->file_index = nb_input_files;
ist->discard = 1;
st->discard = AVDISCARD_ALL;
- ist->opts = filter_codec_opts(codec_opts, choose_decoder(o, ic, st), ic, st);
+ ist->opts = filter_codec_opts(codec_opts, ist->st->codec->codec_id, ic, st, choose_decoder(o, ic, st));
ist->ts_scale = 1.0;
MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
return 0;
}
-static void parse_forced_key_frames(char *kf, OutputStream *ost)
-{
- char *p;
- int n = 1, i;
-
- for (p = kf; *p; p++)
- if (*p == ',')
- n++;
- ost->forced_kf_count = n;
- ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n);
- if (!ost->forced_kf_pts) {
- av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
- exit_program(1);
- }
- p = kf;
- for (i = 0; i < n; i++) {
- char *next = strchr(p, ',');
- if (next) *next++ = 0;
- ost->forced_kf_pts[i] = parse_time_or_die("force_key_frames", p, 1);
- p = next;
- }
-}
-
static uint8_t *get_line(AVIOContext *s)
{
AVIOContext *line;
st->codec->codec_type = type;
choose_encoder(o, oc, ost);
if (ost->enc) {
- ost->opts = filter_codec_opts(codec_opts, ost->enc, oc, st);
+ ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st, ost->enc);
}
avcodec_get_context_defaults3(st->codec, ost->enc);
if (!ost->stream_copy) {
const char *p = NULL;
- char *forced_key_frames = NULL, *frame_size = NULL;
+ char *frame_size = NULL;
char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL;
char *intra_matrix = NULL, *inter_matrix = NULL;
const char *filters = "null";
}
}
- MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st);
- if (forced_key_frames)
- parse_forced_key_frames(forced_key_frames, ost);
+ MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
+ if (ost->forced_keyframes)
+ ost->forced_keyframes = av_strdup(ost->forced_keyframes);
MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
"cannot be used together.\n", ost->file_index, ost->index);
exit_program(1);
}
+ if (o->recording_time != INT64_MAX)
+ av_log(NULL, AV_LOG_WARNING,
+ "-t does not work with -filter_complex (yet).\n");
if (configure_output_filter(ofilter->graph, ofilter, ofilter->out_tmp) < 0) {
av_log(NULL, AV_LOG_FATAL, "Error configuring filter.\n");
AV_DICT_DONT_OVERWRITE);
if(o->recording_time != INT64_MAX)
av_dict_set(&oc->metadata, "duration", NULL, 0);
+ av_dict_set(&oc->metadata, "creation_time", NULL, 0);
}
if (!o->metadata_streams_manual)
for (i = output_files[nb_output_files - 1]->ost_index; i < nb_output_streams; i++) {