Skip to content

Commit eb36e32

Browse files
committed
added lossless encoding option to zoom_composite
1 parent eba0559 commit eb36e32

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

inputs/scripts/zoom_composite.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import cv2
23
import glob
34
import numpy as np
@@ -20,21 +21,22 @@
2021
expand_left = 30
2122
expand_right = 30
2223

23-
start_in_black_void = False # enabled to start zooming out from a black void instead of starting on the first frame
24-
num_interpolated_frames = 20 # number of interpolated frames per keyframe, controls zoom speed (and the expand ratio)
25-
frame_rate = 30 # fps of the output video
26-
output_file = "zoom.mp4" # name of output file (this will be saved in the folder with the key frames)
27-
preview_output = False # if enabled this will show a preview of the video in a window as it renders
28-
zoom_out = False # if enabled this will zoom out instead of zooming in
29-
acceleration_smoothing = False # if enabled this slows the start and stop
30-
video_size = (1920*2, 1080*2) # 4k by default
24+
start_in_black_void = False # enabled to start zooming out from a black void instead of starting on the first frame
25+
num_interpolated_frames = 25 # number of interpolated frames per keyframe, controls zoom speed (and the expand ratio)
26+
frame_rate = 30 # fps of the output video
27+
output_file = "zoom.mp4" # name of output file (this will be saved in the folder with the key frames)
28+
preview_output = False # if enabled this will show a preview of the video in a window as it renders
29+
zoom_out = False # if enabled this will zoom out instead of zooming in
30+
acceleration_smoothing = 0. #1.8 # if > 0. this slows the start and stop, good values are 1 to 3
31+
video_size = (1920*2, 1080*2) # video output resolution
32+
encode_lossless = False # set to True to make an uncompressed video file (this will take a lot of disk space)
3133

3234
# *****************************************************************
3335

3436
# find keyframes and sort them
3537
print("Loading keyframes from {0}...".format(DEFAULT_PATHS.outputs+"/"+frames_path))
3638
frame_filenames = sorted(glob.glob(DEFAULT_PATHS.outputs+"/"+frames_path+"/*.png"), reverse=True)
37-
#frame_filenames = frame_filenames[0:20] # limit to 20 frames for testing
39+
#frame_filenames = frame_filenames[0:3] # limit to 20 frames for testing
3840
num_keyframes = len(frame_filenames)
3941

4042
frame0_cv2_image = cv2.imread(frame_filenames[0])
@@ -68,9 +70,16 @@
6870
glGenerateMipmap(GL_TEXTURE_2D)
6971

7072
# create video encoder
71-
video_output_path = DEFAULT_PATHS.outputs+"/"+gdl.get_noclobber_checked_path(DEFAULT_PATHS.outputs, frames_path+"/"+output_file)
73+
if encode_lossless == False:
74+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
75+
else:
76+
fourcc = cv2.VideoWriter_fourcc(*'HFYU')
77+
output_file = os.path.splitext(output_file)[0]+".avi"
78+
7279
print("Creating video of size {0}x{1}...".format(video_size[0], video_size[1]))
73-
result = cv2.VideoWriter(video_output_path, cv2.VideoWriter_fourcc(*'mp4v'), frame_rate, video_size)
80+
video_output_path = DEFAULT_PATHS.outputs+"/"+gdl.get_noclobber_checked_path(DEFAULT_PATHS.outputs, frames_path+"/"+output_file)
81+
82+
result = cv2.VideoWriter(video_output_path, fourcc, frame_rate, video_size)
7483
frame_pixels = (GLubyte * (3*video_size[0]*video_size[1]))(0)
7584

7685
if preview_output: # show video window if preview is enabled
@@ -79,8 +88,8 @@
7988
else: start_offset = 4 # otherwise start very slightly pulled back from the first keyframe
8089

8190
# create a schedule of time values for each rendered video frame
82-
if acceleration_smoothing == True:
83-
t_schedule = np.tanh(np.linspace(-1.25, 1.25, num_interpolated_frames * num_keyframes))
91+
if acceleration_smoothing > 0.:
92+
t_schedule = np.tanh(np.linspace(-acceleration_smoothing, acceleration_smoothing, num_interpolated_frames * num_keyframes))
8493
t_schedule = t_schedule - np.min(t_schedule)
8594
t_schedule = t_schedule / np.max(t_schedule) * (num_keyframes-2.5) + start_offset
8695
else:

0 commit comments

Comments
 (0)