Skip to main content

A python library which simplifies creating and exporting videos.

Project description

vidmaker

A python library which simplifies creating and exporting videos.

Purpose

vidmaker was created because I wanted to record some of my pygame projects, and I found this to be the most convenient way.

How to use

NOTE: vidmaker uses temporary disk space to store frames. This prevents over usage of memory, but slows it down

Since this is a python library, install it by pip install vidmaker

Currently vidmaker only has one class, Video, making it extremely simple to use.

First, you have to initialize your video with the path you want it to render at the fps and the resolution. Always include the ".mp4" ending to the path, vidmaker DOES NOT do it for you.

import vidmaker

video = vidmaker.Video(path="vidmaker.mp4", fps=60, resolution=(300, 300))

Then you have to update the video every frame with the image you want it to add to your video.

import pygame
import vidmaker

FPS = 60

WINDOW = pygame.display.set_mode((300, 300))
# If fps and resolution are auto then late_export has to be True
video = vidmaker.Video("vidmaker.mp4", late_export=True)
pygame.display.set_caption("vidmaker test")


def main(window):
    pygame.init()
    clock = pygame.time.Clock()

    while True:
        clock.tick(FPS)
        window.fill((255, 0, 0))
        events = pygame.event.get()
        keys = pygame.key.get_pressed()
        ctrl_pressed = keys[pygame.K_LCTRL] or keys[pygame.K_RCTRL]
        for event in events:
            if event.type == pygame.QUIT:
                pygame.quit()
                return
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q and ctrl_pressed:
                    pygame.quit()
                    return

        # set inverted=True if your colors are inverted
        video.update(pygame.surfarray.pixels3d(window).swapaxes(0, 1), inverted=False)  # THIS LINE
        pygame.display.update()


main(WINDOW)

Once your program finishes, you just have to export your video

video.export(verbose=True)

If you have a long video, you may consider compressing it to a smaller file size. vidmaker offers custom compression although it requires ffmpeg and is not super accurate, although very useful. If your desired compression settings don't turn out as intended, you can just run compress again with the rest of the code commented out.

video.compress(target_size=1024, new_file=True)  # target_size is in KB
"""
Old code of unsuccessful compression
"""
video.compress(target_size=2048, new_file=True)  # keep testing different compression sizes until you find a good one

That's it! You should find your video fully rendered at the given path, but the longer the video, the longer video.export() and video.compress() take. I tested around 100fps during exporting on my computer and it should be even faster without verbose; compression is also much faster than export. The speed does heavily depend of what you are exporting and your computer.

Contributing

Contributing is always appreciated! I would love it if anyone was to make a pull request to add another feature or create an issue post. Possible features could be things like an option to use memory instead of disk space, the option to render videos in different formats (only mp4 right now), and many more. If there is enough demand I might add some myself as well. Thanks for the support!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vidmaker-2.3.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

vidmaker-2.3.0-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file vidmaker-2.3.0.tar.gz.

File metadata

  • Download URL: vidmaker-2.3.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for vidmaker-2.3.0.tar.gz
Algorithm Hash digest
SHA256 9bfe6fbb366cd4248ada1ee17cf6deaaf7272ab9e8bd2ae1c412be71154c0569
MD5 e97b1add09bea30c4c85b5f1a5dd0082
BLAKE2b-256 14ffb851b494fad7eb33d4450df0b1200312ae8987f5060cccfd8ed3a9183ce4

See more details on using hashes here.

File details

Details for the file vidmaker-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: vidmaker-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for vidmaker-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 662a2fd0da073838b8ebb8c64ce71737e0321bcf863d0800f180bf7831dd5b5b
MD5 8836aaad156c390ae3fcf830d0dff708
BLAKE2b-256 fc571359cb4447908065e0ff5924450a268ad5c658ee7a0ae5b4cb9cac87d6a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page