Skip to content

Commit

Permalink
ffmpeg: add support for specifically setting an input start TS
Browse files Browse the repository at this point in the history
Additionally do not reset the start timestamp if this option is set
for an input.
  • Loading branch information
jeeb committed Feb 15, 2018
1 parent aa62808 commit 369a722
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fftools/ffmpeg.c
Expand Up @@ -4385,7 +4385,7 @@ static int process_input(int file_index)
pkt_dts = av_rescale_q_rnd(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
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 && !copy_ts
pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts && !ifile->set_start_time
&& (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->last_ts != AV_NOPTS_VALUE) {
int64_t delta = pkt_dts - ifile->last_ts;
if (delta < -1LL*dts_delta_threshold*AV_TIME_BASE ||
Expand Down
2 changes: 2 additions & 0 deletions fftools/ffmpeg.h
Expand Up @@ -116,6 +116,7 @@ typedef struct OptionsContext {

/* input options */
int64_t input_ts_offset;
int64_t input_ts_start;
int loop;
int rate_emu;
int accurate_seek;
Expand Down Expand Up @@ -402,6 +403,7 @@ typedef struct InputFile {
int64_t input_ts_offset;

int64_t ts_offset;
int64_t set_start_time;
int64_t last_ts;
int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
int seek_timestamp;
Expand Down
11 changes: 10 additions & 1 deletion fftools/ffmpeg_opt.c
Expand Up @@ -1153,7 +1153,13 @@ static int open_input_file(OptionsContext *o, const char *filename)
f->start_time = o->start_time;
f->recording_time = o->recording_time;
f->input_ts_offset = o->input_ts_offset;
f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);

if (o->input_ts_start) {
f->set_start_time = o->input_ts_start;
f->ts_offset = o->input_ts_start - (ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0);
} else {
f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
}
f->nb_streams = ic->nb_streams;
f->rate_emu = o->rate_emu;
f->accurate_seek = o->accurate_seek;
Expand Down Expand Up @@ -3350,6 +3356,9 @@ const OptionDef options[] = {
{ "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
"set the input ts scale", "scale" },
{ "its_start_point", HAS_ARG | OPT_TIME | OPT_OFFSET |
OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_start) },
"set the input ts start point", "time_off" },
{ "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
"set the recording timestamp ('now' to set the current time)", "time" },
{ "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
Expand Down

0 comments on commit 369a722

Please sign in to comment.