skvideo.io.FFmpegWriter
skvideo.io.FFmpegWriter¶Writes frames using FFmpeg
Using FFmpeg as a backend, this class provides sane initializations for the default case.
Video file path for writing.
How to interpret the frames piped in from Python.
How to encode the output file.
Path to a media file whose audio track should be muxed into the
output. Used to preserve audio across a vread / vwrite
round-trip (issues #173, #176). By default the output contains
the video from the piped-in frames plus the first audio
stream from audiosrc (equivalent to passing
-map 0:v:0 -map 1:a:0 to ffmpeg).
To take full control of stream selection, supply your own
-map in outputdict. When outputdict contains a
-map entry, our default -map arguments yield entirely;
this is in line with ffmpeg’s additive -map semantics (a
second -map adds streams rather than overriding earlier
ones). Examples (note the list form for multiple -map
values):
Copy all audio streams:
outputdict={'-map': ['0:v:0', '1:a']}Pick a specific audio stream:
outputdict={'-map': ['0:v:0', '1:a:5']}
The audio is stream-copied with -c:a copy (no re-encoding);
set -c:a (or -codec:a / -acodec) in outputdict
to override the codec. The output is also trimmed to the shorter
of video/audio via -shortest, which is the intuitive
behavior when the video is a subset of the original.
0 (default) for quiet, 1 to print the ffmpeg command.
Methods
|
Closes the video and terminates FFmpeg process |
|
Sends ndarray frames to FFmpeg |
Notes
The FFmpeg subprocess is launched lazily on the first writeFrame
call. Constructing a writer and calling close() without writing any
frames is a no-op and produces no output file — this keeps cleanup in a
finally (or a construct-only validation) from raising. Use the
high-level skvideo.io.vwrite, which rejects empty (0-frame) input
with ValueError, if you want that guarded.
Prepares parameters
Does not instantiate the an FFmpeg subprocess, but simply prepares the required parameters.
Video file path for writing
Input dictionary parameters, i.e. how to interpret the data coming from python.
Output dictionary parameters, i.e. how to encode the data when writing to file.
Closes the video and terminates FFmpeg process
Raises RuntimeError if FFmpeg exited with a non-zero return
code, including its stderr output in the exception message (issue
#111). Previously a failing encode produced a silent empty/corrupt
output file with no indication of what went wrong.
Sends ndarray frames to FFmpeg