Really Dumb HTML5 Video Tag Back-end
Written by
on
in
Snaking.
So you want to create a stupid-and-dirty HTML5 video tag to allow you to monitor a (local-only) multicast stream from your (Django + Nginx) web site? Not something to be seen by "real people", but a way for you to see if anything is broadcasting?
This is a pretty simplistic thing, again; do *not* do this on a production site!
@permission_required( 'videostream' ) def video( request, channel=None, scale=2 ): """Stream video content to the client""" uri = 'udp://%s:%s'%( channel.target_ip, channel.target_port ) width,height = [int(x)//scale for x in channel.resolution.split('x') ] def stream( ): command = [ 'gst-launch', '-e', '-q', 'udpsrc','uri=%s'%( uri, ),'!', 'tsdemux', '!', 'ffdec_mpeg2video', '!', 'ffmpegcolorspace', '!', 'videoscale', '!', 'video/x-raw-yuv,framerate=25/1,width=%s,height=%s'%(width,height),'!', 'theoraenc', 'quality=63','keyframe-force=10','!', 'oggmux', '!', 'fdsink', 'async=true', ] pipe = subprocess.Popen( command, stdout=subprocess.PIPE, bufsize=-1, shell=False ) CHUNK = 8192 while pipe.poll() is None: yield pipe.stdout.read(CHUNK) return HttpResponse( stream(), content_type='video/ogg' )
Then you just create a simple HTML5 reference to the video and you're off to the races:
<video src="{% url 'video' channel=channel.id%}" poster="{% url 'channel_screenshot' channel=channel.id %}" autoplay="autoplay" > Your browser does not appear to support Ogg Theora Video, please use Firefox 3.5 or above, or Chrome 3.0 or above to view the video. </video>
Again: do *NOT* do this, your server will melt down if more than one or two people view the content, and you likely don't have a license for the codecs, and the results are not particularly good looking. That said, it's a freaking cool thing to do just to play around with HTML5 video with no real investment in it.
Pingbacks
Pingbacks are closed.
Comments
Comments are closed.