Encode Video takes a specified frame range as input and creates a video file. This article walks you through every code section in the script. At the end of the article, you will find the annotated script code for your reference.
How the script works:
At the top of most scripts we import the external Python libraries first:
import os, re.
Section 1: Create the main function, define attributes, and display these attributes within a user prompt.
-
Frames folder, folder.
-
Frame file format, fnt.
-
Number of the frame to start with, start.
-
Number of the frame to end with, end.
-
Number of frames per seconds of video, fps.
-
Name of the video output, name.
Between line 11 and 16, lux.DIALOG functions define the prompt's attributes. Lines 17 through 20, include the lux.getInputDialog function which generates the actual user prompt. In line 20, an "id" tag recalls the most recent input values.
Section 2: Check for errors and exit peacefully if errors arise. Assign user input to corresponding variables. A line-by-line code breakdown is shown below.
-
If the user clicks "Cancel", exit gracefully.
-
If the frames folder is empty, give an error message.
-
Assign the folder path to the fld variable.
-
Assign the files format to the files variable.
-
If the file format is empty, give an error message.
-
If the file number isn't there give error message.
-
Compile the frame numbers into a pattern object called reDigits.
-
Make a boolean expression called found and set it to "False".
-
From line 35 to line 41 check that the frames with the correct format are present. If not, stop the script.
-
Assign the starting frame to the start variable.
-
Assign the ending frame to the end variable.
-
If start is greater than end, give an error message.
-
Assign the desired frames per second to fps variable.
-
If the name desired is empty, give error message.
-
Assign the desired name to the name variable.
Section 3: Compile the frame input into a video. See below for a line-by-line breakdown.
-
Combine the folder's pathname and the video's file name to generate a full pathname
-
Output the process of the video encoding to the console
-
Compile and encode the video using all the frames
-
If the video fails to compile, take note of the error message.
-
Call to the main function.
If everything goes well you should see this message at the end.
Code View: