class_docstr: Implement FFmpeg wrapper for video compression defence based on H.264/MPEG-4 AVC.
  
  Video compression uses H.264 video encoding. The video quality is controlled with the constant rate factor
  parameter. More information on the constant rate factor: https://trac.ffmpeg.org/wiki/Encode/H.264.
docstr: Create an instance of VideoCompression.
  
  :param video_format: Specify one of supported video file extensions, e.g. `avi`, `mp4` or `mkv`.
  :param constant_rate_factor: Specify constant rate factor (range 0 to 51, where 0 is lossless).
  :param channels_first: Set channels first or last.
  :param apply_fit: True if applied during fitting/training.
  :param apply_predict: True if applied during predicting.
  :param device_type: Type of device on which the classifier is run, either `gpu` or `cpu`.
  :param verbose: Show progress bars.
code: def __init__(
      self,
      *,
      video_format: str,
      constant_rate_factor: int = 28,
      channels_first: bool = False,
      apply_fit: bool = False,
      apply_predict: bool = True,
      device_type: str = "gpu",
      verbose: bool = False,
  ):
      """
      Create an instance of VideoCompression.
  
      :param video_format: Specify one of supported video file extensions, e.g. `avi`, `mp4` or `mkv`.
      :param constant_rate_factor: Specify constant rate factor (range 0 to 51, where 0 is lossless).
      :param channels_first: Set channels first or last.
      :param apply_fit: True if applied during fitting/training.
      :param apply_predict: True if applied during predicting.
      :param device_type: Type of device on which the classifier is run, either `gpu` or `cpu`.
      :param verbose: Show progress bars.
      """
      from torch.autograd import Function
  
      super().__init__(
          device_type=device_type,
          is_fitted=True,
          apply_fit=apply_fit,
          apply_predict=apply_predict,
      )
      self.video_format = video_format
      self.constant_rate_factor = constant_rate_factor
      self.channels_first = channels_first
      self.verbose = verbose
      self._check_params()
  
      self.compression_numpy = VideoCompression(
          video_format=video_format,
          constant_rate_factor=constant_rate_factor,
          channels_first=channels_first,
          apply_fit=apply_fit,
          apply_predict=apply_predict,
          verbose=verbose,
      )
  
      class CompressionPyTorchNumpy(Function):  # pylint: disable=W0223
          """
          Function running Preprocessor.
          """
  
          @staticmethod
          def forward(ctx, input):  # pylint: disable=W0622,W0221
              numpy_input = input.detach().cpu().numpy()
              result, _ = self.compression_numpy(numpy_input)
              return input.new(result)
  
          @staticmethod
          def backward(ctx, grad_output):  # pylint: disable=W0221
              numpy_go = grad_output.cpu().numpy()
              result = self.compression_numpy.estimate_gradient(
                  None, numpy_go
              )
              return grad_output.new(result)
  
      self._compression_pytorch_numpy = CompressionPyTorchNumpy
  
file_path: adversarial-robustness-toolbox/art/defences/preprocessor/video_compression_pytorch.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, TYPE_CHECKING
  from art.defences.preprocessor.preprocessor import PreprocessorPyTorch
  from art.defences.preprocessor.video_compression import VideoCompression
label_desc: Use image node_id 1 to create a new VideoCompressionPyTorch object from inherited base classes: PreprocessorPyTorch with example: obj = VideoCompressionPyTorch()