FFMPEG Many video formats and cameras (via ffmpeg)

Extensions: .mov, .avi, .mpg, .mpeg, .mp4, .mkv, .wmv

The ffmpeg format provides reading and writing for a wide range of movie formats such as .avi, .mpeg, .mp4, etc. And also to read streams from webcams and USB cameras.

To read from camera streams, supply “<video0>” as the filename, where the “0” can be replaced with any index of cameras known to the system.

Note that for reading regular video files, the avbin plugin is more efficient.

By setting the environment variable ‘IMAGEIO_FFMPEG_EXE’ the ffmpeg executable to use can be overridden. E.g. os.environ['IMAGEIO_FFMPEG_EXE'] = '/path/to/my/ffmpeg' Otherwise, imageio will look for ffmpeg on the system path and then download ffmpeg if not found.

Parameters for reading

loop : bool
If True, the video will rewind as soon as a frame is requested beyond the last frame. Otherwise, IndexError is raised. Default False.
size : str | tuple
The frame size (i.e. resolution) to read the images, e.g. (100, 100) or “640x480”. For camera streams, this allows setting the capture resolution. For normal video data, ffmpeg will rescale the data.
pixelformat : str
The pixel format for the camera to use (e.g. “yuyv422” or “gray”). The camera needs to support the format in order for this to take effect. Note that the images produced by this reader are always rgb8.
ffmpeg_params: list
List additional arguments to ffmpeg for input file options. Example ffmpeg arguments to use aggressive error handling: [‘-err_detect’, ‘aggressive’]
print_info : bool
Print information about the video file as reported by ffmpeg.

Parameters for saving

fps : scalar
The number of frames per second. Default 10.
codec : str
the video codec to use. Default ‘libx264’, which represents the widely available mpeg4. Except when saving .wmv files, then the defaults is ‘msmpeg4’ which is more commonly supported for windows
quality : float | None
Video output quality. Default is 5. Uses variable bit rate. Highest quality is 10, lowest is 0. Set to None to prevent variable bitrate flags to FFMPEG so you can manually specify them using ffmpeg_params instead. Specifying a fixed bitrate using ‘bitrate’ disables this parameter.
bitrate : int | None
Set a constant bitrate for the video encoding. Default is None causing ‘quality’ parameter to be used instead. Better quality videos with smaller file sizes will result from using the ‘quality’ variable bitrate parameter rather than specifiying a fixed bitrate with this parameter.
pixelformat: str
The output video pixel format. Default is ‘yuv420p’ which most widely supported by video players.
ffmpeg_params: list
List additional arguments to ffmpeg for output file options. Example ffmpeg arguments to use only intra frames and set aspect ratio: [‘-intra’, ‘-aspect’, ‘16:9’]
ffmpeg_log_level: str
Sets ffmpeg output log level. Default is “warning”. Values can be “quiet”, “panic”, “fatal”, “error”, “warning”, “info” “verbose”, or “debug”. Also prints the FFMPEG command being used by imageio if “info”, “verbose”, or “debug”.
macro_block_size: int
Size constraint for video. Width and height, must be divisible by this number. If not divisible by this number imageio will tell ffmpeg to scale the image up to the next closest size divisible by this number. Most codecs are compatible with a macroblock size of 16 (default), some can go smaller (4, 8). To disable this automatic feature set it to None, however be warned many players can’t decode videos that are odd in size and some codecs will produce poor results or fail. See https://en.wikipedia.org/wiki/Macroblock.