7

I try to play sound from a php script to my raspberry pi 3 via the audio jack. I use in the php script the following code:

<?php
$fetch = 'wget "http://192.168.1.127/sound.mp3" -O sound.mp3 --no-check-certificate';
$play = 'omxplayer -o local sound.mp3';
echo shell_exec($fetch);
echo shell_exec("sudo chown upload sound.mp3");
echo shell_exec($play);
?>

I got the file from a local ip adress and save it to the pi. Then I play the sound via the omxplayer command. On the real shell (over SSH in Putty), the Pi will output the sound without any problems. When I try the script, I got the following error message when I use the omxplayer command.

* failed to open vchiq instance

I searched then in forums for this error. They mean that it will be something with the missing permission of the file. For that I set the whole directory to the permission level 777 and the fileowner, as you can see in the script, to upload.

Unfortunately, this didn't work. Does anyone have another solution to get an output from the pi?

Thanks for every responses.

3 Answers 3

18

Omxplayer is a video and audio player. Your user needs to be in the video group, even though you only want to playback audio.

Don't use the 777 mode on the /dev/vchiq because it's not secure! A better solution is to add your user to the system group called video. For example: To add user testuser in your Linux system to the video group, use this command:

usermod -aG video testuser
2
  • 1
    This should really be usermod -aG video testuser otherwise the testuser will be removed from other groups
    – nickjb
    Commented Feb 23, 2020 at 13:03
  • this solution dont work for me. Im using a Banana Pi Zero M2
    – Erick Crus
    Commented Aug 31, 2023 at 16:51
9

Finally I found a solution for that problem, after I searched again. The problem was with a directory in the /dev. I hit the following command in the command line and it works great.

sudo chmod 777 /dev/vchiq
3
  • 7
    rather than change systemwide, it's to better to change for the specific user. sudo usermod -a -G video username. this answer can be found over the place, like here: raspberrypi.stackexchange.com/questions/19436/… Commented Nov 28, 2018 at 21:24
  • The "777" mode om the /dev/vchiq is hole in the security! Especially it's important to use when video camera used. Use the "video" group instead to appropriate user.
    – Alex
    Commented Jul 31, 2019 at 7:27
  • Dont do this, it allows any system user write access to the device, adjust the individual user settings as above
    – nickjb
    Commented Feb 23, 2020 at 13:00
4

A lot of users have actually been brought to this question because they tried raspistill and it returned this error.

In any case, the error is usually because you forgot to add the sudo, so sudo raspistill -o output.jpg should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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