Friday, August 14, 2009

Usage of SSH and VLC

This is a followup to an earlier post about VLC in order to elaborate a bit on how I use SSH in that context. First, you need to insure that your SSH works properly from the local to the remote hosts. I am assuming that you know the IP addresses of both hosts here, and both machines are expected to be running Linux. To that end, insure that you can run this command to list files on the remote machine:
echo ls -d .bash\* | ssh -X -Y "REMOTE_USER_NAME@REMOTE_IP_ADDRESS"
You need to change "REMOTE_USER_NAME" to be the username on that remote host, and "REMOTE_IP_ADDRESS" should be the IP address of that remote host (I am using an IP address instead of a hostname to side-step questions discussion about how to set up DNS on your local network given the complexity of DNS). When I do this from my Linux laptop to my Linux desktop, both of which are on my local area network, I simply see a list of files that match the ".b*" expression:
.bash_history
.bash_logout
.bash_profile
.bashrc
Note the backslash in front of the "*" on the command on the local machine, which avoids shell expansion on the local host. If you are able to do that, then you should be able to use the same "echo" command to send vlc commands to the remote host. You may or may not have a SSH agent running on your local system. I do, and it is called seahorse. If you are running GNOME on Debian Linux, it is likely to be available to you by running "seahorse" at a shell command prompt. That seahorse program is an interface to a daemon that runs in the background, handling requests for passwords and such, such that when you request a ssh connection to a remote machine, the seahorse daemon will display an X window dialog box that prompts you for the password for authentication. I'm not exactly sure as to how it determines the password to type in if you don't have a ~/.ssh/ directory setup. If you don't have a .ssh directory, I would encourage you to read up on Linux SSH tutorials on the web for more detailed info. Second, you need to use the ssh command to send a VLC command to stream the AVI file back to the local host, and invoke VLC in GUI mode to receive the stream and display it. Below is the VLC commands I run from the local machine to (a) start the remote VLC session to stream it back, and (b) to start a VLC GUI session locally that will be the receiver:
LOCAL_IP_ADDRESS=you_must_set_this_value
REMOTE_IP_ADDRESS=you_must_set_this_value

# senderVLCCommand is the command we want to execute on the remote
# machine.  I included the sed command that just adds " sender --> "
# to the front of every line so that we can see it on the local
# terminal. Note that although this is placed in the background
# (&), we will still see the "sender" output lines:

senderVLCCommand="vlc -vvv --sout \
  '#std{access=udp,mux=ts,dst=${LOCAL_IP_ADDRESS}:1234}' \\\"$file\\\" 2>&1 \
  | sed 's%^%  sender --> %g'"
sshSenderCommand="echo \"$senderVLCCommand\" \
  | ssh -X -Y \"${REMOTE_USER_NAME}@${REMOTE_IP_ADDRESS}\" sh &"
sh "$sshSenderCommand"

# Note spawn the local VLC session, which will read the stream. Note
# the port number used here in the sender and receiver sessions
# happens to be 1234 (chosen arbitrarily, as long as the number is >
# 1024 and not in use by some other process).

$receiverVLCCommand="vlc -vvv udp://\@:1234 2>&1 | sed 's%^%receiver -->%g' &"
sh "$receiverVLCCommand"

Both commands are put into the background. It has been my experience that this isn't a problem for the sender to start before the receiver starts, as presumably it will block waiting for a receiver to connect to the sender port before transmission starts. Note that for the second command, I use a sed command to prefix "reciever" so that I can monitor errors that occur (and will occur if you have network setup problems or corrupt AVI files, or both). Word of warning: The position slider on the receiver GUI window does not work as you would expect it to. I have not yet found a solution, and would appreciate any comments as to a suitable fix.

No comments:

Post a Comment