diff options
author | Gyan Doshi <ffmpeg@gyani.pro> | 2021-07-16 17:59:39 +0530 |
---|---|---|
committer | Gyan Doshi <ffmpeg@gyani.pro> | 2021-07-17 20:34:21 +0530 |
commit | c320b78e95bab2a71a636dc4da905522c4646b35 (patch) | |
tree | 55053642cd89687b0e6072a3a83846b8219c2e60 /fftools/ffmpeg.c | |
parent | 075157ec867e0bf8d500bbbd23fee86f37eff45a (diff) | |
download | ffmpeg-c320b78e95bab2a71a636dc4da905522c4646b35.tar.gz |
ffmpeg: add option readrate
Allows to read inputs at arbitrary rates.
-re is equivalent to -readrate 1
Tested with -copyts {+ start_at_zero}, -ss, streamcopied & decoded streams.
Diffstat (limited to 'fftools/ffmpeg.c')
-rw-r--r-- | fftools/ffmpeg.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1ac2e48600..e0f2fe138f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3765,7 +3765,7 @@ static int transcode_init(void) /* init framerate emulation */ for (i = 0; i < nb_input_files; i++) { InputFile *ifile = input_files[i]; - if (ifile->rate_emu) + if (ifile->readrate || ifile->rate_emu) for (j = 0; j < ifile->nb_streams; j++) input_streams[j + ifile->ist_index]->start = av_gettime_relative(); } @@ -4225,12 +4225,19 @@ static int get_input_packet_mt(InputFile *f, AVPacket **pkt) static int get_input_packet(InputFile *f, AVPacket **pkt) { - if (f->rate_emu) { + if (f->readrate || f->rate_emu) { int i; + int64_t file_start = copy_ts * ( + (f->ctx->start_time != AV_NOPTS_VALUE ? f->ctx->start_time * !start_at_zero : 0) + + (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0) + ); + float scale = f->rate_emu ? 1.0 : f->readrate; for (i = 0; i < f->nb_streams; i++) { InputStream *ist = input_streams[f->ist_index + i]; + if (!ist->nb_packets) continue; + int64_t stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start); int64_t pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE); - int64_t now = av_gettime_relative() - ist->start; + int64_t now = (av_gettime_relative() - ist->start)*scale + stream_ts_offset; if (pts > now) return AVERROR(EAGAIN); } |