try: from .base_engine import * except ImportError: from base_engine import * import re class FFMPEG(BaseRenderEngine): @classmethod def version(cls): version = None try: ver_out = subprocess.check_output([cls.renderer_path(), '-version'], timeout=SUBPROCESS_TIMEOUT).decode('utf-8') match = re.match(".*version\s*(\S+)\s*Copyright", ver_out) if match: version = match.groups()[0] except Exception as e: logger.error("Failed to get FFMPEG version: {}".format(e)) return version @classmethod def get_encoders(cls): raw_stdout = subprocess.check_output([cls.renderer_path(), '-encoders'], stderr=subprocess.DEVNULL, timeout=SUBPROCESS_TIMEOUT).decode('utf-8') pattern = '(?P[VASFXBD.]{6})\s+(?P\S{2,})\s+(?P.*)' encoders = [m.groupdict() for m in re.finditer(pattern, raw_stdout)] return encoders @classmethod def get_all_formats(cls): raw_stdout = subprocess.check_output([cls.renderer_path(), '-formats'], stderr=subprocess.DEVNULL, timeout=SUBPROCESS_TIMEOUT).decode('utf-8') pattern = '(?P[DE]{1,2})\s+(?P\S{2,})\s+(?P.*)' formats = [m.groupdict() for m in re.finditer(pattern, raw_stdout)] return formats @classmethod def get_output_formats(cls): return [x for x in cls.get_all_formats() if 'E' in x['type'].upper()] @classmethod def get_frame_count(cls, path_to_file): raw_stdout = subprocess.check_output([cls.renderer_path(), '-i', path_to_file, '-map', '0:v:0', '-c', 'copy', '-f', 'null', '-'], stderr=subprocess.STDOUT, timeout=SUBPROCESS_TIMEOUT).decode('utf-8') match = re.findall(r'frame=\s*(\d+)', raw_stdout) if match: frame_number = int(match[-1]) return frame_number if __name__ == "__main__": print(FFMPEG.get_frame_count('/Users/brett/Desktop/Big_Fire_02.mov'))