Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Add proper extension to filename template if required.
dot_pos = self.split_name_format.rfind('.')
if self.split_mkvmerge and not self.split_name_format.endswith('.mkv'):
self.split_name_format += '.mkv'
# Don't add if we find an extension between 2 and 4 characters
elif not (dot_pos >= 0) or (
dot_pos >= 0 and not
((len(self.split_name_format) - (dot_pos+1) <= 4 >= 2))):
self.split_name_format += '.mp4'
output_file_prefix = get_and_create_path(
self.split_name_format,
self.split_directory if self.split_directory is not None
else self.output_directory)
mkvmerge_available = is_mkvmerge_available()
ffmpeg_available = is_ffmpeg_available()
if mkvmerge_available and (self.split_mkvmerge or not ffmpeg_available):
if not self.split_mkvmerge:
logging.warning(
'ffmpeg not found, falling back to fast copy mode (split-video -c/--copy).')
split_video_mkvmerge(video_paths, scene_list, output_file_prefix, video_name,
suppress_output=self.quiet_mode or self.split_quiet)
elif ffmpeg_available:
if self.split_mkvmerge:
logging.warning('mkvmerge not found, falling back to normal splitting'
' mode (split-video).')
split_video_ffmpeg(video_paths, scene_list, output_file_prefix,
video_name, arg_override=self.split_args,
hide_progress=self.quiet_mode,
suppress_output=self.quiet_mode or self.split_quiet)
else:
if not (mkvmerge_available or ffmpeg_available):
scene_list = []
folder = os.path.splitext(video_path)[0]
if os.path.exists(folder):
print('--- STOP : The folder for this video already exists, it is probably already split.')
else:
try:
# If stats file exists, load it.
if os.path.exists(stats_file_path):
# Read stats from CSV file opened in read mode:
with open(stats_file_path, 'r') as stats_file:
stats_manager.load_from_csv(stats_file, base_timecode)
if video_splitter.is_ffmpeg_available():
# Set downscale factor to improve processing speed.
video_manager.set_downscale_factor()
# Start video_manager.
video_manager.start()
# Perform scene detection on video_manager.
scene_manager.detect_scenes(frame_source=video_manager)
# Obtain list of detected scenes.
scene_list = scene_manager.get_scene_list(base_timecode)
# Each scene is a tuple of (start, end) FrameTimecodes.
print('%s scenes obtained' % len(scene_list))
if len(scene_list)>0:
if rate_factor is None:
rate_factor = 22 if not high_quality else 17
if preset is None:
preset = 'veryfast' if not high_quality else 'slow'
override_args = ('-c:v libx264 -preset {PRESET} -crf {RATE_FACTOR} -c:a copy'.format(
PRESET=preset, RATE_FACTOR=rate_factor))
if not copy:
logging.info('FFmpeg codec args set: %s', override_args)
if filename:
logging.info('Video output file name format: %s', filename)
if ctx.obj.split_directory is not None:
logging.info('Video output path set: \n%s', ctx.obj.split_directory)
ctx.obj.split_args = override_args
mkvmerge_available = is_mkvmerge_available()
ffmpeg_available = is_ffmpeg_available()
if not (mkvmerge_available or ffmpeg_available) or (
(not mkvmerge_available and copy) or (not ffmpeg_available and not copy)):
split_tool = 'ffmpeg/mkvmerge'
if (not mkvmerge_available and copy):
split_tool = 'mkvmerge'
elif (not ffmpeg_available and not copy):
split_tool = 'ffmpeg'
error_strs = [
"{EXTERN_TOOL} is required for split-video{EXTRA_ARGS}.".format(
EXTERN_TOOL=split_tool, EXTRA_ARGS=' -c/--copy' if copy else ''),
"Install the above tool%s to enable video splitting support." % (
's' if split_tool.find('/') > 0 else '')]
if mkvmerge_available:
error_strs += [
'You can also specify `split-video -c/--copy` to use mkvmerge for splitting.']
error_str = '\n'.join(error_strs)
# Add proper extension to filename template if required.
dot_pos = self.split_name_format.rfind('.')
if self.split_mkvmerge and not self.split_name_format.endswith('.mkv'):
self.split_name_format += '.mkv'
# Don't add if we find an extension between 2 and 4 characters
elif not (dot_pos >= 0) or (
dot_pos >= 0 and not
((len(self.split_name_format) - (dot_pos+1) <= 4 >= 2))):
self.split_name_format += '.mp4'
output_file_prefix = get_and_create_path(
self.split_name_format,
self.split_directory if self.split_directory is not None
else self.output_directory)
mkvmerge_available = is_mkvmerge_available()
ffmpeg_available = is_ffmpeg_available()
if mkvmerge_available and (self.split_mkvmerge or not ffmpeg_available):
if not self.split_mkvmerge:
logging.warning(
'ffmpeg not found, falling back to fast copy mode (split-video -c/--copy).')
split_video_mkvmerge(video_paths, scene_list, output_file_prefix, video_name,
suppress_output=self.quiet_mode or self.split_quiet)
elif ffmpeg_available:
if self.split_mkvmerge:
logging.warning('mkvmerge not found, falling back to normal splitting'
' mode (split-video).')
split_video_ffmpeg(video_paths, scene_list, output_file_prefix,
video_name, arg_override=self.split_args,
hide_progress=self.quiet_mode,
suppress_output=self.quiet_mode or self.split_quiet)
else:
if not (mkvmerge_available or ffmpeg_available):