Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Running vlc from cgi-script

  1. #1
    Join Date
    Jul 2018
    Beans
    6

    Question Running vlc from cgi-script

    Hello, I'm new here and am posting this because I can't find anything relevant in a search of the forums.

    I have a suite of perl scripts that plays selections from my music collection. A kind of personalised version of iTunes. I use an apache server on my LAN to handle the user interface, backed up by a MySQL database, and I use VLC to play the tracks and control the play through VLC's html interface. It's been running fine under Windows for a good few years.

    Since Windows 10 is an abomination, I am finally taking the plunge to move everything to Linux and I'm running Ubuntu 16.04 with apache, with a MySQL database backend.

    On Ubuntu the interface and database parts work fine, but my script doesn't seem able to invoke vlc to play the music. I've tried various things and after banging my head against it for a while I decided to seek help.

    The command string generated by the script is of the form:

    /usr/bin/vlc --http-password="xxxxx" --intf="http" --one-instance --play-and-exit --playlist-enqueue /path_to_music/test.mp3

    Run from the command line, this plays the track and I can control it through the http interface in a webpage (port 8080). It exits normally at the end.

    However, when I execute the same command through a perl system call (forked process) in my script, the call returns error code 256 and no music is heard . The apache error log says:

    Home directory not accessible: Permission denied
    [00000000020c3ec8] pulse audio output error: PulseAudio server connection failure: Connection refused
    Home directory not accessible: Permission denied
    [00000000020cb7d8] core interface error: no suitable interface module
    [0000000001ff6178] core libvlc error: interface "globalhotkeys,none" initialization failed
    [00000000020cb7d8] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
    [00000000020cb7d8] core interface error: no suitable interface module
    [0000000001ff6178] core libvlc error: interface "dbus,none" initialization failed
    [00000000020cb7d8] core interface error: no suitable interface module
    [0000000001ff6178] core libvlc error: interface "default" initialization failed


    My best guess is that it's a permissions issue and the cgi environment is not able to invoke the vlc application correctly. Is that right? Is this an example of Linux' superior security isolating the web server from other applications?

    And if so, what is the workaround?

    Any help will be appreciated.

    Philip

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Running vlc from cgi-script

    Quote Originally Posted by philpot65 View Post
    My best guess is that it's a permissions issue and the cgi environment is not able to invoke the vlc application correctly. Is that right? Is this an example of Linux' superior security isolating the web server from other applications?

    And if so, what is the workaround?

    Any help will be appreciated.

    Philip
    Yes. Apache cannot directly cause any GUI programs to be run. Web servers run under a different userid than your login session. Only programs running with the same userid as the X/Session can run GUI programs. Ok, that isn't entirely true, but effectively it is.

    It can return a file/MIME-type that your system could know how to handle and, if configured for that mime-type, then vlc would be used to handle the data. I have no idea how to make that happen. It would depend on the DE, window manager and browser used. Basically, the list should return an m3u playlist. It is more about the mime-type, since file extensions don't matter to Linux.

    Beware that about 80% of what you learned under Windows just doesn't apply any more. For example, the GUI isn't part of the OS. The GUI is just another program. I use openbox without any DE (desktop environment) because I prefer a simple interface. But that isn't directly helpful to you, today.

  3. #3
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Running vlc from cgi-script

    A little experimentation shows that the problem is profound. If I try to play an MP3 file with the mpv program, I have no problems if I'm running under my own account. However some testing shows that the www-data "user" under which Apache runs cannot play the same file because of a variety of permissions problems. The www-data account is pretty limited for security reasons. It doesn't even own its home directory, /var/www; root does. Even fiddling with that didn't solve the permissions problem.
    Last edited by SeijiSensei; July 16th, 2018 at 07:19 PM.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  4. #4
    Join Date
    Jul 2018
    Beans
    6

    Re: Running vlc from cgi-script

    Quote Originally Posted by TheFu View Post
    Yes. Apache cannot directly cause any GUI programs to be run. Web servers run under a different userid than your login session. Only programs running with the same userid as the X/Session can run GUI programs. Ok, that isn't entirely true, but effectively it is.

    It can return a file/MIME-type that your system could know how to handle and, if configured for that mime-type, then vlc would be used to handle the data. I have no idea how to make that happen. It would depend on the DE, window manager and browser used. Basically, the list should return an m3u playlist. It is more about the mime-type, since file extensions don't matter to Linux.

    Beware that about 80% of what you learned under Windows just doesn't apply any more. For example, the GUI isn't part of the OS. The GUI is just another program. I use openbox without any DE (desktop environment) because I prefer a simple interface. But that isn't directly helpful to you, today.
    Thanks for the advice. I know that *nix <> Windows. My computing background goes back to the days when GUIs were just a twinkle in a programmer's eye, but it's a while since I had to work in a plain terminal.

    It occurred to me since I made my original post that VLC's own html interface, running in a web page, does somehow manage to interact with a running instance of the VLC program. At first sight, it appears to do so through a mass of javascript, however unlikely that may seem. I wonder if there's a way to exploit that.

  5. #5
    Join Date
    Jul 2018
    Beans
    6

    Re: Running vlc from cgi-script

    Quote Originally Posted by SeijiSensei View Post
    A little experimentation shows that the problem is profound. If I try to play an MP3 file with the mpv program, I have no problems if I'm running under my own account. However some testing shows that the www-data "user" under which Apache runs cannot play the same file because of a variety of permissions problems. The www-data account is pretty limited for security reasons. It doesn't even own its home directory, /var/www; root does. Even fiddling with that didn't solve the permissions problem.
    This is pretty much what I thought. However, web pages do play music (and videos), so must be able to interact in some way with media software on the user's machine.

    Of course, that is on the client side, not the server side. However, if I run VLC from a terminal I can then control it from a web page using the VLC html interface (fast forward or back, jump to new location in track, pause, restart, empty playlist, etc.). I can do this both on the server itself, and in a browser on another machine on the LAN.
    Last edited by philpot65; July 17th, 2018 at 07:48 AM.

  6. #6
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Running vlc from cgi-script

    Seems that trying to get 1 server to send another webserver commands running under different userids is the hard way to solve this.
    VLC's html interface is just running a web server, but under the userid running VLC.You can send it commands over that interface, but that seems like the hard way to do things. Have you tried just setting up the MIME types and external helper programs to play a downloaded playlist yet? Works just like how downloading a .docx file will open libreoffice.

  7. #7
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Running vlc from cgi-script

    Another option for streaming media is DLNA depending on the mix of devices you want to support. I use minidlna for this; others use Plex.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  8. #8
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Running vlc from cgi-script

    Quote Originally Posted by SeijiSensei View Post
    Another option for streaming media is DLNA depending on the mix of devices you want to support. I use minidlna for this; others use Plex.
    True. And I tested a new VLC (v3.x) a few weeks ago and this was the first time the DLNA parts worked correctly. I prefer other clients myself. Just depends on the situation for what is easiest/best. IMHO, vlc is overkill for music, I'm more of a cmus guy.

  9. #9
    Join Date
    Jul 2018
    Beans
    6

    Re: Running vlc from cgi-script

    Quote Originally Posted by TheFu View Post
    Seems that trying to get 1 server to send another webserver commands running under different userids is the hard way to solve this.
    If I were starting from scratch, I might agree with you. However, I'm trying to port an existing application that already works fine on another platform. If I can't do that, then I am certainly open to considering other options.

    Quote Originally Posted by TheFu View Post
    VLC's html interface is just running a web server, but under the userid running VLC.You can send it commands over that interface, but that seems like the hard way to do things. Have you tried just setting up the MIME types and external helper programs to play a downloaded playlist yet? Works just like how downloading a .docx file will open libreoffice.
    I checked out the playlist file format and it's not complicated. However, when I tried to generate such a new file from within my code I ran into another "permission denied" message. What I'm thinking about now is pushing the playlist into the music database and then running some kind of daemon to check the relevant table and stream anything it finds there to vlc. This seems overly complex, but maybe it's the only way.

  10. #10
    Join Date
    Jul 2018
    Beans
    6

    Re: Running vlc from cgi-script

    Quote Originally Posted by SeijiSensei View Post
    Another option for streaming media is DLNA depending on the mix of devices you want to support. I use minidlna for this; others use Plex.
    I'm not trying to stream the music from one computer to another. I want it to play on the web server (which is connected to a stereo system), but be controllable from any computer on the LAN through the vlc html interface. That's how I have it now and it suits my needs.

    I realise this sounds like an awfully unprofessional setup, but it's just my home entertainment centre, behind a firewall, with a remote interface that works over the LAN. I'd rather try to use what I've already got before redesigning the whole thing.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •