Commit 488a0fa6 authored by Anton Khirnov's avatar Anton Khirnov
Browse files

avconv: support -t as an input option.

It limits the duration of the data read from a given input.
parent 811bd078
...@@ -30,6 +30,8 @@ version 10: ...@@ -30,6 +30,8 @@ version 10:
- when transcoding with avconv (i.e. not streamcopying), -ss is now accurate - when transcoding with avconv (i.e. not streamcopying), -ss is now accurate
even when used as an input option. Previous behavior can be restored with even when used as an input option. Previous behavior can be restored with
the -noaccurate_seek option. the -noaccurate_seek option.
- avconv -t option can now be used for inputs, to limit the duration of
data read from an input file
version 9: version 9:
......
...@@ -958,6 +958,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost) ...@@ -958,6 +958,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost)
static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt) static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
{ {
OutputFile *of = output_files[ost->file_index]; OutputFile *of = output_files[ost->file_index];
InputFile *f = input_files [ist->file_index];
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base); int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base);
AVPacket opkt; AVPacket opkt;
...@@ -974,6 +975,16 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p ...@@ -974,6 +975,16 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
return; return;
} }
if (f->recording_time != INT64_MAX) {
start_time = f->ctx->start_time;
if (f->start_time != AV_NOPTS_VALUE)
start_time += f->start_time;
if (ist->last_dts >= f->recording_time + start_time) {
ost->finished = 1;
return;
}
}
/* force the input stream PTS */ /* force the input stream PTS */
if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
audio_size += pkt->size; audio_size += pkt->size;
......
...@@ -239,6 +239,7 @@ typedef struct InputFile { ...@@ -239,6 +239,7 @@ typedef struct InputFile {
int ist_index; /* index of first stream in ist_table */ int ist_index; /* index of first stream in ist_table */
int64_t ts_offset; int64_t ts_offset;
int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */ int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
int64_t recording_time;
int nb_streams; /* number of stream that avconv is aware of; may be different int nb_streams; /* number of stream that avconv is aware of; may be different
from ctx.nb_streams if new streams appear during av_read_frame() */ from ctx.nb_streams if new streams appear during av_read_frame() */
int rate_emu; int rate_emu;
......
...@@ -463,7 +463,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, ...@@ -463,7 +463,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
snprintf(name, sizeof(name), "trim for input stream %d:%d", snprintf(name, sizeof(name), "trim for input stream %d:%d",
ist->file_index, ist->st->index); ist->file_index, ist->st->index);
ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ? ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
AV_NOPTS_VALUE : 0, INT64_MAX, &last_filter, &pad_idx, name); AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -550,7 +550,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, ...@@ -550,7 +550,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
snprintf(name, sizeof(name), "trim for input stream %d:%d", snprintf(name, sizeof(name), "trim for input stream %d:%d",
ist->file_index, ist->st->index); ist->file_index, ist->st->index);
ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ? ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
AV_NOPTS_VALUE : 0, INT64_MAX, &last_filter, &pad_idx, name); AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -689,6 +689,7 @@ static int open_input_file(OptionsContext *o, const char *filename) ...@@ -689,6 +689,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
f->ctx = ic; f->ctx = ic;
f->ist_index = nb_input_streams - ic->nb_streams; f->ist_index = nb_input_streams - ic->nb_streams;
f->start_time = o->start_time; f->start_time = o->start_time;
f->recording_time = o->recording_time;
f->ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp); f->ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp);
f->nb_streams = ic->nb_streams; f->nb_streams = ic->nb_streams;
f->rate_emu = o->rate_emu; f->rate_emu = o->rate_emu;
...@@ -2146,7 +2147,8 @@ const OptionDef options[] = { ...@@ -2146,7 +2147,8 @@ const OptionDef options[] = {
{ "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET | { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
OPT_OUTPUT, { .off = OFFSET(chapters_input_file) }, OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
"set chapters mapping", "input_file_index" }, "set chapters mapping", "input_file_index" },
{ "t", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(recording_time) }, { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
"record or transcode \"duration\" seconds of audio/video", "record or transcode \"duration\" seconds of audio/video",
"duration" }, "duration" },
{ "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) }, { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment