Created
September 12, 2019 14:54
-
-
Save Winding6636/3e4ed91b9d36c3f3c2e8829b62761c42 to your computer and use it in GitHub Desktop.
autoconcatgenescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import os | |
import subprocess | |
VERSION = '1.0' | |
def process_arguments(): | |
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
# video options | |
file_options = parser.add_argument_group('File Options') | |
file_options.add_argument('-i', '--input', help='source video file/directory', action='append', required=True) | |
file_options.add_argument('-o', '--output', help='output video file', action='store', required=True) | |
file_options.add_argument('-f', '--ffmpeg_binary', help='FFmpeg binary file', action='store', default='ffmpeg') | |
# parse arguments | |
return parser.parse_args() | |
# process arguments | |
args = process_arguments() | |
# verify input files | |
if not os.path.isdir(args.input[0]): | |
for path in args.input: | |
assert os.path.isfile(path), f'ファイルがありません: {path}' | |
else: | |
# sorted([os.path.join(args.input[0], f) for f in os.listdir(args.input[0]) if os.path.isfile(os.path.join(args.input[0], f))]) | |
videos = [] | |
for f in os.listdir(args.input[0]): | |
if os.path.isfile(os.path.join(args.input[0], f)): | |
videos.append(os.path.join(args.input[0], f)) | |
args.input = sorted(videos) | |
#concat lists gene | |
ccat_files = 'concat:' | |
for input_file in args.input: | |
ccat_files += input_file+'|' | |
print("Combine Start...") | |
#変換プロセス | |
execute = [ | |
args.ffmpeg_binary, | |
'-i', | |
f'{ccat_files}', | |
'-c', | |
'copy', | |
args.output, | |
'-y' | |
] | |
subprocess.run(execute, check=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment