57 lines
2.1 KiB
Python
Executable File
57 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import json
|
|
import subprocess
|
|
import logging
|
|
|
|
|
|
def get_infos(file):
|
|
'''
|
|
Cette fonction extrait les informations du film à l'aide de ffprobe et les stocke
|
|
dans un dictionnaire pour une utilisation ultérieure.
|
|
|
|
-> http://ffmpeg.org/ffprobe.html
|
|
'''
|
|
v_infos, 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}"
|
|
a_infos_raw = subprocess.getoutput(a_infos_cmd)
|
|
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']
|
|
})
|
|
a_infos = []
|
|
for a_stream in full_a_infos['streams']:
|
|
a_stream_infos = {
|
|
'index': a_stream['index'],
|
|
'channels': a_stream['channels']}
|
|
a_infos.append(a_stream_infos)
|
|
duration = subprocess.getoutput(f"ffprobe -v quiet -print_format json -show_format {file}")
|
|
duration = json.loads(duration)
|
|
duration = float(duration['format']['duration'])
|
|
infos = {'duration': duration, 'video': v_infos, 'audio': a_infos}
|
|
logging.debug("Informations du film : \n" + json.dumps(infos, indent=True))
|
|
return infos
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import argparse
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("f_input")
|
|
parser.add_argument("-d", "--debug", dest='debug', action='store_true')
|
|
args = parser.parse_args()
|
|
if args.debug:
|
|
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)
|