Skip to content

Instantly share code, notes, and snippets.

@amcgregor
Created December 14, 2010 08:48
Show Gist options
  • Save amcgregor/740156 to your computer and use it in GitHub Desktop.
Save amcgregor/740156 to your computer and use it in GitHub Desktop.
A trivial example of a chunked response.
#!/usr/bin/env python
# encoding: utf-8
import logging
from marrow.server.http import HTTPServer
def hello(request):
def transcode_video(request):
# p-code ahoy!
video = Transcoder('mpeg4', 'h264', 'aac')
while True:
chunk = yield request['wsgi.input'].async_read, 4096
video.write(chunk)
chunk = yield video.async_read_remaining
yield chunk
return b'200 OK', [(b'Content-Type', b'video/mpeg4')], transcode_video()
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.DEBUG)
HTTPServer(None, 8080, application=hello).start()
#!/usr/bin/env python
# encoding: utf-8
import logging
from functools import partial
from marrow.server.http import HTTPServer
def hello(request):
# p-code ahoy!
video = load_video(request['REQUEST_PATH'])
target = video.stream_transcode('mpeg4', 'h264', 'aac') # container, video codec, audio codec
return b'200 OK', [(b'Content-Type', b'video/mpeg4')], iterate(partial(target.read, 4096), '')
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.DEBUG)
HTTPServer(None, 8080, application=hello).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment