allow for auto reversing video

This commit is contained in:
leminlimez
2025-03-30 17:23:21 -04:00
parent 60a4541a02
commit 58216d7949
6 changed files with 131 additions and 121 deletions

View File

@@ -42,11 +42,14 @@ def get_thumbnail_from_contents(contents: bytes, output_file: str = None):
contents = get_thumbnail_from_mov(inp_file.name, output_file)
return contents
def create_caml(video_path: str, output_file: str, update_label=lambda x: None):
def create_caml(video_path: str, output_file: str, auto_reverses: bool, update_label=lambda x: None):
cam = cv2.VideoCapture(video_path)
assets_path = os.path.join(output_file, "assets")
frame_count = int(cam.get(cv2.CAP_PROP_FRAME_COUNT))
FRAME_LIMIT = 300
reverse = 0
if auto_reverses:
reverse = 1
if frame_count > FRAME_LIMIT:
raise Exception(f"Videos must be under {FRAME_LIMIT} fps to loop. Either reduce the frame rate or make it shorter.")
try:
@@ -76,7 +79,7 @@ def create_caml(video_path: str, output_file: str, update_label=lambda x: None):
<CALayer allowsEdgeAntialiasing="1" allowsGroupOpacity="1" bounds="0 0 {width} {height}" contentsFormat="RGBA8" cornerCurve="circular" name="CALayer1" position="{int(width/2)} {int(height/2)}">
<contents type="CGImage" src="assets/0.jpg"/>
<animations>
<animation type="CAKeyframeAnimation" calculationMode="linear" keyPath="contents" beginTime="1e-100" duration="{duration}" removedOnCompletion="0" repeatCount="inf" repeatDuration="0" speed="1" timeOffset="0">
<animation type="CAKeyframeAnimation" calculationMode="linear" keyPath="contents" beginTime="1e-100" duration="{duration}" removedOnCompletion="0" repeatCount="inf" repeatDuration="0" speed="1" timeOffset="0" autoreverses="{reverse}">
<values>\n""")
while(True):
# reading from frame