def test_stream_exclude(self): with open('tests/ffmpeg3.out', 'r') as ff: info = MediaInfo.parse_ffmpeg_details('/dev/null', ff.read()) setup = ConfigFile(self.get_setup()) p = setup.get_profile('excl_test_1') streams = info.ffmpeg_streams(p) self.assertEqual(len(streams), 12, 'expected 6 streams (12 elements)')
def test_stream_reassign_default(self): with open('tests/ffmpeg4.out', 'r') as ff: info = MediaInfo.parse_ffmpeg_details('/dev/null', ff.read()) setup = ConfigFile(self.get_setup()) p = setup.get_profile('excl_test_2') streams = info.ffmpeg_streams(p) self.assertEqual(len(streams), 8, 'expected 4 streams (8 elements)')
def test_stream_map_all(self): with open('tests/ffmpeg3.out', 'r') as ff: info = MediaInfo.parse_ffmpeg_details('/dev/null', ff.read()) setup = ConfigFile(self.get_setup()) p = setup.get_profile('qsv') streams = info.ffmpeg_streams(p) self.assertEqual(len(streams), 2, 'expected -map 0')
def test_skip_profile(self): with open('tests/ffmpeg.out', 'r') as ff: info = MediaInfo.parse_ffmpeg_details('/dev/null', ff.read()) info.filesize_mb = 499 config = ConfigFile(self.get_setup()) rule = config.match_rule(info) self.assertIsNotNone(rule, 'Expected rule match') self.assertTrue(rule.is_skip(), 'Expected a SKIP rule')
def test_mediainfo3(self): with open('tests/ffmpeg3.out', 'r') as ff: info = MediaInfo.parse_ffmpeg_details('/dev/null', ff.read()) self.assertIsNotNone(info) self.assertEqual(info.vcodec, 'hevc') self.assertEqual(info.res_width, 3840) self.assertEqual(info.fps, 23) self.assertEqual(info.runtime, (2 * 3600) + (5 * 60) + 53) self.assertEqual(info.path, '/dev/null') self.assertEqual(info.colorspace, 'yuv420p10le')
def test_mediainfo2(self): with open('tests/ffmpeg2.out', 'r') as ff: info = MediaInfo.parse_ffmpeg_details('/dev/null', ff.read()) self.assertIsNotNone(info) self.assertEqual(info.vcodec, 'h264') self.assertEqual(info.res_width, 1920) self.assertEqual(info.fps, 24) self.assertEqual(info.runtime, (52 * 60) + 49) self.assertEqual(info.path, '/dev/null') self.assertEqual(info.colorspace, 'yuv420p')
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.path, '-i', _path], stderr=subprocess.PIPE) as proc: output = proc.stderr.read().decode(encoding='utf8') mi = MediaInfo.parse_ffmpeg_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)