moviepy.video.io.ffmpeg_writer.FFMPEG_VideoWriter#
- class moviepy.video.io.ffmpeg_writer.FFMPEG_VideoWriter(filename, size, fps, codec='libx264', audiofile=None, preset='medium', bitrate=None, with_mask=False, logfile=None, threads=None, ffmpeg_params=None, pixel_format=None)[source]#
A class for FFMPEG-based video writing.
- Parameters:
filename (str) – Any filename like
"video.mp4"
etc. but if you want to avoid complications it is recommended to use the generic extension".avi"
for all your videos.size (tuple or list) – Size of the output video in pixels (width, height).
fps (int) – Frames per second in the output video file.
codec (str, optional) –
FFMPEG codec. It seems that in terms of quality the hierarchy is ‘rawvideo’ = ‘png’ > ‘mpeg4’ > ‘libx264’ ‘png’ manages the same lossless quality as ‘rawvideo’ but yields smaller files. Type
ffmpeg -codecs
in a terminal to get a list of accepted codecs.Note for default ‘libx264’: by default the pixel format yuv420p is used. If the video dimensions are not both even (e.g. 720x405) another pixel format is used, and this can cause problem in some video readers.
audiofile (str, optional) – The name of an audio file that will be incorporated to the video.
preset (str, optional) – Sets the time that FFMPEG will take to compress the video. The slower, the better the compression rate. Possibilities are:
"ultrafast"
,"superfast"
,"veryfast"
,"faster"
,"fast"
,"medium"
(default),"slow"
,"slower"
,"veryslow"
,"placebo"
.bitrate (str, optional) – Only relevant for codecs which accept a bitrate. “5000k” offers nice results in general.
with_mask (bool, optional) – Set to
True
if there is a mask in the video to be encoded.pixel_format (str, optional) – Optional: Pixel format for the output video file. If is not specified
"rgb24"
will be used as the default format unlesswith_mask
is set asTrue
, then"rgba"
will be used.logfile (int, optional) – File descriptor for logging output. If not defined,
subprocess.PIPE
will be used. Defined using another value, the log level of the ffmpeg command will be “info”, otherwise “error”.threads (int, optional) – Number of threads used to write the output with ffmpeg.
ffmpeg_params (list, optional) – Additional parameters passed to ffmpeg command.