def peri_test(address, colour_space, init_delay): factory = VideoSourceFactory.get_instance() global source source = factory.connect_network_source(address, colour_space) sleep(init_delay) assert source is not None global frame, frame_with_colour_mismatch, tmp_frame frame = VideoFrame(colour_space, False) # TODO the loop is due to issue #135 n_attempts = 0 n_max_attempts = 10 while not source.get_frame(frame): sleep(1) n_attempts += 1 if n_attempts >= n_max_attempts: break assert source.get_frame(frame) tmp_frame = VideoFrame(colour_space, False) if colour_space == ColourSpace.BGRA: mismatch_colour_space = ColourSpace.I420 else: mismatch_colour_space = ColourSpace.BGRA frame_with_colour_mismatch = VideoFrame(mismatch_colour_space, False) yield
def peri_test(colour_space): global frame frame = VideoFrame(colour_space, cols, rows) assert frame is not None global stereo_frame, stereo_count stereo_frame = VideoFrame(colour_space, cols, rows, stereo_count) assert stereo_frame is not None yield
def peri_test(codec, colour_space): # This section runs before each test global frame frame = VideoFrame(colour_space, 400, 640) global frame_with_colour_mismatch if colour_space == ColourSpace.BGRA: colour_space_with_mismatch = ColourSpace.I420 else: colour_space_with_mismatch = ColourSpace.BGRA frame_with_colour_mismatch = VideoFrame(colour_space_with_mismatch, 400, 640) global factory factory = VideoTargetFactory.get_instance() assert factory is not None global file_name file_name = '{}_{}-{}.{}'.format( tmp_file_prefix, strftime('%Y-%m-%d-%H-%M-%S'), ''.join(choice(ascii_uppercase) for _ in range(5)), __file_ext(codec) ) global target, frame_rate target = None target = factory.create_file_writer(codec, file_name, frame_rate) assert target is not None try: file_null = open(devnull, 'w') check_call(['ffprobe', '--help'], stdout=file_null, stderr=file_null) except BaseException: raise RuntimeError( 'FFmpeg does not appear to be installed on your system,\n' 'GiftGrab tests need FFmpeg.') # Run test yield # This section runs after each test global tmp_file_prefix for f in listdir('.'): if str(f).startswith(tmp_file_prefix): remove(f)
def peri_test(colour_space): # This section runs before each test factory = VideoSourceFactory.get_instance() global source try: source = factory.get_device(Device.DeckLinkSDI4K, colour_space) except IOError as e: raise RuntimeError( 'Could not connect to Blackmagic DeckLink SDI 4K,\n' + 'The detailed error was:\n' + e.message) assert source is not None global frame, frame_with_colour_mismatch frame = VideoFrame(colour_space, False) if colour_space == ColourSpace.BGRA: mismatch_colour_space = ColourSpace.UYVY else: mismatch_colour_space = ColourSpace.BGRA frame_with_colour_mismatch = VideoFrame(mismatch_colour_space, False) global height, width assert source.get_frame(frame) width = frame.cols() height = frame.rows() global sub_x, sub_y, sub_width, sub_height sub_width = width // 3 sub_height = height // 3 sub_x = width // 2 sub_y = height // 2 # health checks assert sub_x + sub_width < width assert sub_y + sub_height < height global sub2_x, sub2_y, sub2_width, sub2_height sub2_width = width // 5 sub2_height = height // 5 sub2_x = width // 6 sub2_y = height // 6 # health checks assert sub2_x + sub2_width < width assert sub2_y + sub2_height < height # Run test yield
def test_resolution(colour_space): rows = 1080 cols = 1920 frame1920x1080 = VideoFrame(colour_space, cols, rows) global target, file_name for i in range(10): target.append(frame1920x1080) del target assert inspection.resolution(file_name) == (cols, rows)
def test_stereo_frame_constructor(colour_space): cols, rows = 1920, 1080 frame = VideoFrame(colour_space, cols, rows) assert frame.stereo_count() == 1 for _stereo_count in range(2, 5): frame = VideoFrame(colour_space, cols, rows, _stereo_count) assert frame.stereo_count() == _stereo_count
def peri_test(colour_space): global frame frame = VideoFrame(colour_space, cols, rows) assert frame is not None yield
source = sfac.get_device(Device.DeckLink4KExtreme12G, ColourSpace.BGRA) elif video_input == 'dvi2pcie': filename, ext = 'dvi2pcie', '.mp4' # start acquirigin frames from an Epiphan DVI2PCIe Duo SDI port source = sfac.get_device(Device.DVI2PCIeDuo_SDI, ColourSpace.BGRA) else: filename = os.path.basename(video_input) filename, ext = os.path.splitext(filename) assert filename assert ext == '.mp4' # initialise reading of passed file source = sfac.create_file_reader(video_input, ColourSpace.BGRA) frame = VideoFrame(ColourSpace.BGRA, False) source.get_frame(frame) frame_shape = (frame.rows(), frame.cols(), 4) # prepare for creating encoders (writers) tfac = VideoTargetFactory.get_instance() frame_rate = source.get_frame_rate() # create a red and green Dyer red_dyer = Dyer(2, 128) green_dyer = Dyer(1, 64) # create the bufferer for the red and green Dyers np_buffer_red = np.zeros(frame_shape, np.uint8) bufferer_red = Bufferer(np_buffer_red) np_buffer_orig = np.zeros_like(np_buffer_red)
def peri_test(colour_space): global stereo_frame, stereo_count, data_length stereo_count = 2 cols, rows = 1920, 1080 stereo_frame = VideoFrame(colour_space, cols, rows, stereo_count) data_length = VideoFrame.required_data_length(colour_space, cols, rows)