Encoding live streams

From Streaming 411

Jump to: navigation, search

Contents

Using VLC for encoding live stream

VLC is a free cross-platform media player http://www.videolan.org/. Precompiled binaries could be found at http://freshrpms.net/. Building from sources described at Building encoding tools from scratch.

Encoding stream from DV source

In my case i used Canopus ADVC110 DV transcoder.

Method #1 (using dv1394 kernel module)

Before start VLC we need to load dv1394 module:
modprobe dv1394
On next step it should be created device for handling stream. For PAL source from first Firewire adaptor (for more details see http://www.linux1394.org/dv1394.php):
mknod -m 666 /home/video/pal_dv_in0 c 171 34
After creating device you need check if it gives a DV stream and camera/converted properly switched:
cat /home/video/pal_dv_in0 > /tmp/0.dv>  # press ctrl-c in some seconds
ls -als /tmp/0.dv 
If resulting file /tmp/0.dv is not zero-sized - you can step further. Encoding stream (H263):
cat /home/video/pal_dv_in0 | vlc - :demux=rawdv :file-caching=20000 -I dummy vlc:quit
--sout '#transcode{vcodec=H263,fps=12.0,vb=32,width=176,height=144,deinterlace,
acodec=mp4a,ab=32,channels=2,samplerate=22100}:rtp{dst=10.2.2.1,port-audio=20000,
port-video=20002,sdp=file:///tmp/test1.sdp}'  --ttl 12 
Resulting stream is sent to host (where DSS installed) 10.2.2.1. You also need a copy .dsp file to DSS folder on server. I prefer to use scp to copy file on remote computer:
scp /tmp/test2.sdp root@10.2.2.1:/home/qtss/stream2.sdp
In the same manner encoding into mpeg4:
#MPEG4
cat pal_dv_in0 | vlc - :demux=rawdv :file-caching=20000 -I dummy vlc:quit 
--sout '#transcode{vcodec=mp4v,fps=12.0,vb=168,width=176,height=144,deinterlace,
acodec=mp4a,ab=32,channels=2,samplerate=22100}:rtp{dst=10.2.2.1,port-audio=20000,
port-video=20002,sdp=file:///tmp/test2.sdp}'  --ttl 12 

Method #2 (using libavc1394)

To enable use dv/rawdv:///dev/raw1394 source VLC should be compiled with --enable-dv options.

Syntax for accessing dv source:
#H263
vlc -vvv -I dummy dv/rawdv:///dev/raw1394 --dv-caching 10000 vlc:quit 
--sout '#transcode{vcodec=H263,vb=168,width=176,height=144,deinterlace,
acodec=mp4a,ab=32,channels=2,samplerate=22100}:rtp{dst=10.2.2.1,port-audio=20000,
port-video=20002,sdp=file:///tmp/test2.sdp}'  --ttl 12

#MPEG4
vlc -vvv -I dummy dv/rawdv:///dev/raw1394 --dv-caching 10000 vlc:quit 
--sout '#transcode{vcodec=mp4v,vb=32,width=176,height=144,deinterlace,
acodec=mp4a,ab=24,channels=2,samplerate=22100}:rtp{dst=10.2.2.1,port-audio=20000,
port-video=20002,sdp=file:///tmp/test2.sdp}'  --ttl 12

Multiple streams

Multiple stream could be sent using duplicate feature of VLC. For example:
vlc -vvv -I dummy dv/rawdv:///dev/raw1394 --dv-caching 10000 vlc:quit --sout '#duplicate{
dst="transcode{vcodec=H263,vb=32,width=176,height=144,fps=5,deinterlace,
acodec=mp4a,ab=32,channels=2,samplerate=22100}:rtp{dst=10.2.2.1,port-audio=20000,
port-video=20002,sdp=file:///tmp/test4a.sdp}",
dst="transcode{vcodec=H263,vb=64,width=176,height=144,deinterlace,
acodec=mp4a,ab=32,fps=10,channels=2,samplerate=22100}:rtp{dst=10.2.2.1,
port-audio=20004,port-video=20006,sdp=file:///tmp/test4b.sdp}"}' 2>/dev/null

After starting encoding upload created .sdp files to DSS root folder.

Transcoding stream from another live stream

VLC can be used to transcode practically any stream into any other stream (depending on what codecs are built info VLC or ffmpeg) and distribute it via QTSS/DSS.

A sample script to open an AXIS network camera MJPEG feed, transcode it to H263 an distribute via DSS:

vlc -vvv --http-reconnect --noaudio --loop http://mywebcam.domain.com:8181/axis-cgi/mjpg/video.cgi?resolution=320x240
 --sout '#transcode{vcodec=H263,venc=ffmpeg{keyint=25},vb=256,width=176,height=144,fps=5}
 :rtp{dst=127.0.0.1,port-video=9250,sdp=file:///tmp/webcam.sdp}'

Again, after starting encoding upload created .sdp files to DSS root folder.

Almost anything that VLC play can also be transcoded!

Using MP4LIVE

Encoding stream from V4L2+ALSA/OSS devices

mp4live is part of MPEG4IP projects (www.mpeg4ip.net).

IMHO its greatest tools for enconding live streams with very flexible structure.

It supports AMR/AAC, h264,h263,MPEG4 codecs, V4L2 as video input device, OSS/ALSA as audio input device. Generating multiple streams (from defined profiles).

After configuring streams throw the GUI its possible to start mp4live in "unattended" mode (no GUI + automatic start):

[root@dev-3 ~]# mp4live --automatic --headless

Do not forget to copy created .sdp files to DSS root folder.

Personal tools