encodage vidéo, gestion HDR10
This commit is contained in:
parent
724aaf6bcd
commit
ed42ca0aa9
@ -20,11 +20,11 @@ def get_infos(file):
|
||||
'color_primaries': None,
|
||||
'color_space': None,
|
||||
'color_transfer': None,
|
||||
'pix_fmt': None,
|
||||
'display_aspect_ratio': None,
|
||||
'pix_fmt': 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 -show_frames -read_intervals "%+#1" -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)
|
||||
@ -36,6 +36,10 @@ def get_infos(file):
|
||||
v_infos.update({prop: v_stream[prop]})
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
v_infos.update({'side_data_list': full_v_infos['frames'][0]['side_data_list']})
|
||||
except KeyError:
|
||||
pass
|
||||
a_infos = []
|
||||
for a_stream in full_a_infos['streams']:
|
||||
a_stream_infos = {
|
||||
@ -133,6 +137,52 @@ def convert_audio(file, track, volume_adj, channels, channel_layout, language, t
|
||||
logging.info(result)
|
||||
|
||||
|
||||
def convert_video(file, infos, start, crop, crf):
|
||||
output = f'{file}_video_t{start}.mkv'
|
||||
fmt = infos['video']['pix_fmt']
|
||||
track = infos['video']['index']
|
||||
codec = 'libx265 -crf {crf} -preset slower'
|
||||
if 'side_data_list' in infos['video'].keys():
|
||||
light_level = f"{infos['video']['side_data_list'][1]['max_content']},{infos['video']['side_data_list'][1]['max_average']}"
|
||||
color_primaries = infos['video']['color_primaries']
|
||||
color_transfer = infos['video']['color_transfer']
|
||||
color_space = infos['video']['color_space']
|
||||
green_x = infos['video']['side_data_list'][0]['green_x'].split('/')
|
||||
green_x = int(int(green_x[0])*(int(green_x[1])/50000))
|
||||
green_y = infos['video']['side_data_list'][0]['green_y'].split('/')
|
||||
green_y = int(int(green_y[0])*(int(green_y[1])/50000))
|
||||
green = f'G({green_x},{green_y})'
|
||||
blue_x = infos['video']['side_data_list'][0]['blue_x'].split('/')
|
||||
blue_x = int(int(blue_x[0])*(int(blue_x[1])/50000))
|
||||
blue_y = infos['video']['side_data_list'][0]['blue_y'].split('/')
|
||||
blue_y = int(int(blue_y[0])*(int(blue_y[1])/50000))
|
||||
blue = f'B({blue_x},{blue_y})'
|
||||
red_x = infos['video']['side_data_list'][0]['red_x'].split('/')
|
||||
red_x = int(int(red_x[0])*(int(red_x[1])/50000))
|
||||
red_y = infos['video']['side_data_list'][0]['red_y'].split('/')
|
||||
red_y = int(int(red_y[0])*(int(red_y[1])/50000))
|
||||
red = f'R({red_x},{red_y})'
|
||||
white_point_x = infos['video']['side_data_list'][0]['white_point_x'].split('/')
|
||||
white_point_x = int(int(white_point_x[0])*(int(white_point_x[1])/50000))
|
||||
white_point_y = infos['video']['side_data_list'][0]['white_point_y'].split('/')
|
||||
white_point_y = int(int(white_point_y[0])*(int(white_point_y[1])/50000))
|
||||
white_point = f'WP({white_point_x},{white_point_y})'
|
||||
min_luminance = infos['video']['side_data_list'][0]['min_luminance'].split('/')
|
||||
min_luminance = int(int(min_luminance[0])*(int(min_luminance[1])/10000))
|
||||
max_luminance = infos['video']['side_data_list'][0]['max_luminance'].split('/')
|
||||
max_luminance = int(int(max_luminance[0])*(int(max_luminance[1])/10000))
|
||||
luminance = f'L({max_luminance},{min_luminance})'
|
||||
master_display = green + blue + red + white_point + luminance
|
||||
hdr = f'-x265-params hdr-opt=1:repeat-headers=1:colorprim={color_primaries}:transfer={color_transfer}:colormatrix={color_space}:master-display={master_display}:max-cll={light_level}'
|
||||
else:
|
||||
hdr = ""
|
||||
command = f'ffmpeg -loglevel error -i {file} -map 0:{track} -ss {start} -t 300 -an -sn -c:v {codec} {hdr} -crf {crf} -pix_fmt {fmt} -filter:v {crop} -y {output}'
|
||||
logging.debug(command)
|
||||
import pdb; pdb.set_trace()
|
||||
result = subprocess.getoutput(command)
|
||||
logging.info(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
@ -153,3 +203,8 @@ if __name__ == '__main__':
|
||||
stabilization(file)
|
||||
for track in infos['audio']:
|
||||
convert_audio(file, track['index'], volumes[track['index']], track['channels'], track['channel_layout'], track['language'], track['title'])
|
||||
vid_part_time = 0
|
||||
crf = 20
|
||||
while vid_part_time < infos['duration']:
|
||||
convert_video(file, infos, vid_part_time, cropsize, crf)
|
||||
vid_part_time += 300
|
||||
|
Loading…
Reference in New Issue
Block a user