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

Implement Transcode Profiles for ffmpeg/vlc

This commit is contained in:
deathbybandaid 2021-01-21 11:46:44 -05:00
parent 03927ec495
commit 630b8dbf2b
3 changed files with 104 additions and 59 deletions

View File

@ -103,44 +103,61 @@ class FFMPEG_Stream():
return ffmpeg_command return ffmpeg_command
def transcode_profiles(self, stream_args): def transcode_profiles(self, stream_args):
# TODO implement actual profiles here
"""
heavy: transcode to AVC with the same resolution, frame-rate, and interlacing as the
original stream. For example 1080i60 AVC 1080i60, 720p60 AVC 720p60.
mobile: trancode to AVC progressive not exceeding 1280x720 30fps.
internet720: transcode to low bitrate AVC progressive not exceeding 1280x720 30fps.
internet480: transcode to low bitrate AVC progressive not exceeding 848x480 30fps for
16:9 content, not exceeding 640x480 30fps for 4:3 content.
internet360: transcode to low bitrate AVC progressive not exceeding 640x360 30fps for
16:9 content, not exceeding 480x360 30fps for 4:3 content.
internet240: transcode to low bitrate AVC progressive not exceeding 432x240 30fps for
16:9 content, not exceeding 320x240 30fps for 4:3 content
"""
if stream_args["transcode_quality"]: if stream_args["transcode_quality"]:
self.fhdhr.logger.info("Client requested a %s transcode for stream." % stream_args["transcode_quality"]) self.fhdhr.logger.info("Client requested a %s transcode for stream." % stream_args["transcode_quality"])
stream_args["transcode_quality"] = None
ffmpeg_command = [] ffmpeg_command = []
if not stream_args["transcode_quality"]: if not stream_args["transcode_quality"] or stream_args["transcode_quality"] == "heavy":
ffmpeg_command.extend( ffmpeg_command.extend([
[
"-c", "copy", "-c", "copy",
"-f", "mpegts", "-f", "mpegts"
] ])
)
elif stream_args["transcode_quality"] == "heavy":
ffmpeg_command.extend([])
elif stream_args["transcode_quality"] == "mobile": elif stream_args["transcode_quality"] == "mobile":
ffmpeg_command.extend([]) ffmpeg_command.extend([
"-c", "copy",
"-s", "1280X720",
"-b:v", "500k",
"-b:a", "128k",
"-f", "mpegts"
])
elif stream_args["transcode_quality"] == "internet720": elif stream_args["transcode_quality"] == "internet720":
ffmpeg_command.extend([]) ffmpeg_command.extend([
"-c", "copy",
"-s", "1280X720",
"-b:v", "1000k",
"-b:a", "196k",
"-f", "mpegts"
])
elif stream_args["transcode_quality"] == "internet480": elif stream_args["transcode_quality"] == "internet480":
ffmpeg_command.extend([]) ffmpeg_command.extend([
"-c", "copy",
"-s", "848X480",
"-b:v", "400k",
"-b:a", "128k",
"-f", "mpegts"
])
elif stream_args["transcode_quality"] == "internet360": elif stream_args["transcode_quality"] == "internet360":
ffmpeg_command.extend([]) ffmpeg_command.extend([
"-c", "copy",
"-s", "640X360",
"-b:v", "250k",
"-b:a", "96k",
"-f", "mpegts"
])
elif stream_args["transcode_quality"] == "internet240": elif stream_args["transcode_quality"] == "internet240":
ffmpeg_command.extend([]) ffmpeg_command.extend([
"-c", "copy",
"-s", "432X240",
"-b:v", "250k",
"-b:a", "96k",
"-f", "mpegts"
])
return ffmpeg_command return ffmpeg_command

View File

@ -86,42 +86,73 @@ class VLC_Stream():
def transcode_profiles(self, stream_args): def transcode_profiles(self, stream_args):
# TODO implement actual profiles here # TODO implement actual profiles here
"""
heavy: transcode to AVC with the same resolution, frame-rate, and interlacing as the
original stream. For example 1080i60 AVC 1080i60, 720p60 AVC 720p60.
mobile: trancode to AVC progressive not exceeding 1280x720 30fps.
internet720: transcode to low bitrate AVC progressive not exceeding 1280x720 30fps.
internet480: transcode to low bitrate AVC progressive not exceeding 848x480 30fps for
16:9 content, not exceeding 640x480 30fps for 4:3 content.
internet360: transcode to low bitrate AVC progressive not exceeding 640x360 30fps for
16:9 content, not exceeding 480x360 30fps for 4:3 content.
internet240: transcode to low bitrate AVC progressive not exceeding 432x240 30fps for
16:9 content, not exceeding 320x240 30fps for 4:3 content
"""
vlc_command = [] vlc_command = []
if stream_args["transcode_quality"]: if stream_args["transcode_quality"]:
self.fhdhr.logger.info("Client requested a %s transcode for stream." % stream_args["transcode_quality"]) self.fhdhr.logger.info("Client requested a %s transcode for stream." % stream_args["transcode_quality"])
stream_args["transcode_quality"] = None
vlc_transcode_string = "#std{mux=ts,access=file,dst=-}" transcode_dict = {}
return [vlc_transcode_string] if not stream_args["transcode_quality"] or stream_args["transcode_quality"] == "heavy":
# dummy do nothing line
'#transcode{vcodec=mp2v,vb=4096,acodec=mp2a,ab=192,scale=1,channels=2,deinterlace}:std{access=file,mux=ts,dst=-"}'
if not stream_args["transcode_quality"]:
vlc_command.extend([])
elif stream_args["transcode_quality"] == "heavy":
vlc_command.extend([]) vlc_command.extend([])
elif stream_args["transcode_quality"] == "mobile": elif stream_args["transcode_quality"] == "mobile":
vlc_command.extend([]) transcode_dict["transcode"] = {
"width": "1280",
"height": "720",
"vb": "500",
"ab": "128"
}
elif stream_args["transcode_quality"] == "internet720": elif stream_args["transcode_quality"] == "internet720":
vlc_command.extend([]) transcode_dict["transcode"] = {
"width": "1280",
"height": "720",
"vb": "1000",
"ab": "196"
}
elif stream_args["transcode_quality"] == "internet480": elif stream_args["transcode_quality"] == "internet480":
vlc_command.extend([]) transcode_dict["transcode"] = {
"width": "848",
"height": "480",
"vb": "400",
"ab": "128"
}
elif stream_args["transcode_quality"] == "internet360": elif stream_args["transcode_quality"] == "internet360":
vlc_command.extend([]) transcode_dict["transcode"] = {
"width": "640",
"height": "360",
"vb": "250",
"ab": "96"
}
elif stream_args["transcode_quality"] == "internet240": elif stream_args["transcode_quality"] == "internet240":
vlc_command.extend([]) transcode_dict["transcode"] = {
"width": "432",
"height": "240",
"vb": "250",
"ab": "96"
}
transcode_dict["std"] = {
"mux": "ts",
"access": "file",
"dst": "-"
}
topkey_index = 0
vlc_transcode_string = ""
for topkey in list(transcode_dict.keys()):
if not topkey_index:
topkey_index += 1
vlc_transcode_string += "#"
else:
vlc_transcode_string += ":"
vlc_transcode_string += "%s{" % topkey
vlc_transcode_string += ",".join(["%s=%s" % (x, transcode_dict[topkey][x]) for x in list(transcode_dict[topkey].keys())])
vlc_transcode_string += "}"
vlc_command.extend([vlc_transcode_string])
return vlc_command return vlc_command

View File

@ -53,10 +53,7 @@ class Tuners():
duration = request.args.get('duration', default=0, type=int) duration = request.args.get('duration', default=0, type=int)
transcode_quality = request.args.get('transcode', default=None, type=str) transcode_quality = request.args.get('transcode', default=None, type=str)
valid_transcode_types = [ valid_transcode_types = [None, "heavy", "mobile", "internet720", "internet480", "internet360", "internet240"]
None, "high", "medium", "low"
"heavy", "mobile", "internet720", "internet480", "internet360", "internet240"
]
if transcode_quality not in valid_transcode_types: if transcode_quality not in valid_transcode_types:
response = Response("Service Unavailable", status=503) response = Response("Service Unavailable", status=503)
response.headers["X-fHDHR-Error"] = "802 - Unknown Transcode Profile" response.headers["X-fHDHR-Error"] = "802 - Unknown Transcode Profile"
@ -68,7 +65,7 @@ class Tuners():
"method": method, "method": method,
"duration": duration, "duration": duration,
"origin_quality": self.fhdhr.config.dict["streaming"]["origin_quality"], "origin_quality": self.fhdhr.config.dict["streaming"]["origin_quality"],
"transcode_quality": transcode_quality, "transcode_quality": transcode_quality or self.fhdhr.config.dict["streaming"]["transcode_quality"],
"accessed": accessed_url, "accessed": accessed_url,
"client": client_address, "client": client_address,
"client_id": session["session_id"] "client_id": session["session_id"]