class_docstr: StreamGear automates transcoding workflow for generating Ultra-Low Latency, High-Quality, Dynamic & Adaptive Streaming Formats (such as MPEG-DASH and HLS) in just few lines of python code.
  StreamGear provides a standalone, highly extensible, and flexible wrapper around FFmpeg multimedia framework for generating chunked-encoded media segments of the content.
  
  SteamGear easily transcodes source videos/audio files & real-time video-frames and breaks them into a sequence of multiple smaller chunks/segments of suitable length. These segments make it
  possible to stream videos at different quality levels (different bitrates or spatial resolutions) and can be switched in the middle of a video from one quality level to another – if bandwidth
  permits – on a per-segment basis. A user can serve these segments on a web server that makes it easier to download them through HTTP standard-compliant GET requests.
  
  SteamGear also creates a Manifest/Playlist file (such as MPD in-case of DASH and M3U8 in-case of HLS) besides segments that describe these segment information (timing, URL, media characteristics like video resolution and bit rates)
   and is provided to the client before the streaming session.
  
  SteamGear currently supports MPEG-DASH (Dynamic Adaptive Streaming over HTTP, ISO/IEC 23009-1) and Apple HLS (HTTP live streaming).
docstr: Internal method that pre-processes default FFmpeg parameters before beginning pipelining.
  
  Parameters:
      channels (int): Number of channels
      rgb_mode (boolean): activates RGB mode _(if enabled)_.
docstr_tok: ["Internal","method","that","pre-processes","default","FFmpeg","parameters","before","beginning","pipelining",".","Parameters",":","channels","(","int",")",":","Number","of","channels","rgb_mode","(","boolean",")",":","activates","RGB","mode","_","(","if","enabled",")","_","."]
code: def __PreProcess(self, channels=0, rgb=False):
      """
      Internal method that pre-processes default FFmpeg parameters before beginning pipelining.
  
      Parameters:
          channels (int): Number of channels
          rgb_mode (boolean): activates RGB mode _(if enabled)_.
      """
      # turn off initiate flag
      self.__initiate_stream = False
      # initialize parameters
      input_parameters = OrderedDict()
      output_parameters = OrderedDict()
      # pre-assign default codec parameters (if not assigned by user).
      default_codec = "libx264rgb" if rgb else "libx264"
      output_parameters["-vcodec"] = self.__params.pop(
          "-vcodec", default_codec
      )
      # enable optimizations and enforce compatibility
      output_parameters["-vf"] = self.__params.pop(
          "-vf", "format=yuv420p"
      )
      aspect_ratio = Fraction(
          self.__inputwidth / self.__inputheight
      ).limit_denominator(10)
      output_parameters["-aspect"] = ":".join(
          str(aspect_ratio).split("/")
      )
      # w.r.t selected codec
      if output_parameters["-vcodec"] in [
          "libx264",
          "libx264rgb",
          "libx265",
          "libvpx-vp9",
      ]:
          output_parameters["-crf"] = self.__params.pop("-crf", "20")
      if output_parameters["-vcodec"] in ["libx264", "libx264rgb"]:
          if not (self.__video_source):
              output_parameters["-profile:v"] = self.__params.pop(
                  "-profile:v", "high"
              )
          output_parameters["-tune"] = self.__params.pop(
              "-tune", "zerolatency"
          )
          output_parameters["-preset"] = self.__params.pop(
              "-preset", "veryfast"
          )
      if output_parameters["-vcodec"] == "libx265":
          output_parameters["-x265-params"] = self.__params.pop(
              "-x265-params", "lossless=1"
          )
      # enable audio (if present)
      if self.__audio:
          # validate audio source
          bitrate = validate_audio(self.__ffmpeg, source=self.__audio)
          if bitrate:
              logger.info(
                  "Detected External Audio Source is valid, and will be used for streams."
              )
  
              # assign audio source
              output_parameters[
                  "{}".format(
                      "-core_asource"
                      if isinstance(self.__audio, list)
                      else "-i"
                  )
              ] = self.__audio
  
              # assign audio codec
              output_parameters["-acodec"] = self.__params.pop(
                  "-acodec",
                  "aac" if isinstance(self.__audio, list) else "copy",
              )
              output_parameters[
                  "a_bitrate"
              ] = bitrate  # temporary handler
              output_parameters["-core_audio"] = (
                  ["-map", "1:a:0"] if self.__format == "dash" else []
              )
          else:
              logger.warning(
                  "Audio source `{}` is not valid, Skipped!".format(
                      self.__audio
                  )
              )
      elif self.__video_source:
          # validate audio source
          bitrate = validate_audio(
              self.__ffmpeg, source=self.__video_source
          )
          if bitrate:
              logger.info("Source Audio will be used for streams.")
              # assign audio codec
              output_parameters["-acodec"] = (
                  "aac" if self.__format == "hls" else "copy"
              )
              output_parameters[
                  "a_bitrate"
              ] = bitrate  # temporary handler
          else:
              logger.warning(
                  "No valid audio_source available. Disabling audio for streams!"
              )
      else:
          logger.warning(
              "No valid audio_source provided. Disabling audio for streams!"
          )
      # enable audio optimizations based on audio codec
      if (
          "-acodec" in output_parameters
          and output_parameters["-acodec"] == "aac"
      ):
          output_parameters["-movflags"] = "+faststart"
  
      # set input framerate
      if self.__sourceframerate > 0 and not (self.__video_source):
          # set input framerate
          self.__logging and logger.debug(
              "Setting Input framerate: {}".format(
                  self.__sourceframerate
              )
          )
          input_parameters["-framerate"] = str(self.__sourceframerate)
  
      # handle input resolution and pixel format
      if not (self.__video_source):
          dimensions = "{}x{}".format(
              self.__inputwidth, self.__inputheight
          )
          input_parameters["-video_size"] = str(dimensions)
          # handles pix_fmt based on channels(HACK)
          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 ValueError(
                  "[StreamGear:ERROR] :: Frames with channels outside range 1-to-4 are not supported!"
              )
      # process assigned format parameters
      process_params = self.__handle_streams(
          input_params=input_parameters, output_params=output_parameters
      )
      # check if processing completed successfully
      assert not (
          process_params is None
      ), "[StreamGear:ERROR] :: {} stream cannot be initiated!".format(
          self.__format.upper()
      )
      # Finally start FFmpef pipline and process everything
      self.__Build_n_Execute(process_params[0], process_params[1])
  
imports: import os
  import time
  import math
  import platform
  import pathlib
  import difflib
  import logging
  import subprocess
  from tqdm import tqdm
  from fractions import Fraction
  from collections import OrderedDict
  from .helper import capPropId, dict2Args, delete_ext_safe, extract_time, is_valid_url, logger_handler, validate_audio, validate_video, check_WriteAccess, get_video_bitrate, get_valid_ffmpeg_path, logcurr_vidgear_ver
label_desc: Use image node_id 4 for calling the StreamGear obj's underlying member method code with example usage: obj.__PreProcess(channels, rgb) without return types