unexpected behavior when invoking vlc from php

*nix specific usage questions
xha1e
New Cone
New Cone
Posts: 5
Joined: 26 Feb 2024 06:48

unexpected behavior when invoking vlc from php

Postby xha1e » 26 Feb 2024 06:58

Hi I am having an issue with invoking vlc from a php page. When the script is invoked from php, VLC returns the following message:

VLC media player 3.0.20 Vetinari
Command Line Interface initialized. Type `help' for help.
> Shutting down.
However, if I invoke the script from command line, vlc runs and a video is played to the raspberry pi hdmi port as expected.

I believe even with proper permissions the issue persists, I am not sure why the result for vlc is different when called from the webpage, rather than from commend line.


Details below:
Device is CM4, and its running pi os lite 32

This is the php that calls the command to run the videoPlayer.sh script, which contains the vlc command.

start-player-form.php:

Code: Select all

<?php include "../includes/console-log.php"; console_log("start-player-form.php connected"); console_log($_POST['videoToPlay']); console_log($_POST['loopVideo']); $videoToPlay = substr($_POST['videoToPlay'], strrpos($_POST['videoToPlay'], "\\")); console_log($videoToPlay); if ($_POST['videoToPlay'] == "Choose...") { echo '<div class="alert alert-warning alert-dismissible fade show" role="alert"> No video file is selected. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div>'; } else { console_log("start-player-form.php function executed"); $startPlayer = escapeshellcmd("sh ../commands/videoPlayer.sh start '" . $videoToPlay . "' '" . $_POST['loopVideo'] . "'"); $startPlayerOutput = shell_exec($startPlayer); echo '<div class="alert alert-success alert-dismissible fade show" role="alert"> ' . $startPlayerOutput . ' <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div>'; }


videoPlayer.sh

Code: Select all

#!/bin/bash echo "Digital Signage Video Player Starting..." #find vlc var=$(ps -ef | grep vlc | grep -v grep | awk '{print $2}') action=$1 fileName=$2 videoLoop=$3 #default path to video upload folder path="/var/www/html/videos/" #play video to HDMI, looped playAndLoop="vlc --loop --fullscreen ${path}${fileName}" #play video to HDMI, not looped playAndExit="vlc --play-and-exit --fullscreen ${path}${fileName}" if [ "$action" = 'start' ]; then if [ "$videoLoop" = 'true' ]; then echo "Playing Video, Loop = true" $playAndLoop fi if [ "$videoLoop" = 'false' ]; then echo "Playing Video, Loop = false" $playAndExit fi fi if [ "$action" = 'stop' ]; then echo "Stopping Video" sudo kill $var fi
Message I receive is:
VLC media player 3.0.20 Vetinari
Command Line Interface initialized. Type `help' for help.
> Shutting down.
Permissions:
-rwxrwxrwx 1 pi www-data 758 Feb 23 21:35 videoPlayer.sh
-rwxrwxrwx 1 pi www-data 1076 Feb 23 21:35 start-player-form.php
drwxrwxrwx 2 pi www-data 4096 Feb 23 21:07 videos

Some similar unresolved post i found:
https://ubuntuforums.org/showthread.php?t=2170458


I can call videoPlayer.sh from command line with the following command and the result works as expected, but not if called from the php.
sh /var/www/html/commands/videoPlayer.sh start big* false

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: unexpected behavior when invoking vlc from php

Postby Rémi Denis-Courmont » 26 Feb 2024 08:58

This looks like normal behaviour if you give no input, as with any tool taking commands from the standard input.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

xha1e
New Cone
New Cone
Posts: 5
Joined: 26 Feb 2024 06:48

Re: unexpected behavior when invoking vlc from php

Postby xha1e » 26 Feb 2024 18:12

The input is the path and file name for the .mp4 video location:

Code: Select all

vlc --loop --fullscreen ${path}${fileName}

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: unexpected behavior when invoking vlc from php

Postby Rémi Denis-Courmont » 26 Feb 2024 18:56

When I wrote standard input, I meant literally standard input, not "command line parameter".
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

xha1e
New Cone
New Cone
Posts: 5
Joined: 26 Feb 2024 06:48

Re: unexpected behavior when invoking vlc from php

Postby xha1e » 29 Feb 2024 00:53

This is the error message I get when running vlc:

command:

Code: Select all

cvlc --play-and-exit --fullscreen "/var/www/html/videos/big*" | 2>&1 | sudo tee output_file
response:
Failed to create secure directory (/var/www/.config/pulse): No such file or directory
[012e96c8] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[01317f48] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[01317f48] main interface error: no suitable interface module
[0128b280] main libvlc error: interface "dbus,none" initialization failed
[012eecf8] main interface error: no suitable interface module
[0128b280] main libvlc error: interface "globalhotkeys,none" initialization failed
[012eecf8] dummy interface: using the dummy interface module...
[h264_v4l2m2m @ 0xec60b810] Could not find a valid device
[h264_v4l2m2m @ 0xec60b810] can't configure decoder
[ec615630] avcodec decoder error: cannot start codec (h264_v4l2m2m)
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
[e8e01958] gles2 generic error: parent window not available
[e8e01958] xcb generic error: window not available
[e8e00ce8] mmal_xsplitter vout display: Try drm
[e8e01958] drm_vout generic: <<< OpenDrmVout: Fmt=I420
[e8e01958] drm_vout generic error: Failed to get xlease
[e8e01958] drm_vout generic error: Failed to open vc4
[e8e00ce8] mmal_xsplitter vout display: Drm no go
[e8e00ce8] gles2 vout display error: parent window not available
[e8e00ce8] gl vout display error: parent window not available
[e8e00ce8] xcb vout display error: window not available
[e8e00ce8] xcb vout display error: window not available
[e8e00ce8] drm_vout vout display: <<< OpenDrmVout: Fmt=I420
[e8e00ce8] drm_vout vout display error: Failed to get xlease
[e8e00ce8] drm_vout vout display error: Failed to open vc4
Error opening terminal: unknown.


Return to “VLC media player for Linux and friends Troubleshooting”

Who is online

Users browsing this forum: Google [Bot] and 9 guests