Created
June 7, 2021 11:32
-
-
Save an0ndev/4abbcb0b57be473749aaffc6bed68e28 to your computer and use it in GitHub Desktop.
stream.py: provides a stream of a macos primary display on a flask server at 0.0.0.0:5000 (warning: hardcoded path to ffmpeg, may need to change)
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
| import flask | |
| import subprocess | |
| app = flask.Flask (__name__) | |
| @app.route ("/") | |
| def root (): | |
| def gen (): | |
| popen = subprocess.Popen ("~/Documents/ffmpeg/ffmpeg -f avfoundation -i 1 -c:v libx264 -preset ultrafast -tune zerolatency -f matroska -", shell = True, stdout = subprocess.PIPE) | |
| # popen = subprocess.Popen ("ffmpeg/ffmpeg -f avfoundation -i 1 -c copy -f matroska -", shell = True, stdout = subprocess.PIPE) | |
| while True: | |
| print ("tryna read") | |
| data = popen.stdout.read (1024 * 1024) | |
| print ("read done") | |
| if not data: | |
| print ("shit ded") | |
| break | |
| print ("yielding") | |
| try: | |
| yield data | |
| except: | |
| popen.stdout.close () | |
| popen.terminate () | |
| print ("didnt yield") | |
| raise | |
| print ("yielded") | |
| print ("done i guess") | |
| return flask.Response (gen (), mimetype = "video/x-matroska") | |
| app.run (host = "0.0.0.0") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment