forked from missing-semester/videos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_title_videos.py
50 lines (44 loc) · 951 Bytes
/
make_title_videos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# https://stackoverflow.com/questions/25891342/creating-a-video-from-a-single-image-for-a-specific-duration-in-ffmpeg
import subprocess
# expect names of files as "[class_abbreviation]_lec[lecture_number]_title.png"
folder = "content/"
prefix = "dcai"
suffix = "png"
num_lectures = 7
duration = 3
framerate = 25
files = []
for i in range(num_lectures):
filename = f"{folder}{prefix}_lec{i+1:02d}_title.{suffix}"
files.append(filename)
for input_file in files:
output_file = input_file[:-4] + ".mp4"
command = [
"ffmpeg",
"-framerate",
str(framerate),
"-i",
input_file,
"-t",
str(duration),
"-c:v",
"libx264",
"-x265-params",
"lossless=1",
"-pix_fmt",
"yuvj420p",
"-vf",
"scale=1920:1080",
output_file,
"-f",
"lavfi",
"-i",
"anullsrc",
"-c:a",
"aac",
"-shortest"
]
try:
subprocess.run(command, check=True)
except subprocess.CalledProcessError as e:
print(f"Error during conversion: {e}")