Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ninjaneural
GitHub Repository: ninjaneural/webui
Path: blob/master/memo/comfyui_anidiff_long/video.py
3275 views
1
import os
2
import shutil
3
from PIL import Image
4
import subprocess
5
6
7
def process_images(target_dir, video_output, fps, sound_file):
8
# FFmpeg를 사용하여 동영상 생성
9
if sound_file:
10
ffmpeg_command = f"ffmpeg -framerate {fps} -i {target_dir}/%07d.png -i {sound_file} -c:a copy -c:v libx264 -pix_fmt yuv420p -map 0:v -map 1:a {video_output}"
11
else:
12
ffmpeg_command = f"ffmpeg -framerate {fps} -i {target_dir}/%07d.png -c:v libx264 -pix_fmt yuv420p {video_output}"
13
14
subprocess.run(ffmpeg_command, shell=True)
15
16
# 사용 예
17
target_dir = './combine' # 타겟 폴더 경로
18
video_output = 'output_video2.mp4' # 출력 동영상 파일 이름
19
fps = 30
20
sound_file = "sound.mp4"
21
22
process_images(target_dir, video_output, fps, sound_file)
23
24