Generator process to read file

def file_reader(self):
        """Generator process to read file"""
        self.update_config()
        path = self.config['path']
        # open file to get dimensions
        with self.subprocess(
                ['ffmpeg', '-v', 'info', '-y', '-an', '-vn', '-i', path, '-'],
                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                stdin=open(os.devnull), universal_newlines=True) as sp:
            for line in sp.stderr.read().splitlines():
                match = re.search('(\d{2,})x(\d{2,})', line)
                if match:
                    xlen, ylen = map(int, match.groups())
                    break
            else:
                self.logger.critical('Failed to open %s', path)
                return
        # read file repeatedly to allow looping
        while True:
            # can change config once per outer loop
            self.update_config()
            bit16 = self.config['16bit']
            self.frame_type = self.config['type']
            self.metadata = Metadata().from_file(path)
            audit = self.metadata.get('audit')
            audit += 'data = %s\n' % path
            audit += '    type: %s, 16bit: %s\n' % (self.frame_type, bit16)
            self.metadata.set('audit', audit)
            bps = {'RGB': 3, 'Y': 1}[self.frame_type]
            pix_fmt = {'RGB': ('rgb24', 'rgb48le'),
                       'Y':   ('gray', 'gray16le')}[self.frame_type][bit16]
            bytes_per_line = xlen * ylen * bps
            if bit16:
                bytes_per_line *= 2
            # open file to read data
            with self.subprocess(
                    ['ffmpeg', '-v', 'warning', '-an', '-i', path,
                     '-f', 'image2pipe', '-pix_fmt', pix_fmt,
                     '-c:v', 'rawvideo', '-'],
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                    stdin=open(os.devnull), bufsize=bytes_per_line) as sp:
                while True:
                    try:
                        raw_data = sp.stdout.read(bytes_per_line)
                    except Exception as ex:
                        self.logger.exception(ex)
                        return
                    if len(raw_data) < bytes_per_line:
                        break
                    if bit16:
                        image = numpy.fromstring(raw_data, dtype=numpy.uint16)
                        image = image.astype(pt_float) / pt_float(256.0)
                    else:
                        image = numpy.fromstring(raw_data, dtype=numpy.uint8)
                    yield image.reshape((ylen, xlen, bps))
            self.update_config()
            if self.frame_no == 0 or self.config['looping'] == 'off':
                return