Search code examples
linuxsshvlc

How to start vlc-nox via ssh in a Linux server running in text mode?


Background
I have a Linux server running in text mode with no X installed. I intend to show video and image using directfb to the monitor (actually a TV). I have installed vlc-nox and it runs as expected if it is invoked in default console (physical keyboard).


Issue
When running it via SSH, no video is displayed, but audio is okay. The error is as below:

directfb vout display error: Cannot create primary surface
fb vout display error: cannot get terminal mode (Inappropriate ioctl for device)
core video output error: video output creation failed
core decoder error: failed to create video output


fbi's way
I think fbi also facing the same issue, as it would raise an error like below:
ioctl VT_GETSTATE: Inappropriate ioctl for device (not a linux console?)
But, fbi provides a solution for this case: -T -vt <arg> start on virtual console <arg>
So, sudo fbi -T 1 /path/to/image/file would display image as expected.


Question: What's the vlc's way?


Solution

  • I finally have a solution for this, so I post it here in case someone has the same question.

    My understanding is that vlc needs to run under a real tty, not a pseudo tty. My solution is composed of two parts.

    Part 1: Let vlc run as daemon mode.

    1. Create a user for the daemon and assign audio and video privilege.

    #useradd -c "VLC daemon" -d / -G audio,video -M -p \! -r -s /bin/false -u 75 -U vlcd

    1. Run vlc at startup using tty1

    I have tried this with unit under ubuntu.

    [Unit]
    Description=VLC server
    After=network.target auditd.service
    [email protected]
    [Service]
    ExecStart=/usr/bin/vlc -I rc --rc-host 127.0.0.1:8080
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=process
    Restart=on-failure
    RestartPreventExitStatus=255
    User=vlcd
    Type=simple
    #StandardError=tty
    StandardOutput=tty
    StandardInput=tty
    RemainAfterExit=yes 
    [Install]
    WantedBy=multi-user.target
    Alias=vlc.service
    

    Please take notic of the Conflicts, ExecStart, StandardInput, and StandardOutput parts.

    • In Conflicts, it will bypass the default getty service, otherwise it should be disable manually by #systemctrl disable getty@tty1.
    • In ExecStart, do not use the -d switch, which meaning that it would keep running and occupying VT 1, which is activated by Alt-F1. -rc enables the remote connect interface.
    • In StandardInput/Output, specify the tty as input and output device.

    Part 2: Remote talk with the daemon, to let it play the file.

    As --rc-host specify a local port, we need to ssh to the server first. Then, use telnet to interact (add, play, pause) with vlc.

    telnet 127.0.0.1 8080
    add /path/to/video/file