Streaming-V4L

From LinuxTVWiki
Jump to: navigation, search

Software applications that can use V4L devices to stream or broadcast audio and video over a network or the Internet.

Software

  • GStreamer
  • VideoLan (VLC media player and VLS) -- the simplest place to start
  • ffserver -- an HTTP/RTSP multimedia streaming server for live and recorded broadcasts
  • XdTV -- XdTV is a software that allows you to watch record & stream TV
  • MPEG4IP -- industrial-strength integration project sponsored by Cisco
  • Darwin streaming server -- Apple's open source streaming server and proxy. Supports RTSP/RTP serving of MOV files.
  • spook -- capture live video and audio and stream it over an IP network
  • Flumotion -- an easy-to-use multi-format distributed streaming server
  • List of clients and servers

Guides

VLC instructions

VLC has a small web server built in, so you don't need any other software to stream.

Note if these commands don't work, you may need to upgrade your VLC. This was done on Debian sid using vlc 0.8.5-svn20060212-0 from the nightly builds for 386 and amd64.

Stream a file to a designated machine

Skip the gui with "-I dummy" -- this allows you to start a streaming session on a remote machine.

   vlc file.avi -I dummy --sout udp://123.45.678.9:8080 --loop

The more recent syntax also works -- note the single quotes, and add "vlc:quit" to quit after the file is played:

   vlc file.avi -I dummy --sout '#std{access=udp,mux=ts,dst=123.45.678.9:8080}'  vlc:quit

Receive:

   vlc udp://@:8080

Stream a file to the network

Again, quotes mandatory:

   vlc file.avi -I dummy --sout '#std{access=mmsh,dst=:8080}' --ttl 12 vlc:quit
   vlc file.avi -I dummy --sout '#std{access=mmsh,dst=:8080}' --ttl 12 --loop

Receive:

   vlc mmsh://servername:8080

See example script below.

Stream from a webcam

   vlc -I dummy -v --noaudio --ttl 12 v4l:/dev/video0:size=320x240 \
   --sout '#std{access=mmsh,dst=:8080}' -V X11 
   vlc -I dummy -v --noaudio --ttl 12 v4l:/dev/video0:size=320x240 \
   --sout '#transcode{vcodec=mp4v,vb=128}:std{access=mmsh,dst=:8080}'

Receive:

   vlc mmsh://123.45.678.9:8080

Stream from television

Use this to find tv channel frequencies:

   scantv - scan a v4l device for TV stations

Stream tv to a single designated machine:

   vlc --color
   v4l:/dev/video2:norm=ntsc:frequency=77250:size=640x480:\
   adev=/dev/dsp2:audio=0 --sout #transcode{vcodec=mp4v,acodec=mpga,vb=512,\
   ab=128,samplerate=44100,venc=ffmpeg{keyint=80,hurry-up,vt=800000},\
   deinterlace}:std{access=udp,mux=ts,dst=123.45.678.9:8080} --ttl 12 -I dummy 

Receive:

   vlc udp://@:8080

Stream tv to the network:

   vlc --color
   v4l:/dev/video2:norm=ntsc:frequency=77250:size=640x480:\
   adev=/dev/dsp2:audio=0 --sout #transcode{vcodec=mp4v,acodec=mpga,vb=512,\
   ab=128,samplerate=44100,venc=ffmpeg{keyint=80,hurry-up,vt=800000},\
   deinterlace}:std{access=mmsh,dst=:8080} --ttl 12 -I dummy 

Receive:

   vlc mmsh://servername:8080

Tested and works. There are lots of variants of this that don't work -- ymmv.

Example script

Customize the script to fit your environment -- this version assumes a firewall that blocks off all but three incoming ports.


#!/bin/bash
#
# stream <input file> <port>
#
# Stream a video file to the network
#
# ------------------------------------------------------------------------

# Check for filename parameter
if [ -z "$1" ]
 then
  echo "Use stream <input file> <port>";
  echo "Which file do you want to stream?";
   exit
fi

# Check for file presence
if [ -e "$1" ]
 then echo "Found" $1
 else echo "There's no" $1
  exit
fi

# Check for port parameter
if [ -z "$2" ]
 then
  echo "Use stream <input file> <port>";
  echo "Which port do you want to stream to? (use 5003, 5900, or 8080)";
   exit
fi

# Check port parameter value (if you're behind a firewall)
if [ "$2" = "5003" -o "$2" = "5900" -o "$2" = "8080" ]
  then echo "";
  else echo "If you want to stream to this port, change this script!";
   exit
fi

starttim=$(date +%F\ %H:%M:%S)
startsec=$(date +%s)
echo "Streaming start time:" $starttim

 vlc $1 -I dummy --sout "#std{access=mmsh,dst=:$2}" --ttl 12 --loop;

echo "Streaming start time:" $starttim
echo "Streaming end time  :" $(date +%F\ %H:%M:%S)
endsec=$(date +%s)
echo "Total streaming time in seconds:" $(( $endsec - $startsec ))

This makes it very easy to ssh into a remote machine and issue something like,

stream filename 8080 &

You can then type "exit", but to release your terminal you will have to kill that ssh session on your local machine.

More elegantly, you can start a screen session and run the stream inside it:

screen
stream filename 8080

Press ctrl-a d to detach; you are now free to leave the machine. To check out the stream or stop it, ssh back to the remote machine and press ctrl-a r. You can of course have several screen sessions running, each with its own video stream.

CPU consumption of these streams is modest, but beware: they simply shift the load over to the router, so you can get a very clogged router.