Exemple #1
0
def test_iter():
    timestamps = []
    pixels = []
    video = Mkv(test_mkv)
    if os.path.exists(index_file(test_mkv)):
        os.unlink(index_file(test_mkv))
    for i, img in enumerate(video):
        assert img.index == i
        timestamps.append(img.timestamp)
        pixels.append(img[20, 30, 1])
    assert len(timestamps) == 16
    assert timestamps[0] == 0.0  # FIXME: Use systeime
    assert timestamps[1] == 0.04
    assert pixels[:6] == [84, 85, 85, 84, 84, 86]

    pixels = [video[i][20, 30, 1] for i in range(6)]
    assert pixels == [84, 85, 85, 84, 84, 86]

    assert video[2].timestamp == 0.08
    assert video[1].timestamp == 0.04
    assert video[2].index == 2
    assert video[0][20, 30, 1] == 84

    video2 = Mkv(test_mkv)
    assert video[3][20, 30, 1] == 84

    assert len(video) == 16
    with raises(IndexError):
        video[100]
Exemple #2
0
def test_mjpg_codec_grey():
    systimes = []
    video = Mkv(mjpg_codec_mkv, grey=True)
    for img in video:
        systimes.append(img.systime)
        assert img.shape == (300, 480)
    assert systimes == [1539001990.82, 1539001991.82, 1539001992.82]
Exemple #3
0
def test_systime():
    video = Mkv(systime_mkv)
    assert video[7].systime == 1448984844.6525
    t = [img.systime for img in video]
    assert t == video.systimes

    cut = video[10:20]
    assert t[10:20] == cut.systimes
Exemple #4
0
def test_mkv_systime():
    video = VideoFilter(Mkv(systime_mkv), lambda f: f[:])
    assert video[7].systime == 1448984844.6525
    t = [img.systime for img in video]
    assert t == video.systimes

    cut = video[10:20]
    assert t[10:20] == cut.systimes
Exemple #5
0
def test_getitem():
    video = Mkv(systime_mkv)
    idx = 31
    for i in range(3):
        assert video[idx - 1].index == idx - 1
    for i in range(3):
        assert video[idx].index == idx
    for i in range(3):
        assert video[idx + 1].index == idx + 1
Exemple #6
0
def test_mkv_getitem():
    video = VideoFilter(Mkv(systime_mkv), lambda f: f[:])
    idx = 31
    for i in range(3):
        assert video[idx - 1].index == idx - 1
    for i in range(3):
        assert video[idx].index == idx
    for i in range(3):
        assert video[idx + 1].index == idx + 1
Exemple #7
0
def test_mjpg_codec():
    systimes = []
    video = Mkv(mjpg_codec_mkv)
    for img in video:
        systimes.append(img.systime)
        assert img.shape == (300, 480, 3)
    assert video[0].systime == 1539001990.82
    assert video[2].systime == 1539001992.82
    assert video[1].systime == 1539001991.82
    assert systimes == [1539001990.82, 1539001991.82, 1539001992.82]
Exemple #8
0
def Video(filename, grey=False):
    """
    Creates a *View* object representing the video in the file *filename*.
    See Overview above.
    """
    if filename.endswith('.mkv'):
        from vi3o.mkv import Mkv
        return Mkv(filename, grey)
    elif filename.endswith('.mjpg'):
        from vi3o.mjpg import Mjpg
        return Mjpg(filename, grey)
    else:
        from vi3o.opencv import CvVideo
        return CvVideo(filename, grey)
Exemple #9
0
def test_pickle():
    video = Mkv(systime_mkv)
    t8 = video[8].systime
    assert t8 > 10000
    sub = video[6::2]
    assert sub[1].systime == t8

    assert video.myiter is not None
    with NamedTemporaryFile() as tmp:
        with open(tmp.name, "wb") as fd:
            pickle.dump(sub, fd)
        loaded = pickle.load(open(tmp.name, "rb"))

    assert loaded[1].systime == t8
Exemple #10
0
def Video(filename, grey=False):
    """
    Creates a *Video* object representing the video in the file *filename*.
    See Overview above.
    """
    from vi3o.mkv import Mkv, UnsupportedFormatError as MkvUnsupported
    try:
        return Mkv(filename, grey)
    except MkvUnsupported:
        pass

    from vi3o.mjpg import Mjpg, UnsupportedFormatError as MjpgUnsupported
    try:
        return Mjpg(filename, grey)
    except MjpgUnsupported:
        pass

    from vi3o.imageio import ImageioVideo
    return ImageioVideo(filename, grey)
Exemple #11
0
def Video(filename, grey=False):
    """
    Creates a *Video* object representing the video in the file *filename*.
    See Overview above.
    """
    # Be compatible with pathlib.Path filenames
    filename = str(filename)

    if filename.endswith('.mkv'):
        from vi3o.mkv import Mkv
        return Mkv(filename, grey)
    elif filename.endswith('.mjpg'):
        from vi3o.mjpg import Mjpg
        return Mjpg(filename, grey)
    elif filename.endswith('recording.xml'):
        from vi3o.recording import read_recording_xml, Recording
        return Recording(read_recording_xml(filename), grey=grey)
    else:
        from vi3o.imageio import ImageioVideo
        return ImageioVideo(filename, grey)
Exemple #12
0
def test_slice():
    video = Mkv(test_mkv)
    sub = video[2:5]
    assert [img[20, 30, 1] for img in sub] == [85, 84, 84]
    assert sub[1].timestamp == video[3].timestamp
    assert len(sub) == 3
Exemple #13
0
def test_no_file():
    with raises(IOError):
        Mkv(test_mkv + 'not_there')
Exemple #14
0
def test_mkv_pathlib_open():
    _ = Mkv(pathlib.Path(test_mkv))
Exemple #15
0
def test_no_serial_number():
    assert Mkv(test_mkv).serial_number == b''
Exemple #16
0
def test_serial_number():
    assert Mkv(mac_mkv).serial_number == b'ACCC8E19244E'