-
Notifications
You must be signed in to change notification settings - Fork 13
/
movify.py
39 lines (32 loc) · 993 Bytes
/
movify.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
import os
import subprocess
def sort_files_by_date(directory):
files = os.listdir(directory)
files.sort(key=lambda x: os.path.getmtime(os.path.join(directory, x)))
return files
def convert_images_to_video(directory, output_file="output.mp4", framerate=16):
sorted_files = sort_files_by_date(directory)
with open("file_list.txt", "w") as file:
for filename in sorted_files:
if filename.endswith(".jpg"):
file_path = os.path.join(directory, filename)
file.write(f"file '{file_path}'\n")
file.write(f"duration {1/framerate}\n")
subprocess.run(
[
"ffmpeg",
"-f",
"concat",
"-safe",
"0",
"-i",
"file_list.txt",
"-vsync",
"vfr",
"-pix_fmt",
"yuv420p",
output_file,
]
)
os.remove("file_list.txt")
convert_images_to_video("./output")