add fps option, output name varient
This commit is contained in:
1 parent
1293b9184a
commit
5344c46e51
3 files changed
+86
-35
No files matched your search
@@ -8,9 +8,12 @@ parser.add_argument("-o", "--output_dir", default="./out", help="Output vid dire
|
|||||||
|
|
||||||
# ffmpeg encoding option
|
# ffmpeg encoding option
|
||||||
parser.add_argument("-c", "--crf", default=20, type=int, help="set crf level")
|
parser.add_argument("-c", "--crf", default=20, type=int, help="set crf level")
|
||||||
|
parser.add_argument("-fps", '-fr', "--frame_rate", default=-1, type=float, help="if minus value, same fps as input")
|
||||||
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("-lb", "--add_letterbox", default=False, action="store_true", help="add letterbox to make 16:9 ratio")
|
||||||
parser.add_argument("-sp", "--add_sharpening", default=False, action="store_true", help="add ffmpeg sharpening filter")
|
parser.add_argument("-sp", "--add_sharpening", default=False, action="store_true", help="add ffmpeg sharpening filter")
|
||||||
|
|
||||||
|
# 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=2, 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)")
|
||||||
|
|
||||||
|
|||||||
+81
-35
@@ -161,14 +161,19 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
add_sharpening = args.add_sharpening
|
add_sharpening = args.add_sharpening
|
||||||
manual_mode = args.manual_mode
|
manual_mode = args.manual_mode
|
||||||
crf = args.crf
|
crf = args.crf
|
||||||
|
fps = args.frame_rate
|
||||||
|
|
||||||
|
output_name_args = []
|
||||||
|
|
||||||
uhd_output_args = ""
|
|
||||||
if uhd_output :
|
|
||||||
uhd_output_args = "-s 3840x2160"
|
|
||||||
|
|
||||||
debug_shortOutput = ""
|
debug_shortOutput = ""
|
||||||
if debug :
|
if debug :
|
||||||
debug_shortOutput = "-t 15 -ss 30"
|
debug_shortOutput = "-t 15 -ss 30"
|
||||||
|
output_name_args.append("debug")
|
||||||
|
|
||||||
|
uhd_output_args = ""
|
||||||
|
if uhd_output :
|
||||||
|
uhd_output_args = "-s 3840x2160"
|
||||||
|
output_name_args.append("uhd")
|
||||||
|
|
||||||
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]
|
||||||
@@ -184,6 +189,7 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
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 add_letterbox :
|
||||||
|
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
|
||||||
# when current ratio is more flat
|
# when current ratio is more flat
|
||||||
@@ -211,13 +217,24 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
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")
|
|
||||||
|
|
||||||
## ffmpeg command setting
|
## ffmpeg command setting
|
||||||
if add_sharpening :
|
if add_sharpening :
|
||||||
sharpen_arg = ',unsharp=7:7:1.5:7:7:1.5'
|
sharpen_arg = ',unsharp=7:7:1.5:7:7:1.5'
|
||||||
|
output_name_args.append("sharp")
|
||||||
else :
|
else :
|
||||||
sharpen_arg = ''
|
sharpen_arg = ''
|
||||||
|
|
||||||
|
if fps > 0 :
|
||||||
|
output_name_args.append(f"fps{fps}")
|
||||||
|
elif fps == 0 :
|
||||||
|
print(f"[!!! ERROR !!!] invalid option. fps = {fps}")
|
||||||
|
|
||||||
|
if len(output_name_args) > 0 :
|
||||||
|
output_file_name= f"{vid_name}_box({','.join(output_name_args)}).mov"
|
||||||
|
else:
|
||||||
|
output_file_name= f"{vid_name}_box.mov"
|
||||||
|
output_path = os.path.join(output_dir, output_file_name)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
ffmpeg arguments
|
ffmpeg arguments
|
||||||
-stats : print only encoding progress status (ignore loglevel argument)
|
-stats : print only encoding progress status (ignore loglevel argument)
|
||||||
@@ -229,7 +246,7 @@ 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}\" -vf \"{crop_arg}{scale_arg}{pad_arg}{sharpen_arg}\"\
|
ffmpeg_command = f"ffmpeg {debug_shortOutput} -i \"{fpath}\" -r 29.97 -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}\""
|
||||||
vid_duration = getVideDuration(fpath)
|
vid_duration = getVideDuration(fpath)
|
||||||
@@ -259,8 +276,8 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
|
|
||||||
vid_index += 1
|
vid_index += 1
|
||||||
start_time = getTime()
|
start_time = getTime()
|
||||||
try:
|
|
||||||
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 :
|
||||||
@@ -269,33 +286,62 @@ def ffmpegEncoding(args, vid_index, vid_num, cropPos, vid_name, fpath, ffmpeg_pr
|
|||||||
ffmpeg_process.append(subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait())
|
ffmpeg_process.append(subprocess.Popen(ffmpeg_command + ' -stats', 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 + ' -stats', shell=False).wait()
|
||||||
|
|
||||||
|
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}\
|
||||||
|
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)
|
||||||
|
while p.poll() is None:
|
||||||
|
displayRemainTime(vid_duration, p.stderr, start_time)
|
||||||
|
else :
|
||||||
|
p = subprocess.Popen(ffmpeg_command, shell=False)
|
||||||
|
ffmpeg_process.append(p.pid)
|
||||||
|
|
||||||
|
retCode = 0
|
||||||
|
|
||||||
|
return retCode
|
||||||
|
# try:
|
||||||
|
# if manual_mode:
|
||||||
|
# # Manual Mode (always cropping one by one)
|
||||||
|
# # Hold process when encoding last video
|
||||||
|
# if vid_index == vid_num :
|
||||||
|
# print(f"[INFO]\t Video Duration : {vid_hour:02d}:{vid_min:02d}:{vid_sec:02d}\
|
||||||
|
# Start Time : {getTime('string')}")
|
||||||
|
# ffmpeg_process.append(subprocess.Popen(ffmpeg_command + ' -stats', shell=False).wait())
|
||||||
|
# else :
|
||||||
|
# ffmpeg_process.append(subprocess.Popen(ffmpeg_command, shell=False))
|
||||||
|
# else:
|
||||||
|
# # Log file mode (encoding simultaneously n videos)
|
||||||
|
# if args.multi_encoding == 0:
|
||||||
|
# subprocess.Popen(ffmpeg_command + ' -stats', 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 + ' -stats', 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)
|
||||||
else :
|
# else :
|
||||||
p = subprocess.Popen(ffmpeg_command, shell=False)
|
# p = subprocess.Popen(ffmpeg_command, shell=False)
|
||||||
ffmpeg_process.append(p.pid)
|
# ffmpeg_process.append(p.pid)
|
||||||
|
|
||||||
retCode = 0
|
# retCode = 0
|
||||||
except Exception as e :
|
# except Exception as e :
|
||||||
print('[!!! ERROR !!!]\t', e)
|
# print('[!!! ERROR !!!]\t', e)
|
||||||
# print(ffmpeg_process)
|
# # print(ffmpeg_process)
|
||||||
# for p in ffmpeg_process :
|
# # for p in ffmpeg_process :
|
||||||
# print('terminate')
|
# # print('terminate')
|
||||||
# os.killpg(os.getpgid(p, signal.SIGTERM))
|
# # os.killpg(os.getpgid(p, signal.SIGTERM))
|
||||||
# # p.terminate()
|
# # # p.terminate()
|
||||||
# # p.kill()
|
# # # p.kill()
|
||||||
|
|
||||||
retCode = -1
|
# retCode = -1
|
||||||
finally :
|
# finally :
|
||||||
return retCode
|
# return retCode
|
||||||
|
|
||||||
@@ -45,6 +45,8 @@ def displayRemainTime(vid_duration, ffmpeg_stream, start_time):
|
|||||||
current_progress_sec = timeToSecond(time_stamp)
|
current_progress_sec = timeToSecond(time_stamp)
|
||||||
total_progress_sec = timeToSecond(vid_duration)
|
total_progress_sec = timeToSecond(vid_duration)
|
||||||
current_percentage = (current_progress_sec / total_progress_sec) * 100
|
current_percentage = (current_progress_sec / total_progress_sec) * 100
|
||||||
|
if current_percentage == 0 :
|
||||||
|
current_percentage = 0.01
|
||||||
|
|
||||||
# eta_time
|
# eta_time
|
||||||
passed_time = getTime() - start_time
|
passed_time = getTime() - start_time
|
||||||
|
|||||||
Reference in new issue
Block a user