# Path: video_processing/stream_processor.py
# class Frame(collections.namedtuple('FrameSet', ['index', 'data'])):
# class StreamSet(collections.namedtuple('StreamSet', ['frame_rate_hz',
#                                                      'stream_headers'])):
# class ProcessorBase(object):
#   def __new__(cls, index=0, data=None):
#   def __new__(cls, frame_rate_hz=-1):
#   def __init__(self, configuration):
#   def open(self, stream_set):
#   def process(self, frame_set):
#   def close(self):


import numpy
import cv2
from video_processing import stream_processor




class OpenCVVideoDecoderProcessor(stream_processor.ProcessorBase):
  """Processor for decoding video using OpenCV."""

  def __init__(self, configuration):
    self._input_video_file = configuration.get('input_video_file', '')
    self._video_stream_name = configuration.get('video_stream_name', 'video')
    self._index = 0

  def open(self, stream_set):
    self._capture = cv2.VideoCapture(self._input_video_file)
    frame_rate_hz = self._capture.get(cv2.CAP_PROP_FPS)
    if stream_set.frame_rate_hz < 0:
      # If the frame rate wasn't set, then we can assume that we're the top
      # of the processing chain and create a new stream set object to
      # contain the video stream.
      stream_set = stream_processor.StreamSet(frame_rate_hz=frame_rate_hz)
    else:
      if stream_set.frame_rate_hz != frame_rate_hz:
        raise Exception('Frame rate in additional video stream is not equal to '
                        'that of the original stream set.')
    image_width = int(self._capture.get(cv2.CAP_PROP_FRAME_WIDTH))
    image_height = int(self._capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
    num_frames = int(self._capture.get(cv2.CAP_PROP_FRAME_COUNT))
    stream_set.stream_headers[
        self._video_stream_name] = stream_processor.StreamHeader(
            frame_data_type=numpy.ndarray,

# Path: video_processing/stream_processor.py
# class Frame(collections.namedtuple('FrameSet', ['index', 'data'])):
# class StreamSet(collections.namedtuple('StreamSet', ['frame_rate_hz',
#                                                      'stream_headers'])):
# class ProcessorBase(object):
#   def __new__(cls, index=0, data=None):
#   def __new__(cls, frame_rate_hz=-1):
#   def __init__(self, configuration):
#   def open(self, stream_set):
#   def process(self, frame_set):
#   def close(self):


# Path: video_processing/processors/opencv_video_decoder.py
import numpy
import cv2
from video_processing import stream_processor





class OpenCVVideoDecoderProcessor(stream_processor.ProcessorBase):
  """Processor for decoding video using OpenCV."""

  def __init__(self, configuration):
    self._input_video_file = configuration.get('input_video_file', '')
    self._video_stream_name = configuration.get('video_stream_name', 'video')
    self._index = 0

  def open(self, stream_set):
    self._capture = cv2.VideoCapture(self._input_video_file)
    frame_rate_hz = self._capture.get(cv2.CAP_PROP_FPS)
    if stream_set.frame_rate_hz < 0:
      # If the frame rate wasn't set, then we can assume that we're the top
      # of the processing chain and create a new stream set object to
      # contain the video stream.
      stream_set = stream_processor.StreamSet(frame_rate_hz=frame_rate_hz)
    else:
      if stream_set.frame_rate_hz != frame_rate_hz:
        raise Exception('Frame rate in additional video stream is not equal to '
                        'that of the original stream set.')
    image_width = int(self._capture.get(cv2.CAP_PROP_FRAME_WIDTH))
    image_height = int(self._capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
    num_frames = int(self._capture.get(cv2.CAP_PROP_FRAME_COUNT))
    stream_set.stream_headers[
        self._video_stream_name] = stream_processor.StreamHeader(
            frame_data_type=numpy.ndarray,

            header_data=stream_processor.VideoStreamHeader(