diff options
author | Paul B Mahol <onemda@gmail.com> | 2021-08-25 13:08:10 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2021-11-18 12:54:17 +0100 |
commit | e5367b481b5232182a4851dbd7fc5a7a5bd475de (patch) | |
tree | 60641b4ff9adf45fadf4dccd2704402492a7f2f3 /fftools | |
parent | 85a6b7f7b746a7bf71146b1530f19f699c4f0fb4 (diff) | |
download | ffmpeg-e5367b481b5232182a4851dbd7fc5a7a5bd475de.tar.gz |
ffmpeg: fix loosing gaps between audio frame timestamps when filtering
Diffstat (limited to 'fftools')
-rw-r--r-- | fftools/ffmpeg.c | 5 | ||||
-rw-r--r-- | fftools/ffmpeg.h | 1 | ||||
-rw-r--r-- | fftools/ffmpeg_opt.c | 1 |
3 files changed, 7 insertions, 0 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 7b2dcee838..b1d2c69fa7 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2382,6 +2382,11 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, decoded_frame->pts = ist->dts; decoded_frame_tb = AV_TIME_BASE_Q; } + if (pkt && pkt->duration && ist->prev_pkt_pts != AV_NOPTS_VALUE && + pkt->pts != AV_NOPTS_VALUE && pkt->pts - ist->prev_pkt_pts > pkt->duration) + ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; + if (pkt) + ist->prev_pkt_pts = pkt->pts; if (decoded_frame->pts != AV_NOPTS_VALUE) decoded_frame->pts = av_rescale_delta(decoded_frame_tb, decoded_frame->pts, (AVRational){1, avctx->sample_rate}, decoded_frame->nb_samples, &ist->filter_in_rescale_delta_last, diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 30225e9ffe..545ff1c8e7 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -314,6 +314,7 @@ typedef struct InputStream { AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */ AVPacket *pkt; + int64_t prev_pkt_pts; int64_t start; /* time when read started */ /* predicted dts of the next packet read for this stream or (when there are * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */ diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 4685cf6435..ce8bae0775 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -875,6 +875,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) } ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; + ist->prev_pkt_pts = AV_NOPTS_VALUE; ist->dec_ctx = avcodec_alloc_context3(ist->dec); if (!ist->dec_ctx) { |