def test_record_to_file(camera, previewing, mode, filenames_format_options): filename1, filename2, format, options = filenames_format_options resolution, framerate = mode expected_failures(resolution, format, options) camera.start_recording( filename1, # Check that in the case of cooked formats, capture correctly # derives the format from the extension format=format if format in RAW_FORMATS else None, **options) try: camera.wait_recording(1) verify2 = (format != 'h264' or (options.get('inline_headers', True) and options.get('intra_period', 1))) if verify2: camera.split_recording(filename2) camera.wait_recording(1) else: with pytest.raises(picamera.PiCameraRuntimeError): camera.split_recording(filename2) finally: camera.stop_recording() if 'resize' in options: resolution = options['resize'] verify_video(filename1, format, resolution) if verify2: verify_video(filename2, format, resolution)
def test_record_to_stream(camera, previewing, mode, format_options): format, options = format_options resolution, framerate = mode expected_failures(resolution, format, options) stream1 = tempfile.SpooledTemporaryFile() stream2 = tempfile.SpooledTemporaryFile() camera.start_recording(stream1, format, **options) try: camera.wait_recording(1) verify2 = format != "h264" or (options.get("inline_headers", True) and options.get("intra_period", 1)) if verify2: camera.split_recording(stream2) camera.wait_recording(1) else: with pytest.raises(picamera.PiCameraRuntimeError): camera.split_recording(stream2) finally: camera.stop_recording() stream1.seek(0) if "resize" in options: resolution = options["resize"] verify_video(stream1, format, resolution) if verify2: stream2.seek(0) verify_video(stream2, format, resolution)
def test_circular_record(camera, mode): resolution, framerate = mode expected_failures(resolution, "h264", {}) stream = picamera.PiCameraCircularIO(camera, seconds=4) camera.start_recording(stream, format="h264") try: # Keep recording until the stream is definitely full and starts # removing earlier bits, or until 20 seconds start = time.time() while stream._length < stream._size and time.time() - start < 20: camera.wait_recording(1) # Record one more second, then test the result camera.wait_recording(1) finally: camera.stop_recording() temp = tempfile.SpooledTemporaryFile() for frame in stream.frames: if frame.header: stream.seek(frame.position) break while True: buf = stream.read1() if not buf: break temp.write(buf) temp.seek(0) verify_video(temp, "h264", resolution)
def test_record_to_stream(camera, previewing, resolution, format_options): format, options = format_options if resolution == (2592, 1944) and 'resize' not in options: pytest.xfail('Cannot encode video at max resolution') if resolution == (1920, 1080) and format == 'mjpeg': pytest.xfail('Locks up camera') stream1 = tempfile.SpooledTemporaryFile() stream2 = tempfile.SpooledTemporaryFile() camera.start_recording(stream1, format, **options) try: camera.wait_recording(1) verify2 = ( format != 'h264' or ( options.get('inline_headers', True) and options.get('bitrate', 1) ) ) if verify2: camera.split_recording(stream2) camera.wait_recording(1) else: with pytest.raises(picamera.PiCameraRuntimeError): camera.split_recording(stream2) finally: camera.stop_recording() stream1.seek(0) if 'resize' in options: resolution = options['resize'] verify_video(stream1, format, resolution) if verify2: stream2.seek(0) verify_video(stream2, format, resolution)
def test_record_to_stream(camera, previewing, mode, format_options): format, options = format_options resolution, framerate = mode expected_failures(resolution, format, options) stream1 = tempfile.SpooledTemporaryFile() stream2 = tempfile.SpooledTemporaryFile() camera.start_recording(stream1, format, **options) try: camera.wait_recording(1) verify2 = (format != 'h264' or (options.get('inline_headers', True) and options.get('intra_period', 1))) if verify2: camera.split_recording(stream2) camera.wait_recording(1) else: with pytest.raises(picamera.PiCameraRuntimeError): camera.split_recording(stream2) finally: camera.stop_recording() stream1.seek(0) if 'resize' in options: resolution = options['resize'] verify_video(stream1, format, resolution) if verify2: stream2.seek(0) verify_video(stream2, format, resolution)
def test_circular_record(camera, previewing, resolution): if resolution == (2592, 1944): pytest.xfail('Cannot encode video at max resolution') stream = picamera.PiCameraCircularIO(camera, seconds=4) camera.start_recording(stream, format='h264') try: # Keep recording until the stream is definitely full and starts # removing earlier bits, or until 20 seconds start = time.time() while stream._length < stream._size and time.time() - start < 20: camera.wait_recording(1) # Record one more second, then test the result camera.wait_recording(1) finally: camera.stop_recording() temp = tempfile.SpooledTemporaryFile() for frame in stream.frames: if frame.header: stream.seek(frame.position) break while True: buf = stream.read1() if not buf: break temp.write(buf) temp.seek(0) verify_video(temp, 'h264', resolution)
def test_record_to_file(camera, previewing, mode, filenames_format_options): filename1, filename2, format, options = filenames_format_options resolution, framerate = mode expected_failures(resolution, format, options) camera.start_recording( filename1, # Check that in the case of cooked formats, capture correctly # derives the format from the extension format=format if format in RAW_FORMATS else None, **options ) try: camera.wait_recording(1) verify2 = format != "h264" or (options.get("inline_headers", True) and options.get("intra_period", 1)) if verify2: camera.split_recording(filename2) camera.wait_recording(1) else: with pytest.raises(picamera.PiCameraRuntimeError): camera.split_recording(filename2) finally: camera.stop_recording() if "resize" in options: resolution = options["resize"] verify_video(filename1, format, resolution) if verify2: verify_video(filename2, format, resolution)
def test_record_to_file(camera, previewing, resolution, filenames_format_options): filename1, filename2, format, options = filenames_format_options if resolution == (2592, 1944) and 'resize' not in options: pytest.xfail('Cannot encode video at max resolution') if resolution == (1920, 1080) and format == 'mjpeg': pytest.xfail('Locks up camera') camera.start_recording(filename1, **options) try: camera.wait_recording(1) verify2 = ( format != 'h264' or ( options.get('inline_headers', True) and options.get('bitrate', 1) ) ) if verify2: camera.split_recording(filename2) camera.wait_recording(1) else: with pytest.raises(picamera.PiCameraRuntimeError): camera.split_recording(filename2) finally: camera.stop_recording() if 'resize' in options: resolution = options['resize'] verify_video(filename1, format, resolution) if verify2: verify_video(filename2, format, resolution)
def test_record_sequence_to_file(camera, mode, tempdir): resolution, framerate = mode expected_failures(resolution, "h264", {}) filenames = [os.path.join(tempdir, "clip%d.h264" % i) for i in range(3)] for filename in camera.record_sequence(filenames): camera.wait_recording(1) for filename in filenames: verify_video(filename, "h264", resolution)
def test_record_sequence_to_file(camera, mode, tempdir): resolution, framerate = mode expected_failures(resolution, 'h264', {}) filenames = [os.path.join(tempdir, 'clip%d.h264' % i) for i in range(3)] for filename in camera.record_sequence(filenames): camera.wait_recording(1) for filename in filenames: verify_video(filename, 'h264', resolution)
def test_record_sequence_to_stream(camera, mode): resolution, framerate = mode expected_failures(resolution, "h264", {}) streams = [tempfile.SpooledTemporaryFile() for i in range(3)] for stream in camera.record_sequence(streams): camera.wait_recording(1) for stream in streams: stream.seek(0) verify_video(stream, "h264", resolution)
def test_record_sequence_to_file(camera, previewing, mode, tmpdir): resolution, framerate = mode if resolution == (2592, 1944): pytest.xfail('Cannot encode video at max resolution') filenames = [os.path.join(str(tmpdir), 'clip%d.h264' % i) for i in range(3)] for filename in camera.record_sequence(filenames): camera.wait_recording(1) for filename in filenames: verify_video(filename, 'h264', resolution)
def test_record_sequence_to_stream(camera, mode): resolution, framerate = mode expected_failures(resolution, 'h264', {}) streams = [tempfile.SpooledTemporaryFile() for i in range(3)] for stream in camera.record_sequence(streams): camera.wait_recording(1) for stream in streams: stream.seek(0) verify_video(stream, 'h264', resolution)
def test_record_sequence_to_stream(camera, previewing, mode): resolution, framerate = mode if resolution == (2592, 1944): pytest.xfail('Cannot encode video at max resolution') streams = [tempfile.SpooledTemporaryFile() for i in range(3)] for stream in camera.record_sequence(streams): camera.wait_recording(1) for stream in streams: stream.seek(0) verify_video(stream, 'h264', resolution)
def test_split_and_capture(camera, mode): resolution, framerate = mode expected_failures(resolution, "h264", {}) v_stream1 = tempfile.SpooledTemporaryFile() v_stream2 = tempfile.SpooledTemporaryFile() c_stream1 = tempfile.SpooledTemporaryFile() camera.start_recording(v_stream1, format="h264") try: camera.wait_recording(1) camera.capture(c_stream1, format="jpeg", use_video_port=True) camera.split_recording(v_stream2) camera.wait_recording(1) finally: camera.stop_recording() v_stream1.seek(0) v_stream2.seek(0) c_stream1.seek(0) verify_image(c_stream1, "jpeg", resolution) verify_video(v_stream1, "h264", resolution) verify_video(v_stream2, "h264", resolution)
def test_split_and_capture(camera, previewing, resolution): if resolution == (2592, 1944): pytest.xfail('Cannot encode video at max resolution') v_stream1 = tempfile.SpooledTemporaryFile() v_stream2 = tempfile.SpooledTemporaryFile() c_stream1 = tempfile.SpooledTemporaryFile() camera.start_recording(v_stream1, format='h264') try: camera.wait_recording(1) camera.capture(c_stream1, format='jpeg', use_video_port=True) camera.split_recording(v_stream2) camera.wait_recording(1) finally: camera.stop_recording() v_stream1.seek(0) v_stream2.seek(0) c_stream1.seek(0) verify_image(c_stream1, 'jpeg', resolution) verify_video(v_stream1, 'h264', resolution) verify_video(v_stream2, 'h264', resolution)
def test_split_and_capture(camera, mode): resolution, framerate = mode expected_failures(resolution, 'h264', {}) v_stream1 = tempfile.SpooledTemporaryFile() v_stream2 = tempfile.SpooledTemporaryFile() c_stream1 = tempfile.SpooledTemporaryFile() camera.start_recording(v_stream1, format='h264') try: camera.wait_recording(1) camera.capture(c_stream1, format='jpeg', use_video_port=True) camera.split_recording(v_stream2) camera.wait_recording(1) finally: camera.stop_recording() v_stream1.seek(0) v_stream2.seek(0) c_stream1.seek(0) verify_image(c_stream1, 'jpeg', resolution) verify_video(v_stream1, 'h264', resolution) verify_video(v_stream2, 'h264', resolution)
def test_multi_res_record(camera, previewing, mode): resolution, framerate = mode if resolution == (2592, 1944): pytest.xfail('Cannot encode video at max resolution') v_stream1 = tempfile.SpooledTemporaryFile() v_stream2 = tempfile.SpooledTemporaryFile() new_res = (resolution[0] // 2, resolution[1] // 2) camera.start_recording(v_stream1, format='h264') try: camera.start_recording(v_stream2, format='h264', resize=new_res, splitter_port=2) try: camera.wait_recording(1) camera.wait_recording(1, splitter_port=2) finally: camera.stop_recording(splitter_port=2) finally: camera.stop_recording() v_stream1.seek(0) v_stream2.seek(0) verify_video(v_stream1, 'h264', resolution) verify_video(v_stream2, 'h264', new_res)
def test_multi_res_record(camera, mode): resolution, framerate = mode expected_failures(resolution, 'h264', {}) v_stream1 = tempfile.SpooledTemporaryFile() v_stream2 = tempfile.SpooledTemporaryFile() new_res = (resolution[0] // 2, resolution[1] // 2) camera.start_recording(v_stream1, format='h264') try: camera.start_recording(v_stream2, format='h264', resize=new_res, splitter_port=2) try: camera.wait_recording(1) camera.wait_recording(1, splitter_port=2) finally: camera.stop_recording() finally: # Deliberately stop out of order to test #105 camera.stop_recording(splitter_port=2) v_stream1.seek(0) v_stream2.seek(0) verify_video(v_stream1, 'h264', resolution) verify_video(v_stream2, 'h264', new_res)
def test_multi_res_record(camera, mode): resolution, framerate = mode expected_failures(resolution, "h264", {}) v_stream1 = tempfile.SpooledTemporaryFile() v_stream2 = tempfile.SpooledTemporaryFile() new_res = (resolution[0] // 2, resolution[1] // 2) camera.start_recording(v_stream1, format="h264") try: camera.start_recording(v_stream2, format="h264", resize=new_res, splitter_port=2) try: camera.wait_recording(1) camera.wait_recording(1, splitter_port=2) finally: camera.stop_recording() finally: # Deliberately stop out of order to test #105 camera.stop_recording(splitter_port=2) v_stream1.seek(0) v_stream2.seek(0) verify_video(v_stream1, "h264", resolution) verify_video(v_stream2, "h264", new_res)