#๐ How to create a video from images (frames)
33 messages ยท Page 1 of 1 (latest)
@sweet roost
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
i would just use the ffmpeg command line utility (not from python), but if you really need to do it with python it looks like the OpenCV library is one way to do it
or use a warpper for ffmpeg ๐
im using cv2 rn
if you are satisfied with that solution you might close this help topic
otherwise, please elaborate what you aren't content with when using cv2
i didnt get anywhere :3
oh, so you're stuck right now?
show the code you got if you require further assistance
!code if it's short
import datetime
from time import sleep
from PIL import ImageGrab
import keyboard
from pathlib import Path
from tkinter import Image, simpledialog as sd
import cv2
FPS = 15
ALT = "alt"
EXIT_BIND = "g"
ENTER_BIND = "x"
ENTER_NAME_BIND = "n"
NAME = "store"
parent = Path(NAME)
parent.mkdir(exist_ok=True)
def exit(path: Path):
for image in frames:
image.save("")
def record_loop(new: str | None = None):
frame = 0
if new is None:
new = str(datetime.datetime.today()).split("-")[1].replace(":", "-")
while True:
if keyboard.is_pressed("+".join([ALT, EXIT_BIND])):
exit(parent / new)
break
frame += 1
number_string = str(frame)
number_string.zfill(5 - len(str(frame)))
name = f"f_{number_string}"
screenshot = ImageGrab.grab()
screenshot.save(name)
sleep(1 / FPS)
def main():
while True:
if keyboard.is_pressed(ALT):
if keyboard.is_pressed(ENTER_BIND):
record_loop()
if keyboard.is_pressed(ENTER_NAME_BIND):
s = sd.askstring("Name", "Name for this recording")
record_loop(s)
sleep(.1)
if __name__ == "__main__":
main()
``` here
"short"
currently gonna insert the images into it
i think i got it
the exit() function you have defined looks a bit strange
the new exit() function makes a lot more sense
i still fixed it more
anyway first error! :D
Traceback (most recent call last):
File "c:\Users\Uzivatel\Desktop\Langs\Python\screen recorder.py", line 78, in <module>
main()
File "c:\Users\Uzivatel\Desktop\Langs\Python\screen recorder.py", line 72, in main
record_loop(s)
File "c:\Users\Uzivatel\Desktop\Langs\Python\screen recorder.py", line 55, in record_loop
exit(parent / new)
File "c:\Users\Uzivatel\Desktop\Langs\Python\screen recorder.py", line 22, in exit
output_video = path.with_suffix("mp4").name
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Uzivatel\AppData\Local\Programs\Python\Python312\Lib\pathlib.py", line 651, in with_suffix
raise ValueError("Invalid suffix %r" % (suffix))
ValueError: Invalid suffix 'mp4'
why is this?
(im pro)
i forgor the dot
https://paste.pythondiscord.com/3I3Q @balmy wind it works, except its much shorter than its supposed to be
what do you mean it's shorter then it supposed to be?
you mean the resulting video?
yes
yeah so it works
its just super fast
confirmed
by testing it
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.