H264 HTTP Test Stream Generator

As I haven't got an H264-capable camera to use as a test source (yet) I'm using the following GStreamer pipeline, adapted from videotestsrc documentation to generate an endless, mildly hypnotic low bitrate zone plate pattern wrapped in an MPEG transport stream. A clock is also shown so that when the stream is transcoded and/or segmented, it's easy to see how bad the lag is. Audio is not included but for example audiotestsrc could be plugged in the pipeline if necessary (although I won't be using audio in my app). VLC is used in the end of the command line to serve the stream over HTTP.
gst-launch-0.10 -v mpegtsmux name="mux" ! fdsink fd=1 »
videotestsrc pattern=zone-plate kx2=20 ky2=20 kt=1 ! »
video/x-raw-yuv,width=320,height=240 ! »
clockoverlay valign=bottom halign=left font-desc="Sans 23" ! »
ffmpegcolorspace ! videorate ! video/x-raw-yuv,framerate=15/1 ! »
x264enc bitrate=100000 cabac=false pass=qual quantizer=27 »
subme=4 threads=0 bframes=0 dct8x8=false ! mux. | »
vlc -I "dummy" file/ts:///dev/stdin »
:sout='#std{access=http{mime=video/mp4},mux=ts,dst=192.168.1.35:8000}'

Update: Here's how to save the encoded video to an MPEG-4 file:

gst-launch-0.10 -v videotestsrc num-buffers=900000 pattern=zone-plate kx2=20 ky2=20 kt=1 ! video/x-raw-yuv,width=1920,height=1080,framerate=25/1 ! x264enc bitrate=16000 cabac=false pass=qual quantizer=27 subme=4 threads=0 bframes=0 dct8x8=false ! queue ! muxer. ffmux_mp4 name=muxer ! filesink location=zone-plate-900000-frames-1920x1080-25fps.m4v

Tagged with:

Categorised as:


HTTP Live Streaming with VLC

Well, it took "a while" but I finally got HTTP Live Streaming working with VLC. Downloading and compiling the latest from Videolan's Git repo was required ("1.2.0-git Twoflower" here). I might add that even though on the box that I did this I've compiled a lot of different programs (an Ubuntu installation that has gone through multiple dist-upgrades so it's a few years old and has a lot of packages (2344 atm) installed), quite a few external -dev packages relating to audio and video had to be apt-get'ed to make things work. Below is the command to make VLC read a DVD and generate a segmented stream of H264 video and AAC audio to directory /var/www/html-video-stream/x/ on our local web server. In an IRL situation we would perhaps run the transcoder and segmenter instances on separate machines, or if we already had a suitable H264 stream source (like a camera) we could skip the transcoding step altogether.
vlc -v -I "dummy" dvdsimple:///dev/scd0 »
:sout="#transcode{vcodec=h264,vb=100, »
venc=x264{aud,profile=baseline,level=30,keyint=30,ref=1}, »
aenc=ffmpeg{aac-profile=low},acodec=mp4a,ab=32,channels=1,samplerate=8000} »
:std{access=livehttp{seglen=10,delsegs=true,numsegs=5, »
index=/var/www/html-video-stream/x/stream.m3u8, »
index-url=http://192.168.1.33/html-video-stream/x/stream-########.ts}, »
mux=ts{use-key-frames}, »
dst=/var/www/html-video-stream/x/stream-########.ts}"
  QuickTime X (fanboys have had this since Snow Leopard) supports HTTP Live Streaming, so in order to show the above stream on a web page in Safari using the <video> tag, we can do the following:
<video autoplay loop controls>
  <source src="http://192.168.1.33/html-video-stream/x/stream.m3u8" »
   type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'/>
  <!-- additional sources here -->
</video>
  Although I'm not sure if this will work in a situation where we attempt to feed H264 to clients that don't support HTTP Live Streaming, that is, we have an additional <source> element that points to a "regular" H264 HTTP stream. However, adding Ogg/Theora and WebM/VP8 support should not cause problems – I just haven't been able to make VLC output those (properly) yet. HTML5 video tag streaming support in different browsers is also one big question mark.

Tagged with:

Categorised as: