class_docstr: WriteGear handles various powerful Video-Writer Tools that provide us the freedom to do almost anything imaginable with multimedia data.
  
  WriteGear API provides a complete, flexible, and robust wrapper around FFmpeg, a leading multimedia framework. WriteGear can process real-time frames into a lossless
  compressed video-file with any suitable specification (such as bitrate, codec, framerate, resolution, subtitles, etc.). It is powerful enough to perform complex tasks such as
  Live-Streaming (such as for Twitch) and Multiplexing Video-Audio with real-time frames in way fewer lines of code.
  
  Best of all, WriteGear grants users the complete freedom to play with any FFmpeg parameter with its exclusive Custom Commands function without relying on any
  third-party API.
  
  In addition to this, WriteGear also provides flexible access to OpenCV's VideoWriter API tools for video-frames encoding without compression.
  
  ??? tip "Modes of Operation"
  
      WriteGear primarily operates in following modes:
  
      * **Compression Mode**: In this mode, WriteGear utilizes powerful **FFmpeg** inbuilt encoders to encode lossless multimedia files.
                              This mode provides us the ability to exploit almost any parameter available within FFmpeg, effortlessly and flexibly,
                              and while doing that it robustly handles all errors/warnings quietly.
  
      * **Non-Compression Mode**: In this mode, WriteGear utilizes basic **OpenCV's inbuilt VideoWriter API** tools. This mode also supports all
                                  parameters manipulation available within VideoWriter API, but it lacks the ability to manipulate encoding parameters
                                  and other important features like video compression, audio encoding, etc.
class_docstr_tok: ["WriteGear","handles","various","powerful","Video-Writer","Tools","that","provide","us","the","freedom","to","do","almost","anything","imaginable","with","multimedia","data",".","WriteGear","API","provides","a","complete",",","flexible",",","and","robust","wrapper","around","FFmpeg",",","a","leading","multimedia","framework",".","WriteGear","can","process","real-time","frames","into","a","lossless","compressed","video-file","with","any","suitable","specification","(","such","as","bitrate",",","codec",",","framerate",",","resolution",",","subtitles",",","etc.",")",".","It","is","powerful","enough","to","perform","complex","tasks","such","as","Live-Streaming","(","such","as","for","Twitch",")","and","Multiplexing","Video-Audio","with","real-time","frames","in","way","fewer","lines","of","code",".","Best","of","all",",","WriteGear","grants","users","the","complete","freedom","to","play","with","any","FFmpeg","parameter","with","its","exclusive","Custom","Commands","function","without","relying","on","any","third-party","API",".","In","addition","to","this",",","WriteGear","also","provides","flexible","access","to","OpenCV","'s","VideoWriter","API","tools","for","video-frames","encoding","without","compression",".","?","?","?","tip","``","Modes","of","Operation","''","WriteGear","primarily","operates","in","following","modes",":","*","*","*","Compression","Mode","*","*",":","In","this","mode",",","WriteGear","utilizes","powerful","*","*","FFmpeg","*","*","inbuilt","encoders","to","encode","lossless","multimedia","files",".","This","mode","provides","us","the","ability","to","exploit","almost","any","parameter","available","within","FFmpeg",",","effortlessly","and","flexibly",",","and","while","doing","that","it","robustly","handles","all","errors\/warnings","quietly",".","*","*","*","Non-Compression","Mode","*","*",":","In","this","mode",",","WriteGear","utilizes","basic","*","*","OpenCV","'s","inbuilt","VideoWriter","API","*","*","tools",".","This","mode","also","supports","all","parameters","manipulation","available","within","VideoWriter","API",",","but","it","lacks","the","ability","to","manipulate","encoding","parameters","and","other","important","features","like","video","compression",",","audio","encoding",",","etc","."]
docstr: Internal method that pre-processes FFmpeg Parameters before beginning to pipeline frames.
  
  Parameters:
      channels (int): Number of channels in input frame.
      dtype (str): Datatype of input frame.
      rgb_mode (boolean): Whether to activate `RGB mode`?
docstr_tok: ["Internal","method","that","pre-processes","FFmpeg","Parameters","before","beginning","to","pipeline","frames",".","Parameters",":","channels","(","int",")",":","Number","of","channels","in","input","frame",".","dtype","(","str",")",":","Datatype","of","input","frame",".","rgb_mode","(","boolean",")",":","Whether","to","activate","`","RGB","mode","`","?"]
code: def __PreprocessFFParams(self, channels, dtype=None, rgb=False):
      """
      Internal method that pre-processes FFmpeg Parameters before beginning to pipeline frames.
  
      Parameters:
          channels (int): Number of channels in input frame.
          dtype (str): Datatype of input frame.
          rgb_mode (boolean): Whether to activate `RGB mode`?
      """
      # turn off initiate flag
      self.__initiate_process = False
      # initialize input parameters
      input_parameters = {}
  
      # handle output frames dimensions
      dimensions = ""
      if (
          self.__output_dimensions is None
      ):  # check if dimensions are given
          dimensions += "{}x{}".format(
              self.__inputwidth, self.__inputheight
          )  # auto derive from frame
      else:
          dimensions += "{}x{}".format(
              self.__output_dimensions[0], self.__output_dimensions[1]
          )  # apply if defined
      input_parameters["-s"] = str(dimensions)
  
      # handles user-defined and auto-assigned input pixel-formats
      if not (
          self.__inputpixfmt is None
      ) and self.__inputpixfmt in get_supported_pixfmts(self.__ffmpeg):
          # assign directly if valid
          input_parameters["-pix_fmt"] = self.__inputpixfmt
      else:
          # handles pix_fmt based on channels and dtype(HACK)
          if dtype.kind == "u" and dtype.itemsize == 2:
              # handle pix_fmt for frames with higher than 8-bit depth
              pix_fmt = None
              if channels == 1:
                  pix_fmt = "gray16"
              elif channels == 2:
                  pix_fmt = "ya16"
              elif channels == 3:
                  pix_fmt = "rgb48" if rgb else "bgr48"
              elif channels == 4:
                  pix_fmt = "rgba64" if rgb else "bgra64"
              else:
                  # raise error otherwise
                  raise ValueError(
                      "[WriteGear:ERROR] :: Frames with channels outside range 1-to-4 are not supported!"
                  )
              # Add endianness suffix (w.r.t byte-order)
              input_parameters["-pix_fmt"] = pix_fmt + (
                  "be" if dtype.byteorder == ">" else "le"
              )
          else:
              # handle pix_fmt for frames with exactly 8-bit depth(`uint8`)
              if channels == 1:
                  input_parameters["-pix_fmt"] = "gray"
              elif channels == 2:
                  input_parameters["-pix_fmt"] = "ya8"
              elif channels == 3:
                  input_parameters["-pix_fmt"] = (
                      "rgb24" if rgb else "bgr24"
                  )
              elif channels == 4:
                  input_parameters["-pix_fmt"] = (
                      "rgba" if rgb else "bgra"
                  )
              else:
                  # raise error otherwise
                  raise ValueError(
                      "[WriteGear:ERROR] :: Frames with channels outside range 1-to-4 are not supported!"
                  )
  
      # handles user-defined output video framerate
      if self.__inputframerate > 0.0:
          # assign input framerate if valid
          self.__logging and logger.debug(
              "Setting Input framerate: {}".format(
                  self.__inputframerate
              )
          )
          input_parameters["-framerate"] = str(self.__inputframerate)
  
      # initiate FFmpeg process
      self.__start_FFProcess(
          input_params=input_parameters,
          output_params=self.__output_parameters,
      )
  
file_path: vidgear/vidgear/gears/writegear.py
imports: import os
  import cv2
  import time
  import platform
  import pathlib
  import logging
  import subprocess
  from .helper import capPropId, dict2Args, is_valid_url, logger_handler, check_WriteAccess, get_valid_ffmpeg_path, get_supported_pixfmts, get_supported_vencoders, check_gstreamer_support, logcurr_vidgear_ver
label_desc: Use image node_id 3 for calling the WriteGear obj's underlying member method code with example usage: obj.__PreprocessFFParams(channels, dtype, rgb) without return types