Skip to main content

A Python class for streaming video from a camera or a video file. It supports frame resizing, FPS control, and automatic restart of the video stream in case of errors.

Project description

Video Streamer

A Python class for streaming video from a camera or a video file. It supports frame resizing, FPS control, and automatic restart of the video stream in case of errors.

Features

  • Stream video from a given source (camera or video file).
  • Control the FPS of the video stream.
  • Option to resize the video frames.
  • Automatic restart of the video stream if the source becomes unavailable.
  • Multi-threaded streaming for asynchronous video frame retrieval.

Installation

To install the required dependencies, you need to install OpenCV:

pip install opencv-python

Usage

Here is an example of how to use the VideoStreamer class:

from video_streamer import VideoStreamer
import cv2

# Set your video source (camera index 0 or a video file path)
video_source = "1.avi"  # Change this to your video source (0 for webcam, or a video file path)

# Create a VideoStreamer instance
streamer = VideoStreamer(video_source)

# Start the video stream in a separate thread
streamer.start()

# Continuously display the video stream
while True:
    frame = streamer.get_frame()
    if frame is None:
        continue
    cv2.imshow("Video Stream", frame)
    
    # Press 'q' to quit the video stream
    if cv2.waitKey(300) & 0xFF == ord('q'):
        break

# Stop the video stream
streamer.stop_thread()
cv2.destroyAllWindows()

Arguments:

  • video_source: The source of the video, which could be a file path or a camera index (0 for webcam).
  • fps (optional): Frames per second for the video stream. If not provided, the default FPS of the video source is used (or 30 if unavailable).
  • resolution (optional): A tuple specifying the width and height for resizing the video frames. If not provided, the original resolution of the video source is used.
  • auto_restart (optional): If set to True, the video stream will automatically restart if the video source becomes unavailable. Default is False.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

monkez_video_input-0.1.1.tar.gz (2.1 kB view details)

Uploaded Source

Built Distribution

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

monkez_video_input-0.1.1-py3-none-any.whl (2.1 kB view details)

Uploaded Python 3

File details

Details for the file monkez_video_input-0.1.1.tar.gz.

File metadata

  • Download URL: monkez_video_input-0.1.1.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for monkez_video_input-0.1.1.tar.gz
Algorithm Hash digest
SHA256 14aeb9b078351a5e49bdbe323b6bd33f67da6986f742dae103fd616f7bd50573
MD5 7482a80210e59a37b629ec189e601ef3
BLAKE2b-256 9a425cd4b438677547c5eaed47057710b032d02c423029acd4e28e650ede4370

See more details on using hashes here.

File details

Details for the file monkez_video_input-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for monkez_video_input-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 985999caf9fc4c47d805fe300a0c0396b67db92e919a534e7477dafd04e872d0
MD5 432e024adc4e6ae413a12924907e7fe0
BLAKE2b-256 e345043089287ce1b1ae4c237672ea10ee45c7862b63df091ae7b26ed6ec7785

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