-
Notifications
You must be signed in to change notification settings - Fork 45
/
fuse_videos.py
32 lines (25 loc) · 1.13 KB
/
fuse_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
import os
from easyvolcap.utils.console_utils import *
def generate_gif_from_pngs(directory):
for root, dirs, files in os.walk(directory):
# Check if the directory is not empty
if not files:
continue
if all(f"{i:04d}.png" in files for i in range(len(files))):
gif_name = os.path.basename(root) + ".gif"
# Define the path for the gif to be at the same level as root
gif_path = os.path.join(root, '..', gif_name)
png_str = os.path.join(root, "%04d.png")
# Construct the ffmpeg command
cmd = [
"ffmpeg", "-hide_banner", "-loglevel", "error", "-framerate", "30",
"-f", "image2", "-nostdin", "-y", "-r", "30", "-i",
f'"{png_str}"', "-lavfi",
"palettegen=stats_mode=single[pal],[0:v][pal]paletteuse=new=1", gif_path
]
# Execute the command
run(cmd)
print(f"Generated GIF for directory: {root}")
# Directory path
DIRECTORY_PATH = 'data/output' # Replace with your directory path
generate_gif_from_pngs(DIRECTORY_PATH)