#๐Ÿ”’ How to create a video from images (frames)

33 messages ยท Page 1 of 1 (latest)

sweet roost
#

title, i am trying to make a very lightweight screen recorder with python (15fps+480p) and i need a way to create a video from all the frames thanks

opaque pilotBOT
#

@sweet roost

Python help channel opened

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.

balmy wind
lusty current
#

or use a warpper for ffmpeg ๐Ÿ™‚

sweet roost
#

im using cv2 rn

balmy wind
# sweet roost 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

balmy wind
#

!code if it's short

opaque pilotBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

sweet roost
#
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

balmy wind
sweet roost
#

i just finished it

balmy wind
sweet roost
#

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

sweet roost
balmy wind
sweet roost
#

yes

sweet roost
#

its just super fast

#

confirmed

#

by testing it

opaque pilotBOT
#
Python help channel closed for inactivity

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.