aboutsummaryrefslogtreecommitdiffstats
path: root/fftools
diff options
context:
space:
mode:
authorGyan Doshi <ffmpeg@gyani.pro>2022-10-21 18:37:37 +0530
committerGyan Doshi <ffmpeg@gyani.pro>2022-11-03 14:38:24 +0530
commit93faba449c0dc9d953d9aeb381f03728ff66e2cb (patch)
treec4d73c1c870c2719a1403d3ecc9084b96ee55a6c /fftools
parent5661c8715ce4f752e676bda75b332efc669694ed (diff)
downloadffmpeg-93faba449c0dc9d953d9aeb381f03728ff66e2cb.tar.gz
ffmpeg: shift start time correction to ffmpeg_opt
In preparation for applying start time correction that accounts for all factors such as copyts, input_ts_offset ..etc
Diffstat (limited to 'fftools')
-rw-r--r--fftools/ffmpeg.c22
-rw-r--r--fftools/ffmpeg_opt.c27
2 files changed, 27 insertions, 22 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 93d1551e1e..62eb3e374b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3192,28 +3192,6 @@ static int transcode_init(void)
input_streams[j + ifile->ist_index]->start = av_gettime_relative();
}
- // Correct starttime based on the enabled streams
- for (i = 0; i < nb_input_files; i++) {
- InputFile *ifile = input_files[i];
- AVFormatContext *is = ifile->ctx;
- int64_t new_start_time = INT64_MAX;
-
- if (is->start_time == AV_NOPTS_VALUE ||
- !(is->iformat->flags & AVFMT_TS_DISCONT))
- continue;
-
- for (int j = 0; j < is->nb_streams; j++) {
- AVStream *st = is->streams[j];
- if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
- continue;
- new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
- }
- if (new_start_time > is->start_time) {
- av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time);
- ifile->ts_offset = -new_start_time;
- }
- }
-
/* init input streams */
for (i = 0; i < nb_input_streams; i++)
if ((ret = init_input_stream(i, error, sizeof(error))) < 0)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index eef325b478..840dc054e9 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -202,6 +202,31 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id
return 0;
}
+static void correct_input_start_times(void)
+{
+ // Correct starttime based on the enabled streams
+ for (int i = 0; i < nb_input_files; i++) {
+ InputFile *ifile = input_files[i];
+ AVFormatContext *is = ifile->ctx;
+ int64_t new_start_time = INT64_MAX;
+
+ if (is->start_time == AV_NOPTS_VALUE ||
+ !(is->iformat->flags & AVFMT_TS_DISCONT))
+ continue;
+
+ for (int j = 0; j < is->nb_streams; j++) {
+ AVStream *st = is->streams[j];
+ if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
+ continue;
+ new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
+ }
+ if (new_start_time > is->start_time) {
+ av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time);
+ ifile->ts_offset = -new_start_time;
+ }
+ }
+}
+
static int apply_sync_offsets(void)
{
for (int i = 0; i < nb_input_files; i++) {
@@ -1268,6 +1293,8 @@ int ffmpeg_parse_options(int argc, char **argv)
goto fail;
}
+ correct_input_start_times();
+
check_filter_outputs();
fail: