Dienstag, 3. September 2013

[How-To] Streaming audio and video on local network

I just wanted to stream some videos and music from one PC to another because that other has loudspeakers connected and a bigger screen. But how to do that?

The simplest thing: copy the files over.

Second thing: share the files via samba or NFS and play them.

You could also try VLC or IceCast or something like that.
I got the VLC one running. With RTP and RTSP. You can use the GUI - but then you can just play one file and then need to redo the setup the the next file ...
With RTP you also should convert to MPEG because else you might not see a thing. The pro side is: from the client you connect one time and then get new data. With RTSP you don't need to convert, the quality is better, but you need to reconnect after every file. Or set-up the server somehow to continuously play something. I didn't find the right things for that...
So the more you want the more you need to dive into config files.
IceCast is config files  from the ground up. So I didn't try at all.

I just wanted to stream some files the simplest way :-(

It should be something like this:
Server: wait for data, push incoming data to mplayer/vlc, they play
Client: connect to server, choose files, push to server

I thought I could do that quickly with QML but failed. It would take some time and C++ to do the task. So I searched for another way.

client: cat file | netcat ip port
server: netcat -l -p port |  mplayer

It works. Most times.
But after one file finished the server would also stop. I didn't find a way around.

But I found socat.
The improved netcat.
It works for now for me for most of the things.

The client:
for FILE1 in "$@"
        echo "Here: $PWD/$FILE1"
        socat TCP4:${SERVERIP}:${SERVERPORT},nodelay,mss=8192 "$PWD/$FILE1"
Calling: ~/stream_this.sh ~/music/*
Plays some files.

The server:
socat tcp-l:
${SERVERPORT},fork system:'vlc --quiet --play-and-exit --qt-start-minimized -',nofork
I use VLC to play the files. Socat will open a new VLC for each incoming file. That's why it will exit its VLC after each one and also will start minimized so it doesn't interrupt the normal work-flow. I tried allowing only one instance but somehow it didn't work.

Not as nice and easy and GUI as it should but for now it's enough for me.

Have fun!