2024-05-24 09:44:19 +02:00
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from vse_toolbox.constants import AUTO_SPLITTER_LOG
|
|
|
|
from vse_toolbox import file_utils
|
|
|
|
|
|
|
|
|
|
|
|
class AutoSplitter(object):
|
|
|
|
|
2024-05-24 11:12:13 +02:00
|
|
|
def __init__(self, path, fps=None):
|
2024-05-24 09:44:19 +02:00
|
|
|
|
2024-05-24 11:12:13 +02:00
|
|
|
self.path = path
|
2024-05-24 09:44:19 +02:00
|
|
|
self.fps = fps
|
|
|
|
|
|
|
|
self.log_path = AUTO_SPLITTER_LOG
|
|
|
|
|
|
|
|
def launch_analysis(self, threshold=0.6):
|
|
|
|
|
2024-05-24 11:12:13 +02:00
|
|
|
ffmpeg_cmd = f"ffmpeg -i {str(self.path)} -filter:v \"select='gt(scene,{threshold})',showinfo\" -f null - 2> {str(self.log_path)}"
|
2024-05-24 09:44:19 +02:00
|
|
|
print(ffmpeg_cmd)
|
|
|
|
|
|
|
|
subprocess.call(ffmpeg_cmd, shell=True)
|
|
|
|
|
|
|
|
def get_split_times(self, as_frame=True):
|
|
|
|
log = file_utils.read_file(self.log_path)
|
|
|
|
|
|
|
|
timecodes = re.findall(r'pts_time:([\d.]+)', log)
|
|
|
|
|
|
|
|
if as_frame:
|
|
|
|
# convert timecode to frame number
|
|
|
|
if not self.fps:
|
|
|
|
self.fps = float(re.findall(r'([\d]+) fps', log)[0])
|
|
|
|
|
|
|
|
return [round(float(time) * self.fps) for time in timecodes]
|
|
|
|
|
|
|
|
return timecodes
|