[MPlayer-dev-eng] [PATCH] Changing audio speed

Dean LM dean.lm at gmail.com
Thu Jul 21 21:57:01 CEST 2005


Hi,

I'm not sure whether this has been addressed before, but I have a
video with the audio sampled at
22050 Hz, when I try playing it the video plays at the correct speed
but the audio is half the
speed it should be (i.e. slooow). I've tried 'mplayer -srate 44100'
but that didn't fix it.
'mplayer -speed 2' doubles both the video and audio speed. Since I
couldn't find a way of changing the
speed of just the audio, I've written a patch which does this (btw
this is my first patch submission).


$ diff MPlayer-1.0pre7/mplayer.c MPlayer-1.0pre7-audio_speed/mplayer.c

217c217,218
< float playback_speed=1.0;
---
> float playback_speed=1.0; // video and audio
> float audio_playback_speed=1.0; // audio only
947c948
<   new_srate = sh_audio->samplerate * playback_speed;
---
>   new_srate = sh_audio->samplerate * audio_playback_speed;
954c955
<     playback_speed = (float)new_srate / (float)sh_audio->samplerate;
---
>     audio_playback_speed = (float)new_srate / (float)sh_audio->samplerate;
2127a2129
>   if(playback_speed != 1.0) audio_playback_speed = playback_speed;
2130c2132
<   ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*playback_speed;
---
>   ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*audio_playback_speed;
2136c2138
<         (int)(sh_audio->samplerate*playback_speed),
---
>         (int)(sh_audio->samplerate*audio_playback_speed),



$ diff MPlayer-1.0pre7/mencoder.c MPlayer-1.0pre7-audio_speed/mencoder.c 

173a174
> float audio_playback_speed=1.0;



$ diff MPlayer-1.0pre7/cfg-common.h MPlayer-1.0pre7-audio_speed/cfg-common.h 

147a148
>       {"audio_speed", &audio_playback_speed, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 100.0, NULL},



this has fixed the problem, the video and audio now plays at the correct speed:

$ mplayer -audio_speed 2 22050hz_audio_video.avi
MPlayer 1.0pre7-3.2.3 (C) 2000-2005 MPlayer Team
CPU: Intel Pentium 4/Xeon/Celeron Foster (Family: 8, Stepping: 4)
Detected cache-line size is 64 bytes
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

Playing 22050hz_audio_video.avi.
AVI file format detected.
VIDEO:  [DIV3]  512x384  24bpp  23.977 fps  897.9 kbps (109.6 kbyte/s)
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 22050 Hz, 2 ch, s16le, 416.0 kbit/58.96% (ratio: 52000->88200)
Selected audio codec: [mp3] afm:mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
SDL: Using driver: x11
vo: X11 running at 1600x1200 with depth 24 and 32 bpp (":0.0" => local display)
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffdivx] vfm:ffmpeg (FFmpeg DivX ;-) (MS MPEG-4 v3))
==========================================================================
Checking audio filter chain for 44100Hz/2ch/s16le -> 44100Hz/2ch/s16le...
AF_pre: 44100Hz/2ch/s16le
AO: [oss] 44100Hz 2ch s16le (2 bps)
Building audio filter chain for 44100Hz/2ch/s16le -> 44100Hz/2ch/s16le...
Starting playback...
VDec: vo config request - 512 x 384 (preferred csp: Planar YV12)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is undefined - no prescaling applied.
VO: [sdl] 512x384 => 512x384 Planar YV12 


Hopefully, this may help others if they have the same problem.

regards,
Dean LM




More information about the MPlayer-dev-eng mailing list