https://github.com/bluemirrors/vidsz
Common Wrapper/Interface around various video reading/writing tools to make video reading stable, consistent, and super easy around different systems and OS.
https://github.com/bluemirrors/vidsz
opencv-python python python3 video-reader video-writer
Last synced: about 1 year ago
JSON representation
Common Wrapper/Interface around various video reading/writing tools to make video reading stable, consistent, and super easy around different systems and OS.
- Host: GitHub
- URL: https://github.com/bluemirrors/vidsz
- Owner: BlueMirrors
- License: apache-2.0
- Created: 2021-06-04T11:32:03.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-24T19:37:24.000Z (about 4 years ago)
- Last Synced: 2025-04-09T07:48:26.957Z (about 1 year ago)
- Topics: opencv-python, python, python3, video-reader, video-writer
- Language: Python
- Homepage: https://vidsz.readthedocs.io/
- Size: 1.95 MB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#
Vidsz: Video's Wizard
 [](https://www.codefactor.io/repository/github/bluemirrors/vidsz)  [](https://www.python.org/) [](https://vidsz.readthedocs.io/en/latest/?badge=latest) [](https://pepy.tech/project/vidsz)
Common Wrapper/Interface around various video reading/writing tools to make video reading stable, consistent and super easy around different systems and OS.
```bash
pip install vidsz
```
Backends
- OpenCV (in-development)
Features
- Easy and hassle free (read/write with ```for-loop```, ```with-block```, ```while-loop```)
- Batch Support. Read and write frames in batches.
# Read Video
## Read with ```for-loop```
```python
from vidsz.opencv import Reader
# open reader
reader = Reader("static/countdown.mp4")
# read frame with for loop
for frame in reader:
# use ndarry-frame however you like
pass
# release
reader.release()
```
## Read with a ```with-block```
```python
with Reader("static/countdown.mp4") as reader:
frame = reader.read()
```
## Read with a ```while-loop```
```python
# this follows similar behavior as opencv counterpart
while reader.is_open():
# returns ndarry-frame or None if nothing left to read
frame = reader.read()
if frame is None:
break
```
## Read frames in a ```batch```
```python
with Reader("dummy.mp4", batch_size=8, dynamic_batch=True) as reader:
batch_frames = reader.read()
```
## Get properties of the reader
```python
# print info: width, height, fps etc.
print(reader)
# access specific things
print(reader.width, reader.height, reader.fps)
# access number-of-frames/seconds/minutes that have been read
print(reader.frame_count, reader.seconds, reader.minutes)
```
# Write Video
## Write a single frame
```python
from vidsz.opencv import Reader, Writer
video_fname = "static/countdown.mp4"
# open reader
reader = Reader(video_fname)
# start writer with the Reader object
# by default it'll append _out in the name of the output video
writer = Writer(reader)
# start writer with your settings;
# you can also give any combinations of
# following settings with Reader object to
# overwrite default settings
writer = Writer(name="out.mp4", width=1920, height=1080, fps=15)
# print writer info
print(writer)
# write single frame
frame = reader.read()
writer.write(frame)
```
## Write with ```for-loop```
```python
# read frame with for loop
for frame in reader:
# write the ndarry-frame
writer.write(frame)
```
## Write a ```batch```
```python
# read batches and write
with Reader("dummy.mp4", batch_size=8, dynamic_batch=True) as reader:
batch_frames = reader.read()
# write list or ndarray of frames
writer.write_all(batch_frames)
# close off
reader.release()
writer.release()
```
## Write with a ```with-block```
```python
# using "with" block, write "static/countdown_out.mp4" (clone of input)
with Reader(video_fname) as reader:
with Writer(reader, name="out_with.mp4") as writer:
writer.write_all(reader)
```
***Logo-Attribution***
Designed by brgfx / Freepik