diff --git a/fHDHR/device/tuners/stream/ffmpeg_stream.py b/fHDHR/device/tuners/stream/ffmpeg_stream.py index 834031a..81133b8 100644 --- a/fHDHR/device/tuners/stream/ffmpeg_stream.py +++ b/fHDHR/device/tuners/stream/ffmpeg_stream.py @@ -103,44 +103,61 @@ class FFMPEG_Stream(): return ffmpeg_command 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"]: self.fhdhr.logger.info("Client requested a %s transcode for stream." % stream_args["transcode_quality"]) - stream_args["transcode_quality"] = None ffmpeg_command = [] - if not stream_args["transcode_quality"]: - ffmpeg_command.extend( - [ - "-c", "copy", - "-f", "mpegts", - ] - ) - elif stream_args["transcode_quality"] == "heavy": - ffmpeg_command.extend([]) + if not stream_args["transcode_quality"] or stream_args["transcode_quality"] == "heavy": + ffmpeg_command.extend([ + "-c", "copy", + "-f", "mpegts" + ]) + 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": - ffmpeg_command.extend([]) + ffmpeg_command.extend([ + "-c", "copy", + "-s", "1280X720", + "-b:v", "1000k", + "-b:a", "196k", + "-f", "mpegts" + ]) + 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": - ffmpeg_command.extend([]) + ffmpeg_command.extend([ + "-c", "copy", + "-s", "640X360", + "-b:v", "250k", + "-b:a", "96k", + "-f", "mpegts" + ]) + 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 diff --git a/fHDHR/device/tuners/stream/vlc_stream.py b/fHDHR/device/tuners/stream/vlc_stream.py index 702ba08..8747055 100644 --- a/fHDHR/device/tuners/stream/vlc_stream.py +++ b/fHDHR/device/tuners/stream/vlc_stream.py @@ -86,42 +86,73 @@ class VLC_Stream(): 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 - """ vlc_command = [] if 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=-}" - return [vlc_transcode_string] - - '#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": + transcode_dict = {} + if not stream_args["transcode_quality"] or stream_args["transcode_quality"] == "heavy": + # dummy do nothing line vlc_command.extend([]) + 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": - vlc_command.extend([]) + transcode_dict["transcode"] = { + "width": "1280", + "height": "720", + "vb": "1000", + "ab": "196" + } + 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": - vlc_command.extend([]) + transcode_dict["transcode"] = { + "width": "640", + "height": "360", + "vb": "250", + "ab": "96" + } + 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 diff --git a/fHDHR_web/api/tuners.py b/fHDHR_web/api/tuners.py index f5b3084..0e3aa88 100644 --- a/fHDHR_web/api/tuners.py +++ b/fHDHR_web/api/tuners.py @@ -53,10 +53,7 @@ class Tuners(): duration = request.args.get('duration', default=0, type=int) transcode_quality = request.args.get('transcode', default=None, type=str) - valid_transcode_types = [ - None, "high", "medium", "low" - "heavy", "mobile", "internet720", "internet480", "internet360", "internet240" - ] + valid_transcode_types = [None, "heavy", "mobile", "internet720", "internet480", "internet360", "internet240"] if transcode_quality not in valid_transcode_types: response = Response("Service Unavailable", status=503) response.headers["X-fHDHR-Error"] = "802 - Unknown Transcode Profile" @@ -68,7 +65,7 @@ class Tuners(): "method": method, "duration": duration, "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, "client": client_address, "client_id": session["session_id"]