Stream Videos Easily

There’s a whole host of benefits when hosting videos on YouTube, but sometimes you want to just DIY.

Like Amazon and other massive cloud providers, it’s crazy easy and crazy scalable (these guys have way more stuff than you have stuff) for you DIYers.

I’ll show you how easy it is with a very simple example, all other deets stripped out for readability…

videoselectedmegafall

First, tell Google you’re about to upload a video.

In fact, Google doesn’t care what you upload, so call it a big ol’ Blob for lack of a better name.

from google.appengine.ext.webapp import blobstore_handlers

blobstore.create_upload_url('some URL of yours')

Next, when your web site user selects a blob/video off their computer, tablet or phone, handle it.

class SubmitNewPropp(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
inputUploads = self.get_uploads()
inputUploadedHybridFile = inputUploads[0]
blobkey = str(inputUploadedHybridFile.key())

Now that you’re done with that, let’s show it to the user.

Create a HTML5 tag.

<video width="420" height="420">
<source src="/servevideo/{{ blobvideokey }}" type="video/webm" />
<source src="/servevideo/{{ blobvideokey }}" type="video/mp4" />
<source src="/servevideo/{{ blobvideokey }}" type="video/ogg" />
Your browser does not support the video tag.
</video>

And of course, you have to be able to handle that request since the user has asked for it.

Serve it up

class ServeVideoHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)

And this isn’t just theory, I’ve done it using Google’s stuff. But who am I to tell you, go try it for yourself and let me know if you have any questions.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: