Created
January 18, 2010 09:24
-
-
Save dopuskh3/279906 to your computer and use it in GitHub Desktop.
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
class FlvFormater(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self, video_name): | |
self.set_header("Content-Type", "video/x-flv") | |
cmd = "/usr/local/bin/ffmpeg -i %s -f flv -acodec aac -s vga -"%video_name | |
self.ioloop = tornado.ioloop.IOLoop.instance() | |
self.pipe = cmdfd = os.popen(cmd) | |
#self.pipe = cmdfd = open("a.avi", "r") | |
self.ioloop.add_handler( cmdfd.fileno(), self.async_callback(self.on_read), self.ioloop.READ ) | |
def on_read(self, fd, events): | |
buffer = self.pipe.read(1024) | |
try: | |
assert buffer | |
self.write(buffer) | |
self.flush() | |
except: | |
self.pipe.close() | |
self.ioloop.remove_handler(fd) | |
self.finish() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment