Created
December 14, 2010 08:48
-
-
Save amcgregor/740156 to your computer and use it in GitHub Desktop.
A trivial example of a chunked response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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