[MPlayer-dev-eng] Possible bug when sample rate changes mid-stream
Paul Kelly
paul at stjohnspoint.co.uk
Tue Oct 15 13:21:44 CEST 2013
Hello again,
Paul Kelly wrote:
> Hello mplayer developers,
> I am experiencing a problem with mplayer when playing MP3 audio in which
> the sample rate changes during playback. The problem shows itself in
> particular with some internet radio stations which change from 22050 Hz
> to 44100 Hz mid-stream without any interruption - mplayer will play such
> a stream at half speed after the change.
A week later and no replies; I am assuming that this is some old can of
worms-type bug that nobody really wants to look at. So I have done some
more research. It seems it was introduced in revision r17996 on 30 March
2006:
<http://code.google.com/p/mplayer-mirror/source/detail?r=17996&path=/trunk/libmpcodecs/ad_ffmpeg.c>.
The log message for that commit is:
> Trust the demuxer instead of the decoder for samplerate detection.
> Fixes the ffmp3_bad_rate_detection.avi sample.
> patch by qwen dux qwendu__at__gmail__.__com
which sounds quite suspicious to me. Why should we trust the demuxer
over the decoder? It seems rather an arbitrary decision.
I have downloaded
<http://samples.mplayerhq.hu/avi/ffmp3_bad_rate_detection.avi>, which I
presume is the sample referred to in the log message, and it seems to me
to play exactly the same both in current mplayer SVN, and with the line
that overrides the libavcodec sample rate removed from ad_ffmpeg.c, as
in my patch below. The sample rate is detected as 48000 Hz and the music
sounds OK, so I presume that is correct and wonder if the hack
introduced in r17996 might not be needed any more, and could be removed?
In case anybody wants to look at it and doesn't have a handy
split-samplerate MP3 file handy, I have uploaded a sample file that
exhibits the problem to
<http://www.stjohnspoint.co.uk/media/sample_rate_change.mp3> (but it's
really very simple - just two MP3 files of different sample rates
spliced together).
I hope this extra information whets the appetite of somebody more
familiar with the code than me, to look into it...
Best regards
Paul K
> I have traced the problem to the setup_format() function in
> libmpcodecs/ad_ffmpeg.c: the FFmpeg/libavcodec MP3 decoder correctly
> detects the change in sample rate, but setup_format() then overwrites
> this changed value with an old value. This means that the change isn't
> detected, and the audio ends up being played at the wrong speed.
>
> The patch below fixes the problem for me, but I'm not sure what the
> intent of the line of code I've removed is, so I would appreciate
> somebody verifying if this is a good way of fixing the problem, or
> whether I should be looking somewhere else.
>
> Thanks in advance for your consideration,
> Best regards,
>
> Paul Kelly
>
>
> --- libmpcodecs/ad_ffmpeg.c~ 2013-10-07 21:30:40.914974196 +0200
> +++ libmpcodecs/ad_ffmpeg.c 2013-10-07 22:32:30.325368173 +0200
> @@ -68,8 +68,7 @@
> if (lavc_context->codec_id == AV_CODEC_ID_AAC &&
> samplerate == 2*sh_audio->wf->nSamplesPerSec) {
> broken_srate = 1;
> - } else if (sh_audio->wf->nSamplesPerSec)
> - samplerate=sh_audio->wf->nSamplesPerSec;
> + }
> }
> if (lavc_context->channels != sh_audio->channels ||
> samplerate != sh_audio->samplerate ||
More information about the MPlayer-dev-eng
mailing list