update
This commit is contained in:
1 parent
7897145524
commit
c6235e9034
6 files changed
+212
-66
No files matched your search
@@ -5,3 +5,4 @@ input/*
|
|||||||
logs/*
|
logs/*
|
||||||
out/*
|
out/*
|
||||||
test_video/*
|
test_video/*
|
||||||
|
capture_image/*
|
||||||
Binary file not shown.
+25
@@ -0,0 +1,25 @@
|
|||||||
|
# docker build -t pixtree/pillar_detection .
|
||||||
|
# docker run -it --name jhkim_pillar_detection --shm-size=60G -w /app -v /mnt/DataSet:/DataSet pixtree/pillar_detection:latest bash
|
||||||
|
# python pillar_detection.py -i /DataSet/Pixtree-NDA/SME/20220114_01주차/input/SMTOWN/ -c 0
|
||||||
|
|
||||||
|
FROM python:3.8.12-buster
|
||||||
|
|
||||||
|
LABEL name="PillarDetection"
|
||||||
|
LABEL date="2022-01-11"
|
||||||
|
|
||||||
|
RUN mkdir /app/
|
||||||
|
WORKDIR /app/
|
||||||
|
|
||||||
|
COPY pillar_detection.py /app/
|
||||||
|
COPY pillar_detection_core.py /app/
|
||||||
|
COPY pillar_detection_utils.py /app/
|
||||||
|
COPY requirements.txt /app/
|
||||||
|
|
||||||
|
RUN apt-get update -y \
|
||||||
|
&& apt-get upgrade -y \
|
||||||
|
&& apt-get dist-upgrade -y \
|
||||||
|
&& apt-get install -y \
|
||||||
|
ffmpeg
|
||||||
|
|
||||||
|
RUN pip install --upgrade pip \
|
||||||
|
&& pip install -r /app/requirements.txt
|
||||||
+56
-16
@@ -5,16 +5,20 @@ parser = argparse.ArgumentParser()
|
|||||||
# file path options
|
# file path options
|
||||||
parser.add_argument("-i", "--input_dir", default="./input", help="Input source vid directory")
|
parser.add_argument("-i", "--input_dir", default="./input", help="Input source vid directory")
|
||||||
parser.add_argument("-o", "--output_dir", default="./out", help="Output vid directory")
|
parser.add_argument("-o", "--output_dir", default="./out", help="Output vid directory")
|
||||||
|
parser.add_argument("-l", "--logfile_dir", help="Log txt file directory")
|
||||||
|
|
||||||
# ffmpeg encoding option
|
# ffmpeg encoding option
|
||||||
parser.add_argument("-c", "--crf", default=18, type=int, help="set crf level")
|
parser.add_argument("-c", "--crf", default=0, type=int, help="set crf level") # 0: SD, 18: HD
|
||||||
parser.add_argument("-fps", '-fr', "--frame_rate", default=-1, type=float, help="if minus value, same fps as input")
|
parser.add_argument("-ivtc", "--inverse_telecine", default='fm', help="add ffmpeg telecine option [fm, bw, fmbw, False]")
|
||||||
|
|
||||||
parser.add_argument("-uhd", "--uhd_output", default=False, action="store_true", help="set output resolution to 3840:2160")
|
parser.add_argument("-uhd", "--uhd_output", default=False, action="store_true", help="set output resolution to 3840:2160")
|
||||||
parser.add_argument("-lb", "--add_letterbox", default=False, action="store_true", help="add letterbox to make 16:9 ratio")
|
parser.add_argument("-fps", '-fr', "--frame_rate", default=-1, type=float, help="if minus value, same fps as input")
|
||||||
parser.add_argument("-sp", "--add_sharpening", default=False, action="store_true", help="add ffmpeg sharpening filter")
|
parser.add_argument("-lb", "--letterbox", default=False, action="store_true", help="add letterbox to make 16:9 ratio")
|
||||||
|
parser.add_argument("-sp", "--sharpening", default=False, action="store_true", help="add ffmpeg sharpening filter")
|
||||||
|
|
||||||
|
|
||||||
# program option
|
# program option
|
||||||
parser.add_argument("-mul", "--multi_encoding", default=2, type=int, help="when log file exist, encoding mutiple videos by this args")
|
parser.add_argument("-mul", "--multi_encoding", default=1, type=int, help="when log file exist, encoding mutiple videos by this args")
|
||||||
parser.add_argument("-d", "--debug", default=False, action="store_true", help="for debugging. (short length video output)")
|
parser.add_argument("-d", "--debug", default=False, action="store_true", help="for debugging. (short length video output)")
|
||||||
|
|
||||||
# logfile option
|
# logfile option
|
||||||
@@ -28,12 +32,18 @@ args = parser.parse_args()
|
|||||||
# options when only edit log file that already exists (no encoding) : -log -edit
|
# options when only edit log file that already exists (no encoding) : -log -edit
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
vid_types = ('*.avi', '*.mov', '*.mp4', '*.mxf')
|
vid_types = ('*.avi', '*.mov', '*.mp4', '*.mxf', '*.mkv')
|
||||||
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
|
output_dir = args.output_dir
|
||||||
logs_dir = input_dir
|
|
||||||
|
'''
|
||||||
|
TODO :
|
||||||
|
ivtc folder select
|
||||||
|
mkdir 위치 main / core 한 쪽으로 정렬
|
||||||
|
'''
|
||||||
|
temp_ivtc_dir = './tmp_fm_output'
|
||||||
|
|
||||||
if args.cropsize_scale < 1 :
|
if args.cropsize_scale < 1 :
|
||||||
print(f"[!!! ERROR !!!]\t Invalid scale option [scale : {args.cropsize_scale}]")
|
print(f"[!!! ERROR !!!]\t Invalid scale option [scale : {args.cropsize_scale}]")
|
||||||
@@ -46,17 +56,25 @@ def main():
|
|||||||
for types in vid_types :
|
for types in vid_types :
|
||||||
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)
|
||||||
|
|
||||||
|
'''
|
||||||
|
hard coding for specific file process (use "/" not "\")
|
||||||
|
'''
|
||||||
|
# input_dir = "Y:/Pixtree-NDA/SME/20220121_02주차/Input/중화질"
|
||||||
|
# input_list = [
|
||||||
|
# os.path.join(input_dir, "문희준 - Our Story (우리이야기).avi"),
|
||||||
|
# os.path.join(input_dir, "보아 - 늘... MV_고화질.avi"),
|
||||||
|
# ]
|
||||||
|
|
||||||
|
if args.logfile_dir is not None :
|
||||||
|
logs_dir = args.logfile_dir
|
||||||
|
else :
|
||||||
|
logs_dir = input_dir
|
||||||
|
|
||||||
print("[INFO]\t Input dir :", input_dir)
|
print("[INFO]\t Input dir :", input_dir)
|
||||||
print("[INFO]\t Ouput dir :", output_dir)
|
print("[INFO]\t Ouput dir :", output_dir)
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
# for specific file process (use "/" not "\")
|
|
||||||
# input_dir = "Y:/Pixtree-NDA/SME/20211209_3차우선순위/output-20211222/source/"
|
|
||||||
# input_list = [
|
|
||||||
# os.path.join(input_dir, "01. 샤이니_누난너무예뻐 MV_xfm_dec_ver3_edit.mov")
|
|
||||||
# ]
|
|
||||||
|
|
||||||
crop_cfg = VideoCropCfg()
|
|
||||||
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]
|
||||||
vid_num = len(input_list)
|
vid_num = len(input_list)
|
||||||
@@ -66,8 +84,9 @@ def main():
|
|||||||
print("[INFO]\t Log dir :", logs_dir)
|
print("[INFO]\t Log dir :", logs_dir)
|
||||||
|
|
||||||
# init crop configuration class
|
# init crop configuration class
|
||||||
# crop_cfg = VideoCropCfg()
|
crop_cfg = VideoCropCfg()
|
||||||
crop_cfg.vid_name = vid_name
|
crop_cfg.vid_name = vid_name
|
||||||
|
crop_cfg.temp_ivtc_dir = temp_ivtc_dir
|
||||||
|
|
||||||
# Read log file if exist
|
# Read log file if exist
|
||||||
if not manual_mode:
|
if not manual_mode:
|
||||||
@@ -87,10 +106,16 @@ def main():
|
|||||||
cropPos = [crop_cfg.frame_width, crop_cfg.frame_height, 0, 0]
|
cropPos = [crop_cfg.frame_width, crop_cfg.frame_height, 0, 0]
|
||||||
|
|
||||||
cropPos = adjustCropArea(cropPos, crop_cfg.frame_width, crop_cfg.frame_height)
|
cropPos = adjustCropArea(cropPos, crop_cfg.frame_width, crop_cfg.frame_height)
|
||||||
|
print(cropPos)
|
||||||
|
|
||||||
cv2.namedWindow(f'{vid_name}', cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO)
|
cv2.namedWindow(f'{vid_name}', cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO)
|
||||||
# Display crop size control UI
|
# Display crop size control UI
|
||||||
while True:
|
while True:
|
||||||
|
# retCode value mean
|
||||||
|
# 0 : keep playing
|
||||||
|
# 1 : done with cropping (to next vid)
|
||||||
|
# 2 : replay
|
||||||
|
# 3 : program exit
|
||||||
retCode, cropPos = videoCropping(crop_cfg, cropPos)
|
retCode, cropPos = videoCropping(crop_cfg, cropPos)
|
||||||
if retCode == 1:
|
if retCode == 1:
|
||||||
break
|
break
|
||||||
@@ -108,12 +133,27 @@ def main():
|
|||||||
if not crop_cfg.isSkipped:
|
if not crop_cfg.isSkipped:
|
||||||
writeLog(logs_dir, log_path, cropPos)
|
writeLog(logs_dir, log_path, cropPos)
|
||||||
|
|
||||||
|
if args.inverse_telecine != False :
|
||||||
|
if not os.path.exists(temp_ivtc_dir):
|
||||||
|
os.mkdir(temp_ivtc_dir)
|
||||||
|
|
||||||
# Set ffmpeg commands, actual ffmpeg encoding
|
# Set ffmpeg commands, actual ffmpeg encoding
|
||||||
if not (args.only_logfile or crop_cfg.isSkipped):
|
if not (args.only_logfile or crop_cfg.isSkipped):
|
||||||
retCode = ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, crop_cfg.ffmpeg_process)
|
retCode = ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, crop_cfg)
|
||||||
if retCode < 0 :
|
if retCode < 0 :
|
||||||
return retCode
|
return retCode
|
||||||
|
|
||||||
|
if args.inverse_telecine != False :
|
||||||
|
if os.path.exists(temp_ivtc_dir):
|
||||||
|
ivtc_file_list = os.listdir(temp_ivtc_dir)
|
||||||
|
for idx, files in enumerate(ivtc_file_list):
|
||||||
|
file_path = os.path.join(temp_ivtc_dir, files)
|
||||||
|
if not os.path.isdir(file_path):
|
||||||
|
print(f"[INFO]\t Delete temporary ivtc file : {file_path}")
|
||||||
|
os.remove(file_path)
|
||||||
|
print(f"[INFO]\t Delete temporary ivtc folder : {temp_ivtc_dir}")
|
||||||
|
os.rmdir(temp_ivtc_dir)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
print(f"\r\n Program End. end time : {getTime('string')}")
|
print(f"\r\n Program End. end time : {getTime('string')}")
|
||||||
+111
-45
@@ -20,6 +20,8 @@ class VideoCropCfg():
|
|||||||
self.frame_height = 0
|
self.frame_height = 0
|
||||||
self.fps = 0
|
self.fps = 0
|
||||||
|
|
||||||
|
self.temp_ivtc_dir = ''
|
||||||
|
|
||||||
def getVidInfo(self, fpath):
|
def getVidInfo(self, fpath):
|
||||||
self.captured_vid = cv2.VideoCapture(fpath)
|
self.captured_vid = cv2.VideoCapture(fpath)
|
||||||
self.frame_width = int(self.captured_vid.get(cv2.CAP_PROP_FRAME_WIDTH))
|
self.frame_width = int(self.captured_vid.get(cv2.CAP_PROP_FRAME_WIDTH))
|
||||||
@@ -42,7 +44,7 @@ def videoCropping(crop_cfg, cropPos):
|
|||||||
# search_distance unit : second
|
# search_distance unit : second
|
||||||
search_distance = 5
|
search_distance = 5
|
||||||
# play_speed unit : millisecond
|
# play_speed unit : millisecond
|
||||||
play_speed = 10
|
play_speed = 18
|
||||||
key = cv2.waitKeyEx(play_speed)
|
key = cv2.waitKeyEx(play_speed)
|
||||||
|
|
||||||
# Close button(X button) event
|
# Close button(X button) event
|
||||||
@@ -134,14 +136,14 @@ def videoCropping(crop_cfg, cropPos):
|
|||||||
# deep copy current frame, use that frame for draw rectangle.
|
# deep copy current frame, use that frame for draw rectangle.
|
||||||
crop_cfg.boxedFrame = copy.deepcopy(crop_cfg.cleanFrame)
|
crop_cfg.boxedFrame = copy.deepcopy(crop_cfg.cleanFrame)
|
||||||
cv2.rectangle(crop_cfg.boxedFrame, (cropPos[2], cropPos[3]), (cropPos[2] + cropPos[0],
|
cv2.rectangle(crop_cfg.boxedFrame, (cropPos[2], cropPos[3]), (cropPos[2] + cropPos[0],
|
||||||
cropPos[3] + cropPos[1]), (0, 0, 255), thickness=2, lineType=cv2.LINE_8)
|
cropPos[3] + cropPos[1]), (0, 0, 255), thickness=1, lineType=cv2.LINE_8)
|
||||||
cv2.imshow(f'{crop_cfg.vid_name}', crop_cfg.boxedFrame)
|
cv2.imshow(f'{crop_cfg.vid_name}', crop_cfg.boxedFrame)
|
||||||
else :
|
else :
|
||||||
_, crop_cfg.frame = crop_cfg.captured_vid.read()
|
_, crop_cfg.frame = crop_cfg.captured_vid.read()
|
||||||
# deep copy current frame for clean preview.
|
# deep copy current frame for clean preview.
|
||||||
crop_cfg.cleanFrame = copy.deepcopy(crop_cfg.frame)
|
crop_cfg.cleanFrame = copy.deepcopy(crop_cfg.frame)
|
||||||
cv2.rectangle(crop_cfg.frame, (cropPos[2], cropPos[3]), (cropPos[2] + cropPos[0],
|
cv2.rectangle(crop_cfg.frame, (cropPos[2], cropPos[3]), (cropPos[2] + cropPos[0],
|
||||||
cropPos[3] + cropPos[1]), (0, 0, 255), thickness=2, lineType=cv2.LINE_8)
|
cropPos[3] + cropPos[1]), (0, 0, 255), thickness=1, lineType=cv2.LINE_8)
|
||||||
cv2.imshow(f'{crop_cfg.vid_name}', crop_cfg.frame)
|
cv2.imshow(f'{crop_cfg.vid_name}', crop_cfg.frame)
|
||||||
crop_cfg.boxedFrame = copy.deepcopy(crop_cfg.frame)
|
crop_cfg.boxedFrame = copy.deepcopy(crop_cfg.frame)
|
||||||
|
|
||||||
@@ -151,18 +153,21 @@ def videoCropping(crop_cfg, cropPos):
|
|||||||
|
|
||||||
return retCode, cropPos
|
return retCode, cropPos
|
||||||
|
|
||||||
def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_process):
|
def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, crop_cfg):
|
||||||
retCode = -1
|
retCode = -1
|
||||||
|
|
||||||
|
output_dir = args.output_dir
|
||||||
|
temp_ivtc_dir = crop_cfg.temp_ivtc_dir
|
||||||
|
|
||||||
uhd_output = args.uhd_output
|
uhd_output = args.uhd_output
|
||||||
debug = args.debug
|
debug = args.debug
|
||||||
add_letterbox = args.add_letterbox
|
letterbox = args.letterbox
|
||||||
output_dir = args.output_dir
|
sharpening = args.sharpening
|
||||||
add_sharpening = args.add_sharpening
|
|
||||||
manual_mode = args.manual_mode
|
manual_mode = args.manual_mode
|
||||||
crf = args.crf
|
|
||||||
fps = args.frame_rate
|
fps = args.frame_rate
|
||||||
|
|
||||||
|
ffmpeg_process = crop_cfg.ffmpeg_process
|
||||||
|
|
||||||
output_name_args = []
|
output_name_args = []
|
||||||
|
|
||||||
debug_shortOutput = ""
|
debug_shortOutput = ""
|
||||||
@@ -188,7 +193,7 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
pad_arg syntax:
|
pad_arg syntax:
|
||||||
pad= {width after padding}:{height after padding}:{x offset of pad}:{y offset of pad}
|
pad= {width after padding}:{height after padding}:{x offset of pad}:{y offset of pad}
|
||||||
"""
|
"""
|
||||||
if add_letterbox :
|
if letterbox :
|
||||||
output_name_args.append("lb")
|
output_name_args.append("lb")
|
||||||
# Always target 16:9 display ratio
|
# Always target 16:9 display ratio
|
||||||
target_ratio = 16 / 9
|
target_ratio = 16 / 9
|
||||||
@@ -200,7 +205,7 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
tmp_height = int(tmp_height)
|
tmp_height = int(tmp_height)
|
||||||
if (tmp_height % 4) != 0:
|
if (tmp_height % 4) != 0:
|
||||||
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:(oh-ih)/2"
|
||||||
scale_arg = f",scale=w={cropPos[0]}:h={tmp_height}"
|
scale_arg = f",scale=w={cropPos[0]}:h={tmp_height}"
|
||||||
output_width, output_height = cropPos[0], tmp_height
|
output_width, output_height = cropPos[0], tmp_height
|
||||||
else:
|
else:
|
||||||
@@ -209,7 +214,7 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
tmp_width = int(tmp_width)
|
tmp_width = int(tmp_width)
|
||||||
if (tmp_width % 4) != 0:
|
if (tmp_width % 4) != 0:
|
||||||
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:(oh-ih)/2"
|
||||||
scale_arg = f",scale=w={tmp_width}:h={cropPos[1]}"
|
scale_arg = f",scale=w={tmp_width}:h={cropPos[1]}"
|
||||||
output_width, output_height = tmp_width, cropPos[1]
|
output_width, output_height = tmp_width, cropPos[1]
|
||||||
|
|
||||||
@@ -218,21 +223,31 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
# print(f'[INFO]\t folder created : {output_dir}')
|
# print(f'[INFO]\t folder created : {output_dir}')
|
||||||
|
|
||||||
## ffmpeg command setting
|
## ffmpeg command setting
|
||||||
if add_sharpening :
|
|
||||||
sharpen_arg = ',unsharp=7:7:1.5:7:7:1.5'
|
|
||||||
output_name_args.append("sharp")
|
|
||||||
else :
|
|
||||||
sharpen_arg = ''
|
|
||||||
|
|
||||||
fps_arg = ""
|
fps_arg = ""
|
||||||
|
sharpen_arg = ""
|
||||||
|
crf = args.crf
|
||||||
|
if crf >= 0 :
|
||||||
|
output_name_args.append(f"crf{crf}")
|
||||||
|
elif crf < 0 :
|
||||||
|
print(f"[!!! ERROR !!!] invalid option. fps = {crf}")
|
||||||
|
crf = 0
|
||||||
if fps > 0 :
|
if fps > 0 :
|
||||||
output_name_args.append(f"fps{fps}")
|
output_name_args.append(f"fps{fps}")
|
||||||
fps_arg = f"-r {fps}"
|
fps_arg = f"-r {fps}"
|
||||||
elif fps == 0 :
|
elif fps == 0 :
|
||||||
print(f"[!!! ERROR !!!] invalid option. fps = {fps}")
|
print(f"[!!! ERROR !!!] invalid option. fps = {fps}")
|
||||||
|
if args.uhd_output :
|
||||||
|
output_name_args.append(f"uhd")
|
||||||
|
if args.letterbox :
|
||||||
|
output_name_args.append(f"lb")
|
||||||
|
if sharpening :
|
||||||
|
sharpen_arg = ',unsharp=7:7:1.5:7:7:1.5'
|
||||||
|
output_name_args.append("sharp")
|
||||||
|
if args.inverse_telecine != False:
|
||||||
|
output_name_args.append(args.inverse_telecine)
|
||||||
|
|
||||||
if len(output_name_args) > 0 :
|
if len(output_name_args) > 0 :
|
||||||
output_file_name= f"{vid_name}_box({','.join(output_name_args)}).mov"
|
output_file_name= f"{vid_name}_box({'_'.join(output_name_args)}).mov"
|
||||||
else:
|
else:
|
||||||
output_file_name= f"{vid_name}_box.mov"
|
output_file_name= f"{vid_name}_box.mov"
|
||||||
output_path = os.path.join(output_dir, output_file_name)
|
output_path = os.path.join(output_dir, output_file_name)
|
||||||
@@ -248,17 +263,36 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
info : defualt
|
info : defualt
|
||||||
'''
|
'''
|
||||||
loglevel = 'quiet'
|
loglevel = 'quiet'
|
||||||
ffmpeg_command = f"ffmpeg {debug_shortOutput} -i \"{fpath}\" {fps_arg} -vf \"{crop_arg}{scale_arg}{pad_arg}{sharpen_arg}\"\
|
if args.inverse_telecine != False :
|
||||||
-y -pix_fmt yuv420p -c:v libx264 -crf {crf} -c:a copy -preset medium -loglevel {loglevel}\
|
temp_ivtc_path = f"\"{temp_ivtc_dir}/{vid_name}_crf0_fm.mov\""
|
||||||
{uhd_output_args} \"{output_path}\""
|
|
||||||
|
if args.inverse_telecine == 'fmbw':
|
||||||
|
ffmpeg_ivtc_command = f"ffmpeg -y -i \"{fpath}\" -vf fieldmatch=mode=pc_n:combmatch=full,bwdif=0:-1:1 -c:v libx264 -crf 0 -preset ultrafast \
|
||||||
|
-stats -loglevel {loglevel} {temp_ivtc_path}"
|
||||||
|
elif args.inverse_telecine == 'bw':
|
||||||
|
ffmpeg_ivtc_command = f"ffmpeg -y -i \"{fpath}\" -vf bwdif=0:-1:1 -c:v libx264 -crf 0 -preset ultrafast \
|
||||||
|
-stats -loglevel {loglevel} {temp_ivtc_path}"
|
||||||
|
else:
|
||||||
|
ffmpeg_ivtc_command = f"ffmpeg -y -i \"{fpath}\" -vf fieldmatch=mode=pc_n:combmatch=full -c:v libx264 -crf 0 -preset ultrafast \
|
||||||
|
-stats -loglevel {loglevel} {temp_ivtc_path}"
|
||||||
|
|
||||||
|
ffmpeg_command = f"ffmpeg {debug_shortOutput} -i {temp_ivtc_path} {fps_arg} -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} -stats\
|
||||||
|
{uhd_output_args} \"{output_path}\""
|
||||||
|
else :
|
||||||
|
ffmpeg_command = f"ffmpeg {debug_shortOutput} -i \"{fpath}\" {fps_arg} -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} \
|
||||||
|
{uhd_output_args} \"{output_path}\""
|
||||||
|
|
||||||
vid_duration = getVideDuration(fpath)
|
vid_duration = getVideDuration(fpath)
|
||||||
vid_hour = vid_duration[0]
|
vid_hour = vid_duration[0]
|
||||||
vid_min = vid_duration[1]
|
vid_min = vid_duration[1]
|
||||||
vid_sec = vid_duration[2]
|
vid_sec = vid_duration[2]
|
||||||
|
|
||||||
print(ffmpeg_command)
|
print(ffmpeg_command)
|
||||||
# print("====================================================================")
|
print("====================================================================")
|
||||||
print("[INFO]\t Encoding start \"%s\" ..." % vid_name)
|
print("[INFO]\t Encoding Arguments")
|
||||||
|
print("[INFO]\t Input File : \"%s\"" % os.path.split(fpath)[1])
|
||||||
print("[INFO]\t CRF : %d" % int(crf))
|
print("[INFO]\t CRF : %d" % int(crf))
|
||||||
print("[INFO]\t Video Duration : %02d:%02d:%02d" % (vid_hour, vid_min, vid_sec))
|
print("[INFO]\t Video Duration : %02d:%02d:%02d" % (vid_hour, vid_min, vid_sec))
|
||||||
print("[INFO]\t Pixel format : YUV420p")
|
print("[INFO]\t Pixel format : YUV420p")
|
||||||
@@ -266,54 +300,86 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
print("[INFO]\t Ffmpeg Preset : medium")
|
print("[INFO]\t Ffmpeg Preset : medium")
|
||||||
print(f"[INFO]\t Cropping Info : [W : {cropPos[0]} H : {cropPos[1]} X : {cropPos[2]} Y : {cropPos[3]}]")
|
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)
|
print("[INFO]\t Crop area ratio : %.5f" %current_crop_ratio)
|
||||||
if add_letterbox :
|
if letterbox :
|
||||||
print("[INFO]\t Target ratio : %.5f" %target_ratio)
|
print("[INFO]\t Target ratio : %.5f" %target_ratio)
|
||||||
if uhd_output :
|
if uhd_output :
|
||||||
print("[INFO]\t Output Resolution : 3840x2160")
|
print("[INFO]\t Output Resolution : 3840x2160")
|
||||||
else:
|
else:
|
||||||
print("[INFO]\t Output Resolution : %dx%d" %(output_width, output_height))
|
print("[INFO]\t Output Resolution : %dx%d" %(output_width, output_height))
|
||||||
if add_sharpening :
|
if sharpening :
|
||||||
print("[INFO]\t Sharpening arg : %s" %sharpen_arg[1:])
|
print("[INFO]\t Sharpening arg : %s" %sharpen_arg[1:])
|
||||||
if fps > 0 :
|
if fps > 0 :
|
||||||
print("[INFO]\t Frame Rate : %.2f" %fps)
|
print("[INFO]\t Frame Rate : %.2f" %fps)
|
||||||
|
print("[INFO]\t Field Match apply : %s" %args.inverse_telecine)
|
||||||
print("[INFO]\t Output File Name : %s" %output_file_name)
|
print("[INFO]\t Output File Name : %s" %output_file_name)
|
||||||
print("====================================================================")
|
print("====================================================================")
|
||||||
|
|
||||||
# st_time = time.time()
|
|
||||||
|
|
||||||
vid_index += 1
|
vid_index += 1
|
||||||
start_time = getTime()
|
start_time = getTime()
|
||||||
|
|
||||||
'''
|
|
||||||
TODO : count running ffmpeg process asynch.
|
|
||||||
'''
|
|
||||||
running_process = 0
|
|
||||||
if manual_mode:
|
if manual_mode:
|
||||||
# Manual Mode (always cropping one by one)
|
# Manual Mode (always cropping 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}\
|
print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
||||||
Start Time : {getTime('string')}")
|
Start Time : {getTime('string')}")
|
||||||
ffmpeg_process.append(subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait())
|
ffmpeg_process.append(subprocess.Popen(ffmpeg_command, shell=False).wait())
|
||||||
else :
|
else :
|
||||||
ffmpeg_process.append(subprocess.Popen(ffmpeg_command, shell=False))
|
ffmpeg_process.append(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:
|
||||||
subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
if args.inverse_telecine != False:
|
||||||
|
subprocess.Popen(ffmpeg_ivtc_command, shell=False).wait()
|
||||||
|
subprocess.Popen(ffmpeg_command, shell=False).wait()
|
||||||
|
|
||||||
|
else :
|
||||||
|
subprocess.Popen(ffmpeg_command, shell=False).wait()
|
||||||
|
|
||||||
elif (vid_index % args.multi_encoding == 0) or (vid_index == vid_num):
|
elif (vid_index % args.multi_encoding == 0) or (vid_index == vid_num):
|
||||||
print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
||||||
Start Time : {getTime('string')}")
|
Start Time : {getTime('string')}")
|
||||||
p = subprocess.Popen(ffmpeg_command + ' -stats', shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
|
||||||
ffmpeg_process.append(p.pid)
|
if args.inverse_telecine != False:
|
||||||
# print(ffmpeg_process)
|
p = subprocess.Popen(ffmpeg_ivtc_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
||||||
while p.poll() is None:
|
print(f"[INFO]\t Step 1. Field match...\t(File Path : {temp_ivtc_path})", end="\n")
|
||||||
displayRemainTime(vid_duration, p.stderr, start_time)
|
while p.poll() is None:
|
||||||
|
displayRemainTime(vid_duration, p.stderr, start_time)
|
||||||
|
print("",end="\n")
|
||||||
|
|
||||||
|
p = subprocess.Popen(ffmpeg_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
||||||
|
print(f"[INFO]\t Step 2. Cropping...", end="\n")
|
||||||
|
while p.poll() is None:
|
||||||
|
displayRemainTime(vid_duration, p.stderr, start_time)
|
||||||
|
print("\n")
|
||||||
|
else :
|
||||||
|
# p = subprocess.Popen(ffmpeg_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
||||||
|
# ffmpeg_process.append(p.pid)
|
||||||
|
# while p.poll() is None:
|
||||||
|
# displayRemainTime(vid_duration, p.stderr, start_time)
|
||||||
|
# print("\n")
|
||||||
|
|
||||||
|
subprocess.Popen(ffmpeg_command, shell=False).wait()
|
||||||
|
|
||||||
else :
|
else :
|
||||||
p = subprocess.Popen(ffmpeg_command, shell=False)
|
if args.inverse_telecine != False:
|
||||||
ffmpeg_process.append(p.pid)
|
print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
||||||
running_process += 1
|
Start Time : {getTime('string')}")
|
||||||
|
p = subprocess.Popen(ffmpeg_ivtc_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
||||||
|
print(f"[INFO]\t Step 1. Field match...\t(File Path : {temp_ivtc_path})", end="\n")
|
||||||
|
while p.poll() is None:
|
||||||
|
displayRemainTime(vid_duration, p.stderr, start_time)
|
||||||
|
print("",end="\n")
|
||||||
|
|
||||||
|
p = subprocess.Popen(ffmpeg_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
||||||
|
print(f"[INFO]\t Step 2. Cropping...", end="\n")
|
||||||
|
while p.poll() is None:
|
||||||
|
displayRemainTime(vid_duration, p.stderr, start_time)
|
||||||
|
print("\n")
|
||||||
|
else :
|
||||||
|
# p = subprocess.Popen(ffmpeg_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
||||||
|
subprocess.Popen(ffmpeg_command, shell=False)
|
||||||
|
|
||||||
|
# ffmpeg_process.append(p.pid)
|
||||||
|
|
||||||
retCode = 0
|
retCode = 0
|
||||||
|
|
||||||
@@ -325,18 +391,18 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
# 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}\
|
# print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
||||||
# Start Time : {getTime('string')}")
|
# Start Time : {getTime('string')}")
|
||||||
# ffmpeg_process.append(subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait())
|
# ffmpeg_process.append(subprocess.Popen(ffmpeg_command, shell=False).wait())
|
||||||
# else :
|
# else :
|
||||||
# ffmpeg_process.append(subprocess.Popen(ffmpeg_command, shell=False))
|
# ffmpeg_process.append(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:
|
||||||
# subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait()
|
# subprocess.Popen(ffmpeg_command, shell=False).wait()
|
||||||
|
|
||||||
# elif (vid_index % args.multi_encoding == 0) or (vid_index == vid_num):
|
# elif (vid_index % args.multi_encoding == 0) or (vid_index == vid_num):
|
||||||
# print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
# print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
||||||
# Start Time : {getTime('string')}")
|
# Start Time : {getTime('string')}")
|
||||||
# p = subprocess.Popen(ffmpeg_command + ' -stats', shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
# p = subprocess.Popen(ffmpeg_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
||||||
# ffmpeg_process.append(p.pid)
|
# ffmpeg_process.append(p.pid)
|
||||||
# while p.poll() is None:
|
# while p.poll() is None:
|
||||||
# displayRemainTime(vid_duration, p.stderr, start_time)
|
# displayRemainTime(vid_duration, p.stderr, start_time)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ def displayRemainTime(vid_duration, ffmpeg_stream, start_time):
|
|||||||
eta = (100 - current_percentage) / encoding_speed
|
eta = (100 - current_percentage) / encoding_speed
|
||||||
eta_time = datetime.datetime.now() + datetime.timedelta(seconds=eta)
|
eta_time = datetime.datetime.now() + datetime.timedelta(seconds=eta)
|
||||||
eta_time = eta_time.strftime('[ETA : %Y-%m-%d %H:%M:%S]')
|
eta_time = eta_time.strftime('[ETA : %Y-%m-%d %H:%M:%S]')
|
||||||
print(f"[INFO]\t now encoding ... {eta_time} [{current_percentage:.2f}%] [Speed : {encoding_speed:.2f} %/s]", end='\r')
|
print(f"[INFO]\t now processing ... {eta_time} [{current_percentage:.2f}%] [Speed : {encoding_speed:.2f} %/s]", end='\r')
|
||||||
|
|
||||||
|
|
||||||
def resizeCropInfo(key, cropPos, frame_width, frame_height):
|
def resizeCropInfo(key, cropPos, frame_width, frame_height):
|
||||||
@@ -151,10 +151,24 @@ def parseLog(log_path, edit_mode, manual_mode, scale):
|
|||||||
cropPos = []
|
cropPos = []
|
||||||
|
|
||||||
if not os.path.exists(log_path):
|
if not os.path.exists(log_path):
|
||||||
print(f"[INFO]\t Can`t find log file. [{log_path}]")
|
if log_path.find('_avs') > 0 :
|
||||||
manual_mode = True
|
avs_log_path = log_path.split(sep='_avs')
|
||||||
edit_mode = False
|
avs_log_path = avs_log_path[0] + avs_log_path[1]
|
||||||
else :
|
if os.path.exists(avs_log_path):
|
||||||
|
print(f"[INFO]\t Using log file for avs input. \
|
||||||
|
[{os.path.basename(log_path)} => {os.path.basename(avs_log_path)}]")
|
||||||
|
log_path = avs_log_path
|
||||||
|
else :
|
||||||
|
print(f"[INFO]\t Can`t find log file for avs input. [{avs_log_path}]")
|
||||||
|
manual_mode = True
|
||||||
|
edit_mode = False
|
||||||
|
else :
|
||||||
|
print(f"[INFO]\t Can`t find log file. [{log_path}]")
|
||||||
|
manual_mode = True
|
||||||
|
edit_mode = False
|
||||||
|
|
||||||
|
|
||||||
|
if not manual_mode :
|
||||||
print(f"[INFO]\t Loading log file... [{log_path}]")
|
print(f"[INFO]\t Loading log file... [{log_path}]")
|
||||||
try :
|
try :
|
||||||
f = open(log_path, "r")
|
f = open(log_path, "r")
|
||||||
|
|||||||
Reference in new issue
Block a user