1

I am trying to use mpg123 to play a mp3 file but am struggling to do it on a GPU.

Upon doing a lot of research, the closest command I found for my requirement was:

mplayer -vo vdpau and -vc ffh264vdpau, ffmpeg12vdpau, ffmwmv3vdpau, ffvc1vdpau -ao alsa filename.mp4

But after googling some of these commands I realized these are geared towards video decoding.

I tried running this command by adapting it for mpg123 in the following way (just to see what response I would get):

mpg123 -vo vdpau and -vc ffh264vdpau, ffmpeg12vdpau, ffmwmv3vdpau, ffvc1vdpau -ao alsa /root/Downloads/Traintoleave.mp3

The following is the output I got:

High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
    version 1.23.8; written and copyright by Michael Hipp and others
    free software (LGPL) without any warranty but with best wishes
Decoder: x86-64 (AVX)
Trying output module: vdpau, device: <nil>
[src/libout123/legacy_module.c:40] error: Unable to open requested module 'vdpau'.
[src/libout123/legacy_module.c:42] error: The only available statically compiled module is 'alsa'.
[src/libout123/libout123.c:432] error: Found no driver out of [vdpau] working with device <default>.
main: [src/mpg123.c:333] error: out123 error 3: failure loading driver module

I still don't understand how I can use mpg123 to make the audio file run on my NVIDIA GPU and monitor its execution time.

Any help or advice will be greatly appreciated.

EDIT: I executed the following command on the terminal:

sudo aplay -L

and got the following output:

default
    Default
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC280 Analog
    Front speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC280 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC280 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC280 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC280 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC280 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
hdmi:CARD=NVidia,DEV=0
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=1
    HDA NVidia, HDMI 1
    HDMI Audio Output

However, this is only information for aplay and not mpg123. I found from another source that aplay is used to play wav files only.

Thanks to another stackoverflow question, I was able to successfully track my device IDs. I ran the command sudo aplay -l and got the following output:

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC280 Analog [ALC280 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

I used this information to play a mp3 file using mpg123 by typing the following command:

mpg123 -D hw:1,3 sample.mp3

This gave me the following output:

High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
    version 1.23.8; written and copyright by Michael Hipp and others
    free software (LGPL) without any warranty but with best wishes
Invalid shared memory segment size
Invalid shared memory segment size


Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: sample.mp3 ...
Invalid shared memory segment size

MPEG 1.0 L III cbr128 44100 stereo
Invalid shared memory segment size
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured
ALSA lib pcm.c:7246:(snd_pcm_recover) underrun occured

[0:06] Decoding of sample.mp3 finished.

I don't know if this audio file was played on the GPU or some other processor. How can I confirm that this file was played on the GPU?

EDIT:

Can VLC be used for decoding audio by using GPU power? I got the idea from this link but I am not certain of it: https://askubuntu.com/questions/240386/how-do-i-enable-hardware-accelerated-video-in-vlc-with-intel-hd-4000-gpu

  • I was going over this website. I found it to be useful: download.nvidia.com/XFree86/gpu-hdmi-audio-document/… – a_sid Nov 27 '16 at 5:10
  • May I ask why you insist on decoding the MP3 file on your GPU? While it should in principle be possible with CUDA etc., I doubt anyone has written any code to actually decode MP3 files on the GPU - the main CPU has more than enough horsepower to do it, and the effort to transfer the data to the CPU would probably outweigh any gains you get from GPU decoding. And vdpau is not for decoding mp3. – dirkt Nov 27 '16 at 8:14
  • @dirkt Thank you for your response. I simply wish to do profiling with the MP3 Decoder and find out how much time its functions would take on the GPU. It is for experimental purposes. – a_sid Nov 27 '16 at 8:31
0

I'm am not aware of any publicly available implementation of a MP3 decoder running on a GPU, certainly not in mpg123, and certainly not using vdpau (which is for video decoding).

It's probably not very easy to make MP3 decoding parallel, which would be necessary to make it run efficiently on a GPU.

A bit of googling finds for example this article, which seems to use a custem CUDA implementation and reported power savings compared to running it on a CPU. (Full text available only on request, so I don't know about performance).

Note that any measurements you do will heavily depend on the quality of the implementation, both for the CPU and GPU case.

  • Thank you for your comprehensive answer. I was hoping there would be open source software for decoding MP3 files. I guess I will have to try and write the code by myself then. – a_sid Nov 27 '16 at 17:09
  • There's lots of open source software to decode MP3, just not for a GPU (because, as I said, it doesn't make a lot of sense to use a GPU for that). – dirkt Nov 27 '16 at 18:14
  • I am aware of the fact that there is open source software available and I have used it already. I require code specifically to run on my GPU. – a_sid Nov 27 '16 at 19:07
  • Can VLC be used for decoding audio by using GPU power? I got the idea from this link: askubuntu.com/questions/240386/… – a_sid Nov 27 '16 at 20:03
  • 1
    All these extensions are APIs are for video encoding/decoding, which sometimes uses dedicated hardware in the GPU: VA-API is by Intel for Intel hardware, VDPAU is by NVIDIA for NVIDIA hardware, and XvMC is on older X extensions. None if these decode MP3 audio, for the reasons given. It doesn't really matter if you use vlc, mplayer, mpg123 or any other player to access those extensions, none of them will decode MP3 on the GPU. – dirkt Nov 28 '16 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.