From 724aaf6bcd63eef5bb24d47514a799aa628b6b01 Mon Sep 17 00:00:00 2001 From: Antoine Van-Elstraete Date: Sun, 20 Jun 2021 01:57:50 +0200 Subject: [PATCH] convertie l'audio. factorisation. --- vid_convert.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/vid_convert.py b/vid_convert.py index 76e8995..6e7b0d6 100755 --- a/vid_convert.py +++ b/vid_convert.py @@ -14,6 +14,7 @@ def get_infos(file): -> http://ffmpeg.org/ffprobe.html ''' v_infos = { + 'index': None, 'height': None, 'width': None, 'color_primaries': None, @@ -123,12 +124,13 @@ def stabilization(file): def convert_audio(file, track, volume_adj, channels, channel_layout, language, title): - bitrate = 64*channels + bitrate = f'{64*channels}k' codec = 'libopus' metadatas = f'-metadata language="{language}" -metadata title="{title}"' - command = f'ffmpeg -i {file} -map 0:{track} -vn -sn -c:a {codec} -b:a {bitrate} -mapping_family 1 -filter:a volume={volume_adj}dB,aformat=channel_layouts={channel_layout} -y {file}_audio_{track}.mka' - logging.debug{command} - + command = f'ffmpeg -loglevel error -i {file} -map 0:{track} -vn -sn -c:a {codec} -b:a {bitrate} -mapping_family 1 -filter:a volume={volume_adj},aformat=channel_layouts={channel_layout} -y {file}_audio_{track}.mka' + logging.debug(command) + result = subprocess.getoutput(command) + logging.info(result) if __name__ == '__main__': @@ -142,10 +144,12 @@ 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') - infos = get_infos(args.f_input) - interlaced = is_interlaced(args.f_input, infos) - cropsize = cropping(args.f_input, infos) - volumes = volume_audio(args.f_input, infos) + file = args.f_input + infos = get_infos(file) + interlaced = is_interlaced(file, infos) + cropsize = cropping(file, infos) + volumes = volume_audio(file, infos) if args.stab: - stabilization(args.f_input) - for + stabilization(file) + for track in infos['audio']: + convert_audio(file, track['index'], volumes[track['index']], track['channels'], track['channel_layout'], track['language'], track['title'])