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: An Internal function that launches FFmpeg subprocess and pipelines commands.
  
  Parameters:
      input_params (dict): Input FFmpeg parameters
      output_params (dict): Output FFmpeg parameters
docstr_tok: ["An","Internal","function","that","launches","FFmpeg","subprocess","and","pipelines","commands",".","Parameters",":","input_params","(","dict",")",":","Input","FFmpeg","parameters","output_params","(","dict",")",":","Output","FFmpeg","parameters"]
code: def __Build_n_Execute(self, input_params, output_params):
      """
      An Internal function that launches FFmpeg subprocess and pipelines commands.
  
      Parameters:
          input_params (dict): Input FFmpeg parameters
          output_params (dict): Output FFmpeg parameters
      """
      # handle audio source if present
      if "-core_asource" in output_params:
          output_params.move_to_end("-core_asource", last=False)
  
      # finally handle `-i`
      if "-i" in output_params:
          output_params.move_to_end("-i", last=False)
  
      # copy streams count
      stream_count = output_params.pop("stream_count", 1)
  
      # convert input parameters to list
      input_commands = dict2Args(input_params)
      # convert output parameters to list
      output_commands = dict2Args(output_params)
      # convert any additional parameters to list
      stream_commands = dict2Args(self.__params)
  
      # create exclusive HLS params
      hls_commands = []
      # handle HLS multi-variant streams
      if self.__format == "hls" and stream_count > 1:
          stream_map = ""
          for count in range(0, stream_count):
              stream_map += "v:{}{} ".format(
                  count,
                  ",a:{}".format(count)
                  if "-acodec" in output_params
                  else ",",
              )
          hls_commands += [
              "-master_pl_name",
              os.path.basename(self.__out_file),
              "-var_stream_map",
              stream_map.strip(),
              os.path.join(
                  os.path.dirname(self.__out_file), "stream_%v.m3u8"
              ),
          ]
  
      # log it if enabled
      if self.__logging:
          logger.debug(
              "User-Defined Output parameters: `{}`".format(
                  " ".join(output_commands) if output_commands else None
              )
          )
          logger.debug(
              "Additional parameters: `{}`".format(
                  " ".join(stream_commands) if stream_commands else None
              )
          )
      # build FFmpeg command from parameters
      ffmpeg_cmd = None
      hide_banner = (
          [] if self.__logging else ["-hide_banner"]
      )  # ensuring less cluterring if specified
      # format commands
      if self.__video_source:
          ffmpeg_cmd = (
              [self.__ffmpeg, "-y"]
              + (
                  ["-re"] if self.__livestreaming else []
              )  # pseudo live-streaming
              + hide_banner
              + ["-i", self.__video_source]
              + input_commands
              + output_commands
              + stream_commands
          )
      else:
          ffmpeg_cmd = (
              [self.__ffmpeg, "-y"]
              + hide_banner
              + ["-f", "rawvideo", "-vcodec", "rawvideo"]
              + input_commands
              + ["-i", "-"]
              + output_commands
              + stream_commands
          )
      # format outputs
      ffmpeg_cmd.extend(
          [self.__out_file] if not (hls_commands) else hls_commands
      )
      # Launch the FFmpeg pipeline with built command
      logger.critical(
          "Transcoding streaming chunks. Please wait..."
      )  # log it
      self.__process = sp.Popen(
          ffmpeg_cmd,
          stdin=sp.PIPE,
          stdout=sp.DEVNULL
          if (not self.__video_source and not self.__logging)
          else sp.PIPE,
          stderr=None if self.__logging else sp.STDOUT,
      )
      # post handle progress bar and runtime errors in case of video_source
      if self.__video_source:
          return_code = 0
          pbar = None
          sec_prev = 0
          if not self.__logging:
              # iterate until stdout runs out
              while True:
                  # read and process data
                  data = self.__process.stdout.readline()
                  if data:
                      data = data.decode("utf-8")
                      # extract duration and time-left
                      if pbar is None:
                          if "Duration:" in data:
                              sec_duration = extract_time(data)
                              # initate progress bar
                              pbar = tqdm(
                                  total=sec_duration,
                                  desc="Processing Frames",
                                  unit="frame",
                              )
                      else:
                          if "time=" in data:
                              sec_current = extract_time(data)
                              # update progress bar
                              if sec_current:
                                  pbar.update(sec_current - sec_prev)
                                  sec_prev = sec_current
                  else:
                      # poll if no data
                      if self.__process.poll() is not None:
                          break
              return_code = self.__process.poll()
          else:
              self.__process.communicate()
              return_code = self.__process.returncode
          # close progress bar
          if pbar:
              pbar.close()
          # handle return_code
          if return_code:
              # log and raise error if return_code is `1`
              logger.error(
                  "StreamGear failed to initiate stream for this video source!"
              )
              error = sp.CalledProcessError(return_code, ffmpeg_cmd)
              raise error
          else:
              # log if successful
              logger.critical(
                  "Transcoding Ended. {} Streaming assets are successfully generated at specified path.".format(
                      self.__format.upper()
                  )
              )
  
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 9 for calling the StreamGear obj's underlying member method code with example usage: obj.__Build_n_Execute(input_params, output_params) without return types