Fonction de détection de l'entrelacement
This commit is contained in:
parent
e02889cee8
commit
372de84443
@ -13,7 +13,15 @@ def get_infos(file):
|
|||||||
|
|
||||||
-> http://ffmpeg.org/ffprobe.html
|
-> 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_cmd = f"ffprobe -v quiet -print_format json -show_format -show_streams -select_streams v {file}"
|
||||||
v_infos_raw = subprocess.getoutput(v_infos_cmd)
|
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}"
|
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_v_infos = json.loads(v_infos_raw)
|
||||||
full_a_infos = json.loads(a_infos_raw)
|
full_a_infos = json.loads(a_infos_raw)
|
||||||
v_stream = full_v_infos['streams'][0]
|
v_stream = full_v_infos['streams'][0]
|
||||||
v_infos.update({
|
for prop in v_infos.keys():
|
||||||
'height': v_stream['height'],
|
try:
|
||||||
'width': v_stream['width'],
|
v_infos.update({prop: v_stream[prop]})
|
||||||
'color_primaries': v_stream['color_primaries'],
|
except KeyError:
|
||||||
'color_space': v_stream['color_space'],
|
pass
|
||||||
'color_transfer': v_stream['color_transfer'],
|
|
||||||
'dar': v_stream['display_aspect_ratio']
|
|
||||||
})
|
|
||||||
a_infos = []
|
a_infos = []
|
||||||
for a_stream in full_a_infos['streams']:
|
for a_stream in full_a_infos['streams']:
|
||||||
a_stream_infos = {
|
a_stream_infos = {
|
||||||
@ -43,6 +48,36 @@ def get_infos(file):
|
|||||||
return infos
|
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__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser()
|
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')
|
logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.INFO, datefmt='%d/%m/%Y %H:%M:%S')
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user