-
-
Notifications
You must be signed in to change notification settings - Fork 255
WriteGear
WriteGear is undoubtedly the most powerful Video Processing Gear of them all. It solely handles various powerful FFmpeg tools that allow us to do almost anything you can imagine with multimedia files. With WriteGear API, you can process real-time video frames into a lossless format and specification suitable for our playback in just a few lines of codes. These specifications include setting bitrate, codec, framerate, resolution, subtitles, compression, etc. Furthermore, we can multiplex extracted audio at the output with compression and all that in real-time(see this example). In addition to this, WriteGear also provides flexible access to OpenCV's VideoWriter API which provide some basic tools for video frames encoding but without compression.
WriteGear primarily operates in the following two modes:
-
Compression Mode: In this mode, WriteGear utilizes
FFmpeg's
inbuilt encoders to encode lossless multimedia files. It provides us the ability to exploit almost any available parameters available within FFmpeg, with so much ease and flexibility and while doing that it robustly handles all errors/warnings quietly. You can find more about this mode here. -
Non-Compression Mode: In this mode, WriteGear utilizes basic OpenCV's inbuilt VideoWriter API. Similar to compression mode, WriteGear also supports all parameters manipulation available within OpenCV's VideoWriter API. But this mode lacks the ability to manipulate encoding parameters and other important features like video compression, audio encoding, etc. You can learn about this mode here.
-
DO NOT feed frames to WriteGear with different dimensions or channels!, otherwise WriteGear will exit with
ValueError
. -
In case WriteGear API fails to detect valid FFmpeg executables on your system(even if Compression Mode is enabled), it will automatically fallbacks to Non-Compression Mode.
-
Follow this WIKI Page for FFmpeg installation.
You can import WriteGear as follows:
from vidgear.gears import WriteGear
-
write(self, frame, rgb_mode = False)
: pipelines ndarray frames to valid Video File.-
rgb_mode
: set this flag to enable RGB Mode - specifies that incoming frames are of RGB format(instead of default BGR). Its default value isFalse
. This flag only works in Compression Mode.
-
-
close(self)
: It safely Terminates the Write process. Therefore it is compulsory to call this function at the end of the main function.
⚠️ Precaution: Heavy resolution multimedia files take time to render which can last up to ~.1-to-3 secs, Kindly wait till the function exit itself and DO NOT try to kill the process instead.
See here for details and complete example
See here for details and complete example
1. output_filename(string): sets the output Video filename. Its Valid Inputs are:
-
path: Valid path of the directory to save the output video file. In this case, the
WriteGear
API will automatically assign a unique filename (with a default extension i.e..mp4
). -
filename(with/without path): Valid filename(with valid extension) of the output video file.
⏹️ Note: Make sure to provide valid filename with valid file-extension based on the encoder(in case of FFmpeg) & FOURCC(in case of OpenCV) whichever being currently in use.
2. compression_mode(boolean): enables/disables Video Compression Mode. If enabled(compression=True
) WriteGear API will utilize the FFmpeg executables to encode output video and if disabled(compression=False
) OpenCV's VideoWriter API will be used. Its default value is True
.
3. custom_ffmpeg(string): if specified, it specify the custom path/directory where the custom FFmpeg executables are located and works only in Compression Mode.
⏹️ Note: It is compulsory to provide custom binaries on a Windows Machine, otherwise this WriteGear with automatically download and extract suitable Static FFmpeg binaries to Temporary directory.
4. **output_params
(dict): This parameter provides the flexibility to manipulate almost all parameters/properties which are supported by FFmpeg(in Compression Mode) or OpenCV's VideoWriter(in Non-Compression Mode) whichever being accessed. In addition to these parameters, other special parameters to manipulate WriteGear API's internal properties are also supported.
👁️🗨️ All supported parameters details and their usage is depicted in the following links:
5. logging(boolean): set this flag to enable/disable
error logging essential for debugging. Its default value is False
.