def test_input_framerate_rtf():
    """
    Testing "-input_framerate" parameter provided by StreamGear
    """
    try:
        mpd_file_path = os.path.join(return_mpd_path(), "dash_test.mpd")
        stream = cv2.VideoCapture(return_testvideo_path())  # Open stream
        test_framerate = stream.get(cv2.CAP_PROP_FPS)
        stream_params = {
            "-clear_prev_assets": True,
            "-input_framerate": test_framerate,
        }
        streamer = StreamGear(output=mpd_file_path, logging=True, **stream_params)
        while True:
            (grabbed, frame) = stream.read()
            if not grabbed:
                break
            streamer.stream(frame)
        stream.release()
        streamer.terminate()
        meta_data = extract_meta_mpd(mpd_file_path)
        assert meta_data and len(meta_data) > 0, "Test Failed!"
        framerate_mpd = string_to_float(meta_data[0]["framerate"])
        assert framerate_mpd > 0.0 and isinstance(framerate_mpd, float), "Test Failed!"
        assert round(framerate_mpd) == round(test_framerate), "Test Failed!"
    except Exception as e:
        pytest.fail(str(e))
Beispiel #2
0
def test_fail_framedimension():
    """
    IO Test - made to fail with multiple frame dimension
    """
    np.random.seed(0)
    # generate random data for 10 frames
    random_data1 = np.random.random(size=(480, 640, 3)) * 255
    input_data1 = random_data1.astype(np.uint8)

    np.random.seed(0)
    random_data2 = np.random.random(size=(580, 640, 3)) * 255
    input_data2 = random_data2.astype(np.uint8)

    streamer = None
    try:
        streamer = StreamGear(output="output.mpd")
        streamer.stream(None)
        streamer.stream(input_data1)
        streamer.stream(input_data2)
    except Exception as e:
        if isinstance(e, ValueError):
            pytest.xfail("Test Passed!")
        else:
            pytest.fail(str(e))
    finally:
        if not streamer is None:
            streamer.terminate()
Beispiel #3
0
def test_rtf_stream(conversion):
    """
    Testing Real-Time Frames Mode
    """
    mpd_file_path = return_mpd_path()
    try:
        # Open stream
        stream = CamGear(source=return_testvideo_path(),
                         colorspace=conversion).start()
        stream_params = {
            "-clear_prev_assets": True,
            "-input_framerate": "invalid",
        }
        streamer = StreamGear(output=mpd_file_path, **stream_params)
        while True:
            frame = stream.read()
            # check if frame is None
            if frame is None:
                break
            if conversion == "COLOR_BGR2RGBA":
                streamer.stream(frame, rgb_mode=True)
            else:
                streamer.stream(frame)
        stream.stop()
        streamer.terminate()
        mpd_file = [
            os.path.join(mpd_file_path, f) for f in os.listdir(mpd_file_path)
            if f.endswith(".mpd")
        ]
        assert len(mpd_file) == 1, "Failed to create MPD file!"
        assert check_valid_mpd(mpd_file[0])
    except Exception as e:
        pytest.fail(str(e))
Beispiel #4
0
def test_params(stream_params, format):
    """
    Testing "-stream_params" parameters by StreamGear
    """
    try:
        assets_file_path = os.path.join(
            return_assets_path(False if format == "dash" else True),
            "format_test{}".format(".mpd" if format == "dash" else ".m3u8"),
        )
        if format == "hls":
            stream_params.update(
                {
                    "-hls_base_url": return_assets_path(
                        False if format == "dash" else True
                    )
                    + os.sep
                }
            )
        stream = cv2.VideoCapture(return_testvideo_path())  # Open stream
        streamer = StreamGear(
            output=assets_file_path, format=format, logging=True, **stream_params
        )
        while True:
            (grabbed, frame) = stream.read()
            if not grabbed:
                break
            streamer.stream(frame)
        stream.release()
        streamer.terminate()
        if format == "dash":
            assert check_valid_mpd(assets_file_path), "Test Failed!"
        else:
            assert extract_meta_video(assets_file_path), "Test Failed!"
    except Exception as e:
        pytest.fail(str(e))
Beispiel #5
0
def test_rtf_livestream(format):
    """
    Testing Real-Time Frames Mode with livestream.
    """
    assets_file_path = return_assets_path(False if format == "dash" else True)

    try:
        # Open stream
        options = {"THREAD_TIMEOUT": 300}
        stream = CamGear(source=return_testvideo_path(), **options).start()
        stream_params = {
            "-livestream": True,
        }
        streamer = StreamGear(output=assets_file_path, format=format, **stream_params)
        while True:
            frame = stream.read()
            # check if frame is None
            if frame is None:
                break
            streamer.stream(frame)
        stream.stop()
        streamer.terminate()
    except Exception as e:
        if not isinstance(e, queue.Empty):
            pytest.fail(str(e))
Beispiel #6
0
def test_method_call_ss():
    """
    Method calling Test - Made to fail by calling method in the wrong context.
    """
    stream_params = {"-video_source": return_testvideo_path()}
    streamer = StreamGear(output="output.mpd", logging=True, **stream_params)
    streamer.stream("garbage.garbage")
    streamer.terminate()
Beispiel #7
0
def test_input_framerate_rtf(format):
    """
    Testing "-input_framerate" parameter provided by StreamGear
    """
    try:
        assets_file_path = os.path.join(
            return_assets_path(False if format == "dash" else True),
            "format_test{}".format(".mpd" if format == "dash" else ".m3u8"),
        )
        stream = cv2.VideoCapture(return_testvideo_path())  # Open stream
        test_framerate = stream.get(cv2.CAP_PROP_FPS)
        stream_params = {
            "-clear_prev_assets": True,
            "-input_framerate": test_framerate,
        }
        if format == "hls":
            stream_params.update(
                {
                    "-hls_base_url": return_assets_path(
                        False if format == "dash" else True
                    )
                    + os.sep
                }
            )
        streamer = StreamGear(
            output=assets_file_path, format=format, logging=True, **stream_params
        )
        while True:
            (grabbed, frame) = stream.read()
            if not grabbed:
                break
            streamer.stream(frame)
        stream.release()
        streamer.terminate()
        if format == "dash":
            meta_data = extract_meta_mpd(assets_file_path)
            assert meta_data and len(meta_data) > 0, "Test Failed!"
            framerate_mpd = string_to_float(meta_data[0]["framerate"])
            assert framerate_mpd > 0.0 and isinstance(
                framerate_mpd, float
            ), "Test Failed!"
            assert round(framerate_mpd) == round(test_framerate), "Test Failed!"
        else:
            meta_data = extract_meta_video(assets_file_path)
            assert meta_data and "framerate" in meta_data, "Test Failed!"
            framerate_m3u8 = float(meta_data["framerate"])
            assert framerate_m3u8 > 0.0 and isinstance(
                framerate_m3u8, float
            ), "Test Failed!"
            assert round(framerate_m3u8) == round(test_framerate), "Test Failed!"
    except Exception as e:
        pytest.fail(str(e))
Beispiel #8
0
def test_invalid_params_rtf():
    """
    Invalid parameter Failure Test - Made to fail by calling invalid parameters
    """
    np.random.seed(0)
    # generate random data for 10 frames
    random_data = np.random.random(size=(480, 640, 3)) * 255
    input_data = random_data.astype(np.uint8)

    stream_params = {"-vcodec": "unknown"}
    streamer = StreamGear(output="output.mpd", logging=True, **stream_params)
    streamer.stream(input_data)
    streamer.stream(input_data)
    streamer.terminate()
Beispiel #9
0
def test_failedchannels():
    """
    IO Test - made to fail with invalid channel length
    """
    np.random.seed(0)
    # generate random data for 10 frames
    random_data = np.random.random(size=(480, 640, 5)) * 255
    input_data = random_data.astype(np.uint8)

    # 'garbage' extension does not exist
    with pytest.raises(ValueError):
        streamer = StreamGear("output.mpd", logging=True)
        streamer.stream(input_data)
        streamer.terminate()
Beispiel #10
0
def test_rtf_stream(conversion, format):
    """
    Testing Real-Time Frames Mode
    """
    assets_file_path = return_assets_path(False if format == "dash" else True)

    try:
        # Open stream
        options = {"THREAD_TIMEOUT": 300}
        stream = CamGear(
            source=return_testvideo_path(), colorspace=conversion, **options
        ).start()
        stream_params = {
            "-clear_prev_assets": True,
            "-input_framerate": "invalid",
        }
        if format == "hls":
            stream_params.update(
                {
                    "-hls_base_url": return_assets_path(
                        False if format == "dash" else True
                    )
                    + os.sep
                }
            )
        streamer = StreamGear(output=assets_file_path, format=format, **stream_params)
        while True:
            frame = stream.read()
            # check if frame is None
            if frame is None:
                break
            if conversion == "COLOR_BGR2RGBA":
                streamer.stream(frame, rgb_mode=True)
            else:
                streamer.stream(frame)
        stream.stop()
        streamer.terminate()
        asset_file = [
            os.path.join(assets_file_path, f)
            for f in os.listdir(assets_file_path)
            if f.endswith(".mpd" if format == "dash" else ".m3u8")
        ]
        assert len(asset_file) == 1, "Failed to create asset file!"
        if format == "dash":
            assert check_valid_mpd(asset_file[0]), "Test Failed!"
        else:
            assert extract_meta_video(asset_file[0]), "Test Failed!"
    except Exception as e:
        if not isinstance(e, queue.Empty):
            pytest.fail(str(e))
Beispiel #11
0
def test_fail_framedimension():
    """
    IO Test - made to fail with multiple frame dimension
    """
    np.random.seed(0)
    # generate random data for 10 frames
    random_data1 = np.random.random(size=(480, 640, 3)) * 255
    input_data1 = random_data1.astype(np.uint8)

    np.random.seed(0)
    random_data2 = np.random.random(size=(580, 640, 3)) * 255
    input_data2 = random_data2.astype(np.uint8)

    streamer = StreamGear(output="output.mpd")
    streamer.stream(None)
    streamer.stream(input_data1)
    streamer.stream(input_data2)
    streamer.terminate()
def test_params(stream_params):
    """
    Testing "-input_framerate" parameter provided by StreamGear
    """
    try:
        mpd_file_path = os.path.join(return_mpd_path(), "dash_test.mpd")
        stream = cv2.VideoCapture(return_testvideo_path())  # Open stream
        streamer = StreamGear(output=mpd_file_path, logging=True, **stream_params)
        while True:
            (grabbed, frame) = stream.read()
            if not grabbed:
                break
            streamer.stream(frame)
        stream.release()
        streamer.terminate()
        assert check_valid_mpd(mpd_file_path)
    except Exception as e:
        pytest.fail(str(e))
Beispiel #13
0
def test_failedchannels(size):
    """
    IO Test - made to fail with invalid channel lengths
    """
    np.random.seed(0)
    if len(size) > 1:
        random_data_1 = np.random.random(size=size[0]) * 255
        input_data_ch1 = random_data_1.astype(np.uint8)
        random_data_2 = np.random.random(size=size[1]) * 255
        input_data_ch3 = random_data_2.astype(np.uint8)
        streamer = StreamGear("output.mpd", logging=True)
        streamer.stream(input_data_ch1)
        streamer.stream(input_data_ch3)
        streamer.terminate()
    else:
        random_data = np.random.random(size=size) * 255
        input_data = random_data.astype(np.uint8)
        streamer = StreamGear("output.mpd", logging=True)
        streamer.stream(input_data)
        streamer.terminate()
Beispiel #14
0
def test_rtf_livestream():
    """
    Testing Real-Time Frames Mode with livestream.
    """
    mpd_file_path = return_mpd_path()
    try:
        # Open stream
        stream = CamGear(source=return_testvideo_path()).start()
        stream_params = {
            "-livestream": True,
        }
        streamer = StreamGear(output=mpd_file_path, **stream_params)
        while True:
            frame = stream.read()
            # check if frame is None
            if frame is None:
                break
            streamer.stream(frame)
        stream.stop()
        streamer.terminate()
    except Exception as e:
        pytest.fail(str(e))