edit log prints
This commit is contained in:
1 parent
67fdffbe10
commit
3a7a49ea4e
2 files changed
+41
-16
No files matched your search
@@ -30,6 +30,7 @@ def main():
|
|||||||
manual_mode = args.manual_mode
|
manual_mode = args.manual_mode
|
||||||
edit_mode = args.edit_mode
|
edit_mode = args.edit_mode
|
||||||
input_dir = args.input_dir
|
input_dir = args.input_dir
|
||||||
|
output_dir = args.output_dir
|
||||||
logs_dir = input_dir
|
logs_dir = input_dir
|
||||||
|
|
||||||
if args.cropsize_scale < 1 :
|
if args.cropsize_scale < 1 :
|
||||||
@@ -44,6 +45,8 @@ def main():
|
|||||||
input_list += glob.glob(os.path.join(input_dir, types))
|
input_list += glob.glob(os.path.join(input_dir, types))
|
||||||
input_list = sorted(input_list)
|
input_list = sorted(input_list)
|
||||||
print("[INFO]\t Input dir :", input_dir)
|
print("[INFO]\t Input dir :", input_dir)
|
||||||
|
print("[INFO]\t Ouput dir :", output_dir)
|
||||||
|
print("")
|
||||||
|
|
||||||
for vid_index, fpath in enumerate(input_list):
|
for vid_index, fpath in enumerate(input_list):
|
||||||
vid_name = os.path.basename(fpath)[:-4]
|
vid_name = os.path.basename(fpath)[:-4]
|
||||||
@@ -83,6 +86,7 @@ def main():
|
|||||||
elif retCode == 2:
|
elif retCode == 2:
|
||||||
crop_cfg.getVidInfo(fpath)
|
crop_cfg.getVidInfo(fpath)
|
||||||
continue
|
continue
|
||||||
|
print("")
|
||||||
|
|
||||||
crop_cfg.vidRelease()
|
crop_cfg.vidRelease()
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|||||||
+37
-16
@@ -164,14 +164,12 @@ def ffmpeg_encoding(args, vid_index, vid_num, cropPos, vid_name, fpath):
|
|||||||
debug_shortOutput = ""
|
debug_shortOutput = ""
|
||||||
if debug :
|
if debug :
|
||||||
debug_shortOutput = "-t 15 -ss 30"
|
debug_shortOutput = "-t 15 -ss 30"
|
||||||
|
|
||||||
crop_arg = f"crop={cropPos[0]}:{cropPos[1]}:{cropPos[2]}:{cropPos[3]}"
|
|
||||||
print(f"[INFO]\t [CropInfo] (W : {cropPos[0]}), (H : {cropPos[1]}), (X : {cropPos[2]}), (Y : {cropPos[3]})")
|
|
||||||
|
|
||||||
crop_arg = f"crop={cropPos[0]}:{cropPos[1]}:{cropPos[2]}:{cropPos[3]}"
|
crop_arg = f"crop={cropPos[0]}:{cropPos[1]}:{cropPos[2]}:{cropPos[3]}"
|
||||||
current_crop_ratio = cropPos[0] / cropPos[1]
|
current_crop_ratio = cropPos[0] / cropPos[1]
|
||||||
scale_arg = ""
|
scale_arg = ""
|
||||||
pad_arg = ""
|
pad_arg = ""
|
||||||
|
output_width, output_height = cropPos[0], cropPos[1]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Set padding(letter box) argument
|
Set padding(letter box) argument
|
||||||
@@ -183,8 +181,6 @@ def ffmpeg_encoding(args, vid_index, vid_num, cropPos, vid_name, fpath):
|
|||||||
if add_letterbox :
|
if add_letterbox :
|
||||||
# Always target 16:9 display ratio
|
# Always target 16:9 display ratio
|
||||||
target_ratio = 16 / 9
|
target_ratio = 16 / 9
|
||||||
print("[INFO]\t Target ratio : %.7f" %target_ratio)
|
|
||||||
|
|
||||||
# when current ratio is more flat
|
# when current ratio is more flat
|
||||||
if target_ratio < current_crop_ratio:
|
if target_ratio < current_crop_ratio:
|
||||||
# offset : simple equation (widht / (height + offset) = 16/9)
|
# offset : simple equation (widht / (height + offset) = 16/9)
|
||||||
@@ -195,7 +191,7 @@ def ffmpeg_encoding(args, vid_index, vid_num, cropPos, vid_name, fpath):
|
|||||||
tmp_height -= (tmp_height % 4)
|
tmp_height -= (tmp_height % 4)
|
||||||
pad_arg = f",pad={cropPos[0]}:{tmp_height}:(ow-iw)/2:(ih-oh)/2"
|
pad_arg = f",pad={cropPos[0]}:{tmp_height}:(ow-iw)/2:(ih-oh)/2"
|
||||||
scale_arg = f",scale=w={cropPos[0]}:h={tmp_height}"
|
scale_arg = f",scale=w={cropPos[0]}:h={tmp_height}"
|
||||||
print(f"[INFO]\t [PadInfo] (W : {cropPos[0]}), (H : {tmp_height})")
|
output_width, output_height = cropPos[0], tmp_height
|
||||||
else:
|
else:
|
||||||
offset = (16 * cropPos[1] - 9 * cropPos[0]) / 9
|
offset = (16 * cropPos[1] - 9 * cropPos[0]) / 9
|
||||||
tmp_width = cropPos[0] + offset
|
tmp_width = cropPos[0] + offset
|
||||||
@@ -204,11 +200,11 @@ def ffmpeg_encoding(args, vid_index, vid_num, cropPos, vid_name, fpath):
|
|||||||
tmp_width -= (tmp_width % 4)
|
tmp_width -= (tmp_width % 4)
|
||||||
pad_arg = f",pad={tmp_width}:{cropPos[1]}:(ow-iw)/2:(ih-oh)/2"
|
pad_arg = f",pad={tmp_width}:{cropPos[1]}:(ow-iw)/2:(ih-oh)/2"
|
||||||
scale_arg = f",scale=w={tmp_width}:h={cropPos[1]}"
|
scale_arg = f",scale=w={tmp_width}:h={cropPos[1]}"
|
||||||
print(f"[INFO]\t [PadInfo] (W : {tmp_width}), (H : {cropPos[1]})")
|
output_width, output_height = tmp_width, cropPos[1]
|
||||||
|
|
||||||
if not os.path.exists(output_dir) :
|
if not os.path.exists(output_dir) :
|
||||||
os.mkdir(output_dir)
|
os.mkdir(output_dir)
|
||||||
print(f'[INFO]\t folder created : {output_dir}')
|
# print(f'[INFO]\t folder created : {output_dir}')
|
||||||
|
|
||||||
output_path = os.path.join(output_dir, f"{vid_name}_box.mov")
|
output_path = os.path.join(output_dir, f"{vid_name}_box.mov")
|
||||||
|
|
||||||
@@ -230,14 +226,29 @@ def ffmpeg_encoding(args, vid_index, vid_num, cropPos, vid_name, fpath):
|
|||||||
ffmpeg_command = f"ffmpeg {debug_shortOutput} -i \"{fpath}\" -vf \"{crop_arg}{scale_arg}{pad_arg}{sharpen_arg}\"\
|
ffmpeg_command = f"ffmpeg {debug_shortOutput} -i \"{fpath}\" -vf \"{crop_arg}{scale_arg}{pad_arg}{sharpen_arg}\"\
|
||||||
-y -pix_fmt yuv420p -c:v libx264 -crf {crf} -c:a copy -preset medium -loglevel {loglevel}\
|
-y -pix_fmt yuv420p -c:v libx264 -crf {crf} -c:a copy -preset medium -loglevel {loglevel}\
|
||||||
{uhd_output_args} \"{output_path}\""
|
{uhd_output_args} \"{output_path}\""
|
||||||
print(ffmpeg_command)
|
|
||||||
print("[INFO]\t Encoding \"%s\" ..." % vid_name)
|
|
||||||
print("[INFO]\t Video CRF = %d" % int(crf))
|
|
||||||
|
|
||||||
# duration_list[0] : hour, [1] : min, [2] : sec
|
|
||||||
duration_list = getVideDuration(fpath)
|
duration_list = getVideDuration(fpath)
|
||||||
print(f"[INFO]\t Video Duration : {duration_list[0]:02d}:{duration_list[1]:02d}:{duration_list[2]:02d}\
|
vid_hour = duration_list[0]
|
||||||
Current Time : {getTime()}")
|
vid_min = duration_list[1]
|
||||||
|
vid_sec = duration_list[2]
|
||||||
|
# print("====================================================================")
|
||||||
|
print("[INFO]\t Encoding start \"%s\" ..." % vid_name)
|
||||||
|
print("[INFO]\t Video CRF : %d" % int(crf))
|
||||||
|
print("[INFO]\t Video Duration : %02d:%02d:%02d" % (vid_hour, vid_min, vid_sec))
|
||||||
|
print("[INFO]\t Pixel format : YUV420p")
|
||||||
|
print("[INFO]\t Video Codec : libx264")
|
||||||
|
print("[INFO]\t Encoding Preset : medium")
|
||||||
|
print(f"[INFO]\t Cropping Info : [W : {cropPos[0]} H : {cropPos[1]} X : {cropPos[2]} Y : {cropPos[3]}]")
|
||||||
|
print("[INFO]\t Crop area ratio : %.5f" %current_crop_ratio)
|
||||||
|
if add_letterbox :
|
||||||
|
print("[INFO]\t Target ratio : %.5f" %target_ratio)
|
||||||
|
if uhd_output :
|
||||||
|
print("[INFO]\t Output Resolution : 3840x2160")
|
||||||
|
else:
|
||||||
|
print("[INFO]\t Output Resolution : %dx%d" %(output_width, output_height))
|
||||||
|
if add_sharpening :
|
||||||
|
print("[INFO]\t Sharpening arg : %s" %sharpen_arg[1:])
|
||||||
|
print("====================================================================")
|
||||||
|
|
||||||
# st_time = time.time()
|
# st_time = time.time()
|
||||||
|
|
||||||
vid_index += 1
|
vid_index += 1
|
||||||
@@ -245,12 +256,18 @@ def ffmpeg_encoding(args, vid_index, vid_num, cropPos, vid_name, fpath):
|
|||||||
# Manual Mode (always encoding one by one)
|
# Manual Mode (always encoding one by one)
|
||||||
# Hold process when encoding last video
|
# Hold process when encoding last video
|
||||||
if vid_index == vid_num :
|
if vid_index == vid_num :
|
||||||
|
print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
||||||
|
Current Time : {getTime()}")
|
||||||
subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
||||||
else :
|
else :
|
||||||
subprocess.Popen(ffmpeg_command, shell=False)
|
subprocess.Popen(ffmpeg_command, shell=False)
|
||||||
else:
|
else:
|
||||||
# Log file mode (encoding simultaneously n videos)
|
# Log file mode (encoding simultaneously n videos)
|
||||||
if args.multi_encoding == 0:
|
if args.multi_encoding == 0:
|
||||||
|
# duration_list[0] : hour, [1] : min, [2] : sec
|
||||||
|
duration_list = getVideDuration(fpath)
|
||||||
|
print(f"[INFO]\t Video Duration : {duration_list[0]:02d}:{duration_list[1]:02d}:{duration_list[2]:02d}\
|
||||||
|
Current Time : {getTime()}")
|
||||||
p = subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
p = subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
||||||
|
|
||||||
# [21.12.08] progress status coding..
|
# [21.12.08] progress status coding..
|
||||||
@@ -263,6 +280,10 @@ def ffmpeg_encoding(args, vid_index, vid_num, cropPos, vid_name, fpath):
|
|||||||
# print('t',infos)
|
# print('t',infos)
|
||||||
# continue
|
# continue
|
||||||
elif (vid_index % args.multi_encoding == 0) or (vid_index == vid_num):
|
elif (vid_index % args.multi_encoding == 0) or (vid_index == vid_num):
|
||||||
|
# duration_list[0] : hour, [1] : min, [2] : sec
|
||||||
|
duration_list = getVideDuration(fpath)
|
||||||
|
print(f"[INFO]\t Video Duration : {duration_list[0]:02d}:{duration_list[1]:02d}:{duration_list[2]:02d}\
|
||||||
|
Current Time : {getTime()}")
|
||||||
subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
||||||
else :
|
else :
|
||||||
subprocess.Popen(ffmpeg_command, shell=False)
|
subprocess.Popen(ffmpeg_command, shell=False)
|
||||||
|
|||||||
Reference in new issue
Block a user