Skip to content

Instantly share code, notes, and snippets.

@Chuzzy
Created November 23, 2024 11:05
Show Gist options
  • Select an option

  • Save Chuzzy/e26b32884e50299367f6fc239343a25f to your computer and use it in GitHub Desktop.

Select an option

Save Chuzzy/e26b32884e50299367f6fc239343a25f to your computer and use it in GitHub Desktop.
Countdown timer
import subprocess
import glob, os
def seconds_to_formatted_time(seconds):
minutes = seconds // 60
seconds = seconds - (minutes * 60)
return f"{int(minutes)}:{seconds:05.2f}"
for minutes in range(2,5):
current_time = minutes * 60.0
one_frame = 1 / 60.0
i = 0
while current_time >= 0:
print(minutes, i, seconds_to_formatted_time(current_time))
command = f"magick -background black -fill red -font DSEG7ClassicMini-Regular.ttf -size 1920x1080 -gravity center label:{seconds_to_formatted_time(current_time)} image{i:07}.png"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
i += 1
current_time -= one_frame
current_time = 0
for x in range(0, 60 * 10):
print(seconds_to_formatted_time(current_time))
command = f"magick -background black -fill red -font DSEG7ClassicMini-Regular.ttf -size 1920x1080 -gravity center label:{seconds_to_formatted_time(current_time)} image{i:07}.png"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
i += 1
cmd=f"ffmpeg -framerate 60 -i image%7d.png -r 60 -c:v libx264 -vf format=yuv420p timer{minutes}.mp4"
subprocess.run(cmd, shell=True, capture_output=True, text=True)
for f in glob.glob("image*.png"):
os.remove(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment