diff --git a/vid_convert.py b/vid_convert.py index 7ed0127..0eb3214 100755 --- a/vid_convert.py +++ b/vid_convert.py @@ -64,13 +64,15 @@ def get_infos(file): 'index': s_stream['index'], 'language': s_stream['tags']['language']} s_infos.append(s_stream_infos) - duration = subprocess.getoutput(f"ffprobe -v quiet -print_format json -show_format {file}") - duration = json.loads(duration) - duration = float(duration['format']['duration']) - hdr10_v_cmd = f'ffmpeg -loglevel panic -i {file} -c:v copy -vbsf hevc_mp4toannexb -f hevc - | hdr10plus_parser -o metadata.json --verify -' + format_data = json.loads(subprocess.getoutput(f"ffprobe -v quiet -print_format json -show_format {file}")) + duration = float(format_data['format']['duration']) + format_name = format_data.get('format', {}).get('format_name', '') + is_mp4_container = 'mp4' in format_name or 'mov' in format_name + bsf = '-vbsf hevc_mp4toannexb' if is_mp4_container else '' + hdr10_v_cmd = f'ffmpeg -loglevel panic -i {file} -c:v copy {bsf} -f hevc - | hdr10plus_parser --verify -' hdr10_v_raw = subprocess.getoutput(hdr10_v_cmd) if 'metadata detected' in hdr10_v_raw: - hdr10_cmd = f'ffmpeg -loglevel panic -i {file} -c:v copy -vbsf hevc_mp4toannexb -f hevc - | hdr10plus_parser -o /tmp/{file}_hdr10_metadata.json -' + hdr10_cmd = f'ffmpeg -loglevel panic -i {file} -c:v copy {bsf} -f hevc - | hdr10plus_parser -o /tmp/{file}_hdr10_metadata.json -' hdr10_cmd_res = subprocess.getoutput(hdr10_cmd) logging.debug(hdr10_cmd_res) v_infos.update({'hdr10plus': True, 'hdr10plus_metadata': f'/tmp/{file}_hdr10_metadata.json'})