summaryrefslogtreecommitdiffstats
path: root/audio/filter
diff options
context:
space:
mode:
authorferreum <code@ferreum.de>2023-08-13 15:12:41 +0200
committerNiklas Haas <github-daiK1o@haasn.dev>2023-09-20 14:36:23 +0200
commite05591ef5947a039183b42c1d6d3be945e5475ab (patch)
treeaf9a634fbe79a67b684d585208219449ed95a640 /audio/filter
parent8080d00d7f31a0e1ba25418e0f08474f1a2f1f61 (diff)
downloadmpv-e05591ef5947a039183b42c1d6d3be945e5475ab.tar.bz2
mpv-e05591ef5947a039183b42c1d6d3be945e5475ab.tar.xz
af_scaletempo2: truncate final packet to expected length
Avoid generating too much audio after EOF. Note: This often has no effect, because less audio is produced than required. Usually this comes to effect with the userspeed filter at high speed (4x) and going back to 1x speed to remove the filter.
Diffstat (limited to 'audio/filter')
-rw-r--r--audio/filter/af_scaletempo2.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/audio/filter/af_scaletempo2.c b/audio/filter/af_scaletempo2.c
index 5258fe3204..ea4b63975e 100644
--- a/audio/filter/af_scaletempo2.c
+++ b/audio/filter/af_scaletempo2.c
@@ -111,6 +111,20 @@ static void process(struct mp_filter *f)
double frame_delay = mp_scaletempo2_get_latency(&p->data, p->speed)
+ out_samples * p->speed;
mp_aframe_set_pts(out, pts - frame_delay / mp_aframe_get_effective_rate(out));
+
+ if (p->sent_final) {
+ double remain_pts = pts - mp_aframe_get_pts(out);
+ double rate = mp_aframe_get_effective_rate(out) / p->speed;
+ int max_samples = MPMAX(0, (int) (remain_pts * rate));
+ // truncate final packet to expected length
+ if (out_samples >= max_samples) {
+ out_samples = max_samples;
+
+ // reset the filter to ensure it stops generating audio
+ // and mp_scaletempo2_frames_available returns false
+ mp_scaletempo2_reset(&p->data);
+ }
+ }
}
mp_aframe_set_size(out, out_samples);