def fetch_details_ffprobe(self, _path: str) -> MediaInfo: ffprobe_path = str(PurePath(self.ffmpeg).parent.joinpath('ffprobe')) if not os.path.exists(ffprobe_path): return MediaInfo(None) args = [ ffprobe_path, '-v', '1', '-show_streams', '-print_format', 'json', '-i', _path ] with subprocess.Popen(args, stdout=subprocess.PIPE) as proc: output = proc.stdout.read().decode(encoding='utf8') info = json.loads(output) return MediaInfo.parse_details_json(_path, info)
def fetch_details(self, _path: str) -> MediaInfo: """Use HandBrakeCLI to get media information :param _path: Absolute path to media file :return: Instance of MediaInfo """ with subprocess.Popen([self.path, '--scan', '-i', _path], stderr=subprocess.PIPE) as proc: output = proc.stderr.read().decode(encoding='utf8') mi = MediaInfo.parse_handbrake_details(_path, output) if mi.valid: return mi return MediaInfo(None)
def make_media(path, vcodec, res_width, res_height, runtime, source_size, fps, colorspace, audio, subtitle) -> MediaInfo: info = { 'path': path, 'vcodec': vcodec, 'stream': 0, 'res_width': res_width, 'res_height': res_height, 'runtime': runtime, 'filesize_mb': source_size, 'fps': fps, 'colorspace': colorspace, 'audio': audio, 'subtitle': subtitle } return MediaInfo(info)
def fetch_details(self, _path: str) -> MediaInfo: """Use ffmpeg to get media information :param _path: Absolute path to media file :return: Instance of MediaInfo """ with subprocess.Popen([self.ffmpeg, '-i', _path], stderr=subprocess.PIPE) as proc: output = proc.stderr.read().decode(encoding='utf8') mi = MediaInfo.parse_details(_path, output) if mi.valid: return mi # try falling back to ffprobe, if it exists try: return self.fetch_details_ffprobe(_path) except Exception as ex: print("Unable to fallback to ffprobe - " + str(ex)) return MediaInfo(None)