From 372de844430fceba8a7c7635e7f404500d9b2bdd Mon Sep 17 00:00:00 2001 From: Antoine Van-Elstraete Date: Thu, 15 Apr 2021 15:10:17 +0200 Subject: [PATCH] =?UTF-8?q?Fonction=20de=20d=C3=A9tection=20de=20l'entrela?= =?UTF-8?q?cement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vid_convert.py | 56 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/vid_convert.py b/vid_convert.py index 7d4fc50..6e2e248 100755 --- a/vid_convert.py +++ b/vid_convert.py @@ -13,7 +13,15 @@ def get_infos(file): -> http://ffmpeg.org/ffprobe.html ''' - v_infos, a_infos = {}, {} + v_infos = { + 'height': None, + 'width': None, + 'color_primaries': None, + 'color_space': None, + 'color_transfer': None, + 'display_aspect_ratio': None + } + a_infos = {} v_infos_cmd = f"ffprobe -v quiet -print_format json -show_format -show_streams -select_streams v {file}" v_infos_raw = subprocess.getoutput(v_infos_cmd) a_infos_cmd = f"ffprobe -v quiet -print_format json -show_format -show_streams -select_streams a {file}" @@ -21,14 +29,11 @@ def get_infos(file): full_v_infos = json.loads(v_infos_raw) full_a_infos = json.loads(a_infos_raw) v_stream = full_v_infos['streams'][0] - v_infos.update({ - 'height': v_stream['height'], - 'width': v_stream['width'], - 'color_primaries': v_stream['color_primaries'], - 'color_space': v_stream['color_space'], - 'color_transfer': v_stream['color_transfer'], - 'dar': v_stream['display_aspect_ratio'] - }) + for prop in v_infos.keys(): + try: + v_infos.update({prop: v_stream[prop]}) + except KeyError: + pass a_infos = [] for a_stream in full_a_infos['streams']: a_stream_infos = { @@ -43,6 +48,36 @@ def get_infos(file): return infos +def interlaced(file, infos): + ''' + Cette fonction detecte si la vidéo est entrelacée. + -> https://fr.wikipedia.org/wiki/Entrelacement_(vid%C3%A9o) + ''' + duration_tier = int(infos['duration'] / 3) + command = f"ffmpeg -loglevel info -ss {duration_tier} -t {duration_tier} -i {file} -an -filter:v idet -f null -y /dev/null" + result = subprocess.getoutput(command) + for line in result.splitlines(): + if "Multi" in line: + TFF = int(line.split('TFF:')[1].split()[0]) + BFF = int(line.split('BFF:')[1].split()[0]) + Progressive = int(line.split('Progressive:')[1].split()[0]) + if "frame= " in line: + total_frame = int(line.split()[1]) + elif "frame=" in line: + total_frame = int(line.split()[0].split("=")[1]) + try: + pct = ((TFF + BFF) / (TFF + BFF + Progressive)) * 100 + pct = round(pct) + except ZeroDivisionError: + pct = 100 + if pct > 10: + logging.debug("Vidéo entrelacée à {pct}%") + return True + else: + logging.debug("Vidéo non entrelacée") + return False + + if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() @@ -53,4 +88,5 @@ if __name__ == '__main__': logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S') else: logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.INFO, datefmt='%d/%m/%Y %H:%M:%S') - get_infos(args.f_input) + infos = get_infos(args.f_input) + interlaced = interlaced(args.f_input, infos)