Globals¶
- av.open(file, mode='r', **kwargs)¶
Main entrypoint to opening files/streams.
- Parameters:
file (str) – The file to open, which can be either a string or a file-like object.
mode (str) –
"r"for reading and"w"for writing.format (str) – Specific format to use. Defaults to autodect.
options (dict) – Options to pass to the container and all streams.
container_options (dict) – Options to pass to the container.
buffer_size (int) – Size of buffer for Python input/output operations in bytes. Honored only when
fileis a file-like object. Defaults to 32768 (32k).timeout – How many seconds to wait for data before giving up, as a float, or a
(open timeout, read timeout)tuple. The open timeout covers both connecting and reading or writing the header. The read timeout covers each subsequent demux, mux, or close, so a stalled peer gives up rather than blocking forever. Each demux and mux gets the full timeout; a close shares one across writing the trailer and flushing, so it cannot outlast the timeout either. On output, it applies only where the destination is unseekable, such as a socket or a pipe. A seekable file is left alone, since the time a write takes there scales with the file rather than with a peer, and giving up part-way would leave it unreadable. A mux that does time out leaves the error on the I/O context, so every later mux and the trailer fail at once. There is no retrying after one.io_open (callable) – Custom I/O callable for opening files/streams. This option is intended for formats that need to open additional file-like objects to
fileusing custom I/O. The callable signature isio_open(url: str, flags: int, options: dict), whereurlis the url to open,flagsis a combination of AVIO_FLAG_* andoptionsis a dictionary of additional options. The callable should return a file-like object.hwaccel (HWAccel) – Optional settings for hardware-accelerated decoding.
- Return type:
For devices (via
libavdevice), pass the name of the device toformat, e.g.:>>> # Open webcam on MacOS. >>> av.open('0', format='avfoundation')
For DASH and custom I/O using
io_open, add a protocol prefix to thefileto prevent the DASH encoder defaulting to the file protocol and using temporary files. The custom I/O callable can be used to remove the protocol prefix to reveal the actual name for creating the file-like object. E.g.:>>> av.open("customprotocol://manifest.mpd", "w", io_open=custom_io)
See also
More information on using input and output devices is available on the FFmpeg website.