From f8cc3bfe01b05139225e698dc1029ae563148764 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 15 Nov 2020 04:50:20 -0800 Subject: [PATCH] deps/media-playback: Fix audio segment duration calc With certain audio encoders, gaps can be introduced into the audio packets, causing the audio duration to be miscalculated because it calculated audio duration based upon the PTS of the current packet to the last packet. However, this audio encoder also did not store timestamps for most of its audio packets, causing PTS values to be calculated based upon duration values. So those two things combined caused audio timestamps to go all out of whack when playing back certain videos with the media source. This is particularly prevalent with WMV files using Microsoft codecs. So to fix it, when the duration needs to be calculated, just calculate the duration based upon the sample count of the audio packet. This fixes the issue with the video in question that caused problems, and likely fixes issues in a lot of videos that may have been floating out there for some time. Basically this is a fix for a potential long-standing issue. Closes obsproject/obs-studio#3683 --- deps/media-playback/media-playback/decode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deps/media-playback/media-playback/decode.c b/deps/media-playback/media-playback/decode.c index e5a259bf5..b5be5ee33 100644 --- a/deps/media-playback/media-playback/decode.c +++ b/deps/media-playback/media-playback/decode.c @@ -246,14 +246,14 @@ void mp_decode_push_packet(struct mp_decode *decode, AVPacket *packet) static inline int64_t get_estimated_duration(struct mp_decode *d, int64_t last_pts) { - if (last_pts) - return d->frame_pts - last_pts; - if (d->audio) { return av_rescale_q(d->in_frame->nb_samples, (AVRational){1, d->in_frame->sample_rate}, (AVRational){1, 1000000000}); } else { + if (last_pts) + return d->frame_pts - last_pts; + if (d->last_duration) return d->last_duration;