|
| 1 | +import os |
1 | 2 | import cv2
|
2 | 3 | import glob
|
3 | 4 | import numpy as np
|
|
20 | 21 | expand_left = 30
|
21 | 22 | expand_right = 30
|
22 | 23 |
|
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) |
31 | 33 |
|
32 | 34 | # *****************************************************************
|
33 | 35 |
|
34 | 36 | # find keyframes and sort them
|
35 | 37 | print("Loading keyframes from {0}...".format(DEFAULT_PATHS.outputs+"/"+frames_path))
|
36 | 38 | 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 |
38 | 40 | num_keyframes = len(frame_filenames)
|
39 | 41 |
|
40 | 42 | frame0_cv2_image = cv2.imread(frame_filenames[0])
|
|
68 | 70 | glGenerateMipmap(GL_TEXTURE_2D)
|
69 | 71 |
|
70 | 72 | # 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 | + |
72 | 79 | 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) |
74 | 83 | frame_pixels = (GLubyte * (3*video_size[0]*video_size[1]))(0)
|
75 | 84 |
|
76 | 85 | if preview_output: # show video window if preview is enabled
|
|
79 | 88 | else: start_offset = 4 # otherwise start very slightly pulled back from the first keyframe
|
80 | 89 |
|
81 | 90 | # 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)) |
84 | 93 | t_schedule = t_schedule - np.min(t_schedule)
|
85 | 94 | t_schedule = t_schedule / np.max(t_schedule) * (num_keyframes-2.5) + start_offset
|
86 | 95 | else:
|
|
0 commit comments