1
0
mirror of https://github.com/fHDHR/fHDHR_NextPVR.git synced 2025-12-06 10:16:58 -05:00

Merge pull request #5 from deathbybandaid/dev

Fix ffmpeg
This commit is contained in:
Deathbybandaid 2020-09-30 15:18:57 -04:00 committed by GitHub
commit 3e24fda3ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,6 @@ import json
import time import time
import requests import requests
import subprocess import subprocess
import errno
import PIL.Image import PIL.Image
import PIL.ImageDraw import PIL.ImageDraw
import PIL.ImageFont import PIL.ImageFont
@ -111,7 +110,7 @@ class HDHR_Hub():
"TunerCount": self.config["fakehdhr"]["tuner_count"], "TunerCount": self.config["fakehdhr"]["tuner_count"],
"FirmwareVersion": self.config["dev"]["reporting_firmware_ver"], "FirmwareVersion": self.config["dev"]["reporting_firmware_ver"],
"DeviceID": self.config["main"]["uuid"], "DeviceID": self.config["main"]["uuid"],
"DeviceAuth": "nextpvrproxy", "DeviceAuth": "fHDHR",
"BaseURL": "http://" + base_url, "BaseURL": "http://" + base_url,
"LineupURL": "http://" + base_url + "/lineup.json" "LineupURL": "http://" + base_url + "/lineup.json"
} }
@ -247,7 +246,7 @@ class HDHR_HTTP_Server():
return Response(image, content_type='image/png', direct_passthrough=True) return Response(image, content_type='image/png', direct_passthrough=True)
@app.route('/watch', methods=['GET']) @app.route('/watch', methods=['GET'])
def watch_nothing(): def watch():
if 'method' in list(request.args.keys()): if 'method' in list(request.args.keys()):
if 'channel' in list(request.args.keys()): if 'channel' in list(request.args.keys()):
@ -283,39 +282,25 @@ class HDHR_HTTP_Server():
"-loglevel", "warning", "-loglevel", "warning",
"pipe:stdout" "pipe:stdout"
] ]
ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE) ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE)
def generate(): def generate():
try:
videoData = ffmpeg_proc.stdout.read(int(hdhr.config["ffmpeg"]["bytes_per_read"]))
while True: while True:
videoData = ffmpeg_proc.stdout.read(int(hdhr.config["ffmpeg"]["bytes_per_read"]))
if not videoData: if not videoData:
break break
else:
# from https://stackoverflow.com/questions/9932332
try: try:
yield videoData yield videoData
time.sleep(0.1) except Exception as e:
except IOError as e:
# Check we hit a broken pipe when trying to write back to the client
if e.errno == errno.EPIPE:
# Send SIGTERM to shutdown ffmpeg
ffmpeg_proc.terminate() ffmpeg_proc.terminate()
# ffmpeg writes a bit of data out to stderr after it terminates,
# need to read any hanging data to prevent a zombie process.
ffmpeg_proc.communicate() ffmpeg_proc.communicate()
break print("Connection Closed: " + str(e))
else: except GeneratorExit:
raise
videoData = ffmpeg_proc.stdout.read(int(hdhr.config["ffmpeg"]["bytes_per_read"]))
ffmpeg_proc.terminate() ffmpeg_proc.terminate()
try:
ffmpeg_proc.communicate() ffmpeg_proc.communicate()
except ValueError: print("Connection Closed.")
print("Connection Closed")
return Response(stream_with_context(generate()), mimetype="audio/mpeg") return Response(stream_with_context(generate()), mimetype="audio/mpeg")
abort(404) abort(404)