Implement App
This commit is contained in:
parent
fdcefdada9
commit
d68570abe7
44
app.py
Normal file
44
app.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from PIL import Image
|
||||||
|
from alive_progress import alive_bar
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
try:
|
||||||
|
shutil.rmtree("tmp")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
os.makedirs("tmp", exist_ok=True)
|
||||||
|
|
||||||
|
fps = 60
|
||||||
|
width = 1920
|
||||||
|
height = 1080
|
||||||
|
bpm = 60
|
||||||
|
length_seconds = 20
|
||||||
|
|
||||||
|
color1 = (255, 0, 0)
|
||||||
|
color2 = (0, 0, 255)
|
||||||
|
|
||||||
|
total_frames = fps * length_seconds
|
||||||
|
frames_per_beat = fps * 60 // bpm
|
||||||
|
|
||||||
|
with alive_bar(total_frames, title="Generating images") as bar:
|
||||||
|
for counter in range(total_frames):
|
||||||
|
if counter % frames_per_beat == 0:
|
||||||
|
img = Image.new("RGB", (width, height), color1)
|
||||||
|
else:
|
||||||
|
img = Image.new("RGB", (width, height), color2)
|
||||||
|
img.save(f"tmp/{counter}.png")
|
||||||
|
bar() # Increment the progress bar
|
||||||
|
|
||||||
|
subprocess.run([
|
||||||
|
"ffmpeg", "-framerate", str(fps), "-i", "tmp/%d.png",
|
||||||
|
"-c:v", "libx264", "-pix_fmt", "yuv420p", "output.mp4"
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user