Skip to main content

Module for saving and loading images and depth as H.264 video

Project description

videoio: save/load image sequence as H.264 video

A small Python module for saving and loading RGB and uint16 (depth) frames as H.264 encoded video

Quickstart

Save/load RGB frames:
import numpy as np
from videoio import videosave, videoread
frames = np.random.random((20,200,400,3)) #[framesNr, height, width, RGB]
# Save to video
videosave("out.mp4", frames)
# Load from video
frames = videoread("out.mp4")
Read frames sequentially:
from videoio import VideoReader
for frame in VideoReader("in.mp4"):
    do_something_with(frame)
Write frames sequentially:
from videoio import VideoWriter
writer = VideoWriter("out.mp4", resolution=(400, 200)) #[width, height]
for i in range(100):
    frame = get_frame()
    writer.write(frame)
writer.close()

or

with VideoWriter("out.mp4", resolution=(400, 200)) as writer:
    for i in range(100):
        frame = get_frame()
        writer.write(frame)
Lossless write/read of uint16 3D arrays (useful for saving depth frames stored in mm, for example Kinect data):
import numpy as np
from videoio import uint16save, uint16read
# Generate 20 random depth frames
depth_frames = (np.random.random((20,200,400))*65535).astype(np.uint16)
# Save
uint16save("out_depth.mp4", depth_frames)
# Load
depth_frames = uint16read("out_depth.mp4")
Save RGB frames in lossless mode with different compression preset and different FPS:
videosave("out.mp4", frames, lossless=True, preset="veryfast", fps=10.5)
Read RGB frames and scale them to target resolution simultaneously:
frames = videoread("in.mp4", output_resolution=(100, 250))

Prerequisites

  • ffmpeg with libx264 enabled and ffprobe (usually comes with ffmpeg)
  • numpy
  • ffmpeg-python

Installation

From pip:

pip install videoio

From source:

git clone https://github.com/vguzov/videoio.git
python setup.py install

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

videoio-0.1.2-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file videoio-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: videoio-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for videoio-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 81cd2bbad3eec34eb2a9f3eb3a58fd1df86cfbc89541b830748b9a6b30b96833
MD5 3d92945336332b7bf38e2a92fdd47c73
BLAKE2b-256 d185ff6cb53b79407c6ee029be111d7be28b476cf17b5beb07010e4b9a012b0a

See more details on using hashes here.

Supported by

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