Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve mp4 streaming video on Google App Engine Blobstore

I am using GAE to serve large files, and I can successfully serve mp3 using a simple blobstoreService.serve(key, res); If I put the resource url in the browser, the media control will appear and/or the media player will start, and the music will start before the download is complete.

However, when I put a mp4 url in the Chrome, the control appears but nothing happens. Here are what I have done:

  1. no content disposition to avoid download. If I put the content disposition, then the browser will download the video.
  2. I even used ffmpeg to convert the video and put -movflags faststart option there but no difference.
  3. I also set the response header to Accept-Ranges:bytes to the first request and I have observed that the next request still asks for full 75MB range. Should I only serve partially even though the browser asks for all?
  4. Or how to let the browser know that I wanted to serve piece by piece so the requests will have ranges. Is content-length necessary? Should I process the HEAD request? I believe right now my servlet only processes GET.
  5. my url is like http://www.somesite.com/serve?folder=aa&file=ok.MP4 the Chrome console shows that only 1MB is downloaded and then it stopped
  6. The html code looks like below except my GAE url is the src. The example mp4 works but if my gae link is there, it doesn't show video at all.

    <video width="640" controls=""> <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> Your browser does not support HTML5 video. </video>

Question

What exactly are needed to do on GAE server side to serve the video using streaming?

Answer

The marked answer has sufficient information on how to serve the mp4 file and it also gives a live web page for demo. From that demo, I was able to tell that my site could serve an mp4 file as long as the Chrome browser could decode it. The problem I encountered was due to the codec used in ffmpeg wasn't recognized by Chrome. Changed to H.264, everything worked fine.

Here is one example of the ffmpeg command line, where OK.MTS is the camcorder file, output1.mp4 is to be uploaded:

ffmpeg -i ok.MTS -codec:v libx264 -profile:v baseline -preset slow -b:v 500k -maxrate 800k -bufsize 1000k -vf scale=-1:432 -threads 0 -b:a 96k output1.mp4
like image 506
Hai Bi Avatar asked Dec 25 '22 01:12

Hai Bi


1 Answers

Is your handler putting the correct Content-Type in the response headers? You need to be setting "Content-Type:video/mp4" for the video to play correctly.

Here is a test site I wrote on App Engine that plays mp3, ogg and mp4 files from Cloud Storage and the BlobStore.

Here is a link to an mp4 file in the BlobStore that uses serve() to return the file. When I paste this link into chrome the content plays correctly.

like image 62
Stuart Langley Avatar answered Dec 28 '22 10:12

Stuart Langley