Really Dumb HTML5 Video Tag Back-end

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 = [
                'udpsrc','uri=%s'%( uri, ),'!',
                'tsdemux', '!',
                'ffdec_mpeg2video', '!',
                'ffmpegcolorspace', '!',
                'videoscale', '!',
                '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:
    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:

        src="{% url 'video'}" 
        poster="{% url 'channel_screenshot' %}" 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.

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.


Comments are closed.


Pingbacks are closed.