videoio


Namevideoio JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/vguzov/videoio
SummaryModule for saving and loading images and depth as H.264 video
upload_time2024-08-27 13:16:19
maintainerNone
docs_urlNone
authorVladimir Guzov
requires_pythonNone
licenseNone
keywords mp4 png h264 video image depth ffmpeg
VCS
bugtrack_url
requirements numpy ffmpeg
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

## Prerequisites

- `ffmpeg>=2.1` **with libx264 enabled**
    - If you are using conda, you can install the correct version with `conda remove ffmpeg` and `conda install ffmpeg x264 -c conda-forge`
- `ffprobe` (usually comes with ffmpeg)

## Quickstart

##### Save/load RGB frames:

```python
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:

```python
from videoio import VideoReader

for frame in VideoReader("in.mp4"):
    do_something_with(frame)
```

##### Write frames sequentially:

```python
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

```python
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):

```python
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:

```python
videosave("out.mp4", frames, lossless=True, preset="veryfast", fps=10.5)
```

##### Read RGB frames and scale them to target resolution simultaneously:

```python
frames = videoread("in.mp4", output_resolution=(100, 250))
```

##### Read video/uint16-array starting from certain frame:

(Works if the input video was created by videoio, other cases are not guaranteed)

```python
frames = videoread("in.mp4", start_frame=100)

for frame in VideoReader("in.mp4", start_frame=100):
    do_something_with(frame)
```

## Installation

From pip:

```
pip install videoio
```

From source:

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vguzov/videoio",
    "name": "videoio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "mp4, png, h264, video, image, depth, ffmpeg",
    "author": "Vladimir Guzov",
    "author_email": "guzov.mail@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/07/8b/3e53eca0ef2bfe1772a153fcf3c15cef556e98ee3e2c422985d07d44d499/videoio-0.3.0.tar.gz",
    "platform": null,
    "description": "# videoio: save/load image sequence as H.264 video\n\nA small Python module for saving and loading RGB and uint16 (depth) frames as H.264 encoded video\n\n## Prerequisites\n\n- `ffmpeg>=2.1` **with libx264 enabled**\n    - If you are using conda, you can install the correct version with `conda remove ffmpeg` and `conda install ffmpeg x264 -c conda-forge`\n- `ffprobe` (usually comes with ffmpeg)\n\n## Quickstart\n\n##### Save/load RGB frames:\n\n```python\nimport numpy as np\nfrom videoio import videosave, videoread\n\nframes = np.random.random((20, 200, 400, 3))  # [framesNr, height, width, RGB]\n# Save to video\nvideosave(\"out.mp4\", frames)\n# Load from video\nframes = videoread(\"out.mp4\")\n```\n\n##### Read frames sequentially:\n\n```python\nfrom videoio import VideoReader\n\nfor frame in VideoReader(\"in.mp4\"):\n    do_something_with(frame)\n```\n\n##### Write frames sequentially:\n\n```python\nfrom videoio import VideoWriter\n\nwriter = VideoWriter(\"out.mp4\", resolution=(400, 200))  # [width, height]\nfor i in range(100):\n    frame = get_frame()\n    writer.write(frame)\nwriter.close()\n```\n\nor\n\n```python\nwith VideoWriter(\"out.mp4\", resolution=(400, 200)) as writer:\n    for i in range(100):\n        frame = get_frame()\n        writer.write(frame)\n```\n\n##### Lossless write/read of uint16 3D arrays (useful for saving depth frames stored in mm, for example Kinect data):\n\n```python\nimport numpy as np\nfrom videoio import uint16save, uint16read\n\n# Generate 20 random depth frames\ndepth_frames = (np.random.random((20, 200, 400)) * 65535).astype(np.uint16)\n# Save\nuint16save(\"out_depth.mp4\", depth_frames)\n# Load\ndepth_frames = uint16read(\"out_depth.mp4\")\n```\n\n##### Save RGB frames in lossless mode with different compression preset and different FPS:\n\n```python\nvideosave(\"out.mp4\", frames, lossless=True, preset=\"veryfast\", fps=10.5)\n```\n\n##### Read RGB frames and scale them to target resolution simultaneously:\n\n```python\nframes = videoread(\"in.mp4\", output_resolution=(100, 250))\n```\n\n##### Read video/uint16-array starting from certain frame:\n\n(Works if the input video was created by videoio, other cases are not guaranteed)\n\n```python\nframes = videoread(\"in.mp4\", start_frame=100)\n\nfor frame in VideoReader(\"in.mp4\", start_frame=100):\n    do_something_with(frame)\n```\n\n## Installation\n\nFrom pip:\n\n```\npip install videoio\n```\n\nFrom source:\n\n```\ngit clone https://github.com/vguzov/videoio.git\npython setup.py install\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Module for saving and loading images and depth as H.264 video",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/vguzov/videoio"
    },
    "split_keywords": [
        "mp4",
        " png",
        " h264",
        " video",
        " image",
        " depth",
        " ffmpeg"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2da5ea290cc888a6114868081491981bec03a6261a5e22fdabdcb89ed5a97da2",
                "md5": "70b8697d501854ff7473c00ed4c63f87",
                "sha256": "5ff628fbdddb67931d36ca7557205c632fba09cd96494294e936122b4fd29201"
            },
            "downloads": -1,
            "filename": "videoio-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "70b8697d501854ff7473c00ed4c63f87",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13610,
            "upload_time": "2024-08-27T13:16:17",
            "upload_time_iso_8601": "2024-08-27T13:16:17.974386Z",
            "url": "https://files.pythonhosted.org/packages/2d/a5/ea290cc888a6114868081491981bec03a6261a5e22fdabdcb89ed5a97da2/videoio-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "078b3e53eca0ef2bfe1772a153fcf3c15cef556e98ee3e2c422985d07d44d499",
                "md5": "70231777492623d67db7a6b7fb93f65f",
                "sha256": "ff006088c9dc5bdd7ea73a7317177d0c3e67033114f68711a43d0b66bfc0e492"
            },
            "downloads": -1,
            "filename": "videoio-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "70231777492623d67db7a6b7fb93f65f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12189,
            "upload_time": "2024-08-27T13:16:19",
            "upload_time_iso_8601": "2024-08-27T13:16:19.067432Z",
            "url": "https://files.pythonhosted.org/packages/07/8b/3e53eca0ef2bfe1772a153fcf3c15cef556e98ee3e2c422985d07d44d499/videoio-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-27 13:16:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vguzov",
    "github_project": "videoio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "ffmpeg",
            "specs": []
        }
    ],
    "lcname": "videoio"
}
        
Elapsed time: 0.30182s