Skvideo io install python

Write Videos From Images using Scikit Video

There are different libraries in python for processing images and videos. We can read videos using python modules like moviepy, opencv, sckit video etc. These libraries also provide tools to write videos in required specification. In this tutorial we are using pillow to read images scikit video to write frames to a video. To get started, you must have python installed and install these libraries.

pip install pillow scikit-video numpy

http://www.scikit-video.org/stable/ If you have alread images stored in a numpy array, you can simple write them in output mp4 file.

import skvideo.io import numpy as np # we create frames using numpy random method outputdata = np.random.random(size=(5, 720, 1280, 3)) * 255 outputdata = outputdata.astype(np.uint8) # save array to output file skvideo.io.vwrite("outputvideo.mp4", outputdata)

Now if we want to customize writer and we need to writer data using writer, we can create a video writer using scikit video. We will provide video save path and frames per second with video encoding quality and preset. You can change these settings according to your requirements and also you can view complete options on scikit video library homepage.

import skvideo.io # save path and fps video_save_path = "output.mp4" fps = 30 # create writer using FFmpegWriter writer = skvideo.io.FFmpegWriter(video_save_path, inputdict=, outputdict=) 

Now we iterate over all images in directory and read images using pillow. After we read an image, we can convert it to numpy array and write using writer.writeFrame() method.

import numpy as np import os from PIL import Image base_path = "IMAGES_DIRECTORY" # iterate over each image using os module for img in os.listdir(base_path): image = Image.open(os.path.join(base_path, img)) # read image image = np.array(image, dtype=np.uint8) #convert to unit8 numpy array # write frame writer.writeFrame(image) # close writer writer.close()

This will write it to path we provided while writing video file. There are different options available for input and output dictionary of writer that we can futher explore.tpg

Читайте также:  Python stdin read all about it

Источник

sk-video 1.1.10

This library provides easy access to common as well as state-of-the-art video processing routines. Check out the website for more details.

Подробности проекта

Ссылки проекта

Статистика

Метаданные

Лицензия: BSD License (BSD)

Сопровождающие

Классификаторы

История выпусков Уведомления о выпусках | Лента RSS

Загрузка файлов

Загрузите файл для вашей платформы. Если вы не уверены, какой выбрать, узнайте больше об установке пакетов.

Source Distribution

Uploaded 12 дек. 2017 г. source

Built Distribution

Uploaded 12 дек. 2017 г. py2 py3

Хеши для sk-video-1.1.10.tar.gz

Хеши для sk-video-1.1.10.tar.gz
Алгоритм Хеш-дайджест
SHA256 fb7125cfa2b31253dcf181d0bf285edd6bb25ffebf61dbd8ba11fadb783609a1 Копировать
MD5 bf253295a038c14785e17be9af68e186 Копировать
BLAKE2b-256 b34bc9613e4261e9c43988d45d0a4db3880d6591a22238f9a5dd81a412b898ae Копировать

Хеши для sk_video-1.1.10-py2.py3-none-any.whl

Хеши для sk_video-1.1.10-py2.py3-none-any.whl
Алгоритм Хеш-дайджест
SHA256 261aec6423a0188968771e532e6ccdbc53bcbd934d349280784210d9ca9ffe76 Копировать
MD5 12cee0b00324197ca656d83698800a12 Копировать
BLAKE2b-256 dd3fce848b8b2062ad1ccf1449094a740c775f6c761339f411e44f1e090f23a7 Копировать

Помощь

О PyPI

Внесение вклада в PyPI

Использование PyPI

Разработано и поддерживается сообществом Python’а для сообщества Python’а.
Пожертвуйте сегодня!

PyPI», «Python Package Index» и логотипы блоков являются зарегистрированными товарными знаками Python Software Foundation.

Источник

Reading and Writing Videos¶

skvideo.io is a module created for using a FFmpeg/LibAV backend to read and write videos. Depending on the available backend, the appropriate probing tool (ffprobe, avprobe, or even mediainfo) will be used to parse metadata from videos.

Reading¶

Use skvideo.io.vread to load any video (here bigbuckbunny ) into memory as a single ndarray. Note that this function assumes you have enough memory to do so, and should only be used for small videos.

import skvideo.io import skvideo.datasets videodata = skvideo.io.vread(skvideo.datasets.bigbuckbunny()) print(videodata.shape) 

Use skvideo.io.vreader to load any video (here bigbuckbunny ) frame-by-frame. This is the function to be used for larger files, and is actually faster than loading a video as 1 ndarray. However, it requires handling each frame as it is loaded. An example snippet:

import skvideo.io import skvideo.datasets videogen = skvideo.io.vreader(skvideo.datasets.bigbuckbunny()) for frame in videogen: print(frame.shape) 
(720, 1280, 3) (720, 1280, 3) . . . (720, 1280, 3) 

Sometimes, particular use cases require fine tuning FFmpeg’s reading parameters. For this, you can use skvideo.io.FFmpegReader

import skvideo.io import skvideo.datasets # here you can set keys and values for parameters in ffmpeg inputparameters = <> outputparameters = <> reader = skvideo.io.FFmpegReader(skvideo.datasets.bigbuckbunny(), inputdict=inputparameters, outputdict=outputparameters) # iterate through the frames accumulation = 0 for frame in reader.nextFrame(): # do something with the ndarray frame accumulation += np.sum(frame) 

For example, FFmpegReader will by default return an RGB representation of a video file, but you may want some other color space that FFmpeg supports, by setting appropriate key/values in outputparameters. Since FFmpeg output is piped into stdin, all FFmpeg commands can be used here.

inputparameters may be useful for raw video which has no header information. Then you should FFmpeg exactly how to interpret your data.

Writing¶

To write an ndarray to a video file, use skvideo.io.write

import skvideo.io import numpy as np outputdata = np.random.random(size=(5, 480, 680, 3)) * 255 outputdata = outputdata.astype(np.uint8) skvideo.io.vwrite("outputvideo.mp4", outputdata) 

Often, writing videos requires fine tuning FFmpeg’s writing parameters to select encoders, framerates, bitrates, etc. For this, you can use skvideo.io.FFmpegWriter

import skvideo.io import numpy as np outputdata = np.random.random(size=(5, 480, 680, 3)) * 255 outputdata = outputdata.astype(np.uint8) writer = skvideo.io.FFmpegWriter("outputvideo.mp4") for i in xrange(5): writer.writeFrame(outputdata[i, :, :, :]) writer.close() 

Reading Video Metadata¶

Use skvideo.io.ffprobe to find video metadata. As below:

import skvideo.io import skvideo.datasets import json metadata = skvideo.io.ffprobe(skvideo.datasets.bigbuckbunny()) print(metadata.keys()) print(json.dumps(metadata["video"], indent=4)) 

skvideo.io.ffprobe returns a dictionary, which can be passed into json.dumps for pretty printing. See the below output:

[u'audio', u'video']  "@index": "0", "@codec_name": "h264", "@codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", "@profile": "Main", "@codec_type": "video", "@codec_time_base": "1/50", "@codec_tag_string": "avc1", "@codec_tag": "0x31637661", "@width": "1280", "@height": "720", "@coded_width": "1280", "@coded_height": "720", "@has_b_frames": "0", "@sample_aspect_ratio": "1:1", "@display_aspect_ratio": "16:9", "@pix_fmt": "yuv420p", "@level": "31", "@chroma_location": "left", "@refs": "1", "@is_avc": "1", "@nal_length_size": "4", "@r_frame_rate": "25/1", "@avg_frame_rate": "25/1", "@time_base": "1/12800", "@start_pts": "0", "@start_time": "0.000000", "@duration_ts": "67584", "@duration": "5.280000", "@bit_rate": "1205959", "@bits_per_raw_sample": "8", "@nb_frames": "132", "disposition":  "@default": "1", "@dub": "0", "@original": "0", "@comment": "0", "@lyrics": "0", "@karaoke": "0", "@forced": "0", "@hearing_impaired": "0", "@visual_impaired": "0", "@clean_effects": "0", "@attached_pic": "0" >, "tag": [  "@key": "creation_time", "@value": "1970-01-01 00:00:00" >,  "@key": "language", "@value": "und" >,  "@key": "handler_name", "@value": "VideoHandler" > ] > 

© Copyright 2015-2017, scikit-video developers (BSD License).
Created using Sphinx 1.7.9.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Video Processing in Python

License

BSD-3-Clause, Unknown licenses found

Licenses found

scikit-video/scikit-video

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Use the new setup from setuptools.

Git stats

Files

Failed to load latest commit information.

README.rst

skvideologo

Travis

Borrowing coding styles and conventions from scikit-image and scikit-learn, scikit-video is a Python module for video processing built on top of scipy, numpy, and ffmpeg/libav.

This project is distributed under the 3-clause BSD.

Dependencies and Installation

Here are the requirements needed to use scikit-video.

  • Either ffmpeg (version >= 2.8) or libav (either version 10 or 11)
  • python (2.7, 3.3 <=)
  • numpy (version >= 1.9.2)
  • scipy (version >= 0.16.0)
  • PIL/Pillow (version >= 3.1)
  • scikit-learn (version >= 0.18)
  • mediainfo (optional)
$ sudo pip install scikit-video
  1. Make sure minimum dependencies (above) are installed. In addition, install setuptools (python-setuptools or python2-setuptools).
  2. Clone the scikit-video repository, enter the project directory, then run:

$ sudo python setup.py install

where python may refer to either python2 or python3.

If you installed scikit-video prior to version 1.1.10, you may have an import conflict. Run the following command(s) to fix it:

$ sudo pip uninstall sk-video

Then To check that the conflict no longer exists, import skvideo and print the file path:

import skvideo print(skvideo.__file__)

if setup correctly, you should see scikit_video in the path:

/usr/lib/python*/site-packages/scikit_video-*.*.*-py*.egg/skvideo/__init__.pyc
  • Spatial-Temporal filtering helper functions
  • Speedup routines (using cython and/or opencl)
  • More ffmpeg/avconv interfacing
  • Wrapping ffmpeg/avconv inside a subprocess to reduce memory overhead
  • Add additional algorithms and maintain more comprehensive benchmarks

Quick tutorial on how to go about setting up your environment to contribute to scikit-video:

After installation, you can launch the test suite from outside the source directory (you will need to have the nose package installed). To ensure that both python2 and python3 versions pass:

$ nosetests2 -v skvideo $ nosetests3 -v skvideo

Copyright 2015-2019, scikit-video developers (BSD license).

Источник

Оцените статью