Exemple #1
0
def test_console_hour(setup_module):
    for f in Path("/tmp/tmv/").rglob("hour*"):
        os.remove(f)

    fn = "hour-90days.mp4"
    cl = [
        "--output", fn, "--slice", "Concat", "--start-time", "11:00",
        "--end-time", "13:00", "--log-level", "DEBUG", CAL_CROSS_IMAGES
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    # assert frames(fn) == 8761
    assert fps(fn) == 25

    fn = "hour-cross.mp4"
    cl = [
        "--output", fn, "--slice", "Concat", "--start-time", "11:00",
        "--end-time", "13:00", "--log-level", "DEBUG",
        str(TEST_DATA / "90days1h/*.jpg")
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    #assert frames(fn) == 896
    assert fps(fn) == 25

    copy_tree(".", "/tmp/tmv")
Exemple #2
0
def test_console_concat(setup_module):
    # move them here to check visually
    for f in Path("/tmp/tmv/").rglob("concat*"):
        os.remove(f)
    fn = "concat-90d.mp4"
    cl = [
        "--output", fn, "--log-level", "DEBUG",
        str(TEST_DATA / "90days1h/*.jpg")
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert frames(fn) == 896
    assert fps(fn) == 25

    fn = "concat-cross.mp4"
    cl = ["--output", fn, "--log-level", "DEBUG", CAL_CROSS_IMAGES]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert frames(fn) == 8761
    assert fps(fn) == 25
    copy_tree(".", "/tmp/tmv")
Exemple #3
0
def no_test_console_autoname(setup_module, capsys):
    cl = [
        "--log-level", "DEBUG", "--filenames",
        str(TEST_DATA / "90days1h/*.jpg")
    ]

    fn = "2020-02-21T06_to_2020-05-16T17.mp4"

    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    l = capsys.readouterr()
    assert l.out.strip() == '2020-02-21T06_to_2020-05-16T17.mp4'
    assert exc.value.code == 0
    assert frames(fn) == 896
    assert fps(fn) == 25
Exemple #4
0
def test_preview_videos(setup_test):
    c = """
        [preview-videos]
        filters.scale="128:-1"
        filters.fps = "fps=5"
        filters.setpts = "0.25*PTS"
        """
    vd = TaskRunner()
    vd.configs(c)
    vd.run_tasks()
    assert Path("daily-videos/previews/2019-10-22.mp4").is_file
    frames_o = frames("daily-videos/2019-10-22.mp4")
    fps_o = fps("daily-videos/2019-10-22.mp4")
    frames_p = frames("daily-videos/previews/2019-10-22.mp4")
    fps_p = fps("daily-videos/previews/2019-10-22.mp4")
    assert fps_o == 25
    assert fps_p == 5
    assert frames_p == pytest.approx((fps_p / fps_o) * 0.25 * frames_o, abs=5)
    # assert False, "Output at " + os.getcwd()
    # run again - should NOT make previews of previews!
    run1_files = list(Path(".").glob("**/*.mp4"))
    vd.run_tasks()
    run2_files = list(Path(".").glob("**/*.mp4"))
    assert run1_files == run2_files, f"{run1_files} != {run2_files}"
Exemple #5
0
def test_console_diagonal(setup_module, caplog):
    """
    Use cal_cross to do numeric and visual tests
    """
    for f in Path("/tmp/tmv/").rglob("diagonal*"):
        os.remove(f)

    fn = "diagonal-cross-auto-fps25.mp4"
    cl = [
        "--output", fn, "--slice", "Diagonal", "--sliceage", "1 hour",
        "--log-level", "DEBUG",
        str(CAL_CROSS_IMAGES)
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert frames(fn) == pytest.approx(365, abs=1)  # one a day
    assert fps(fn) == 25

    fn = "diagonal-90days.mp4"

    cl = [
        "--output", fn, "--slice", "Diagonal", "--speedup", "1000000", "--end",
        "2000-04-01T00-00-00", "--log-level", "DEBUG", CAL_CROSS_IMAGES
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    vi = VideoInfo(fn)
    assert vi.real_duration.total_seconds() == pytest.approx(
        timedelta(days=90).total_seconds(), abs=3600 * 10)
    assert vi.real_start == dt(2000, 1, 1, 0, 0, 0)
    assert vi.duration.total_seconds() == pytest.approx(
        timedelta(days=90).total_seconds() / 1000000, abs=1)
    assert vi.fps == 25

    fn = "diagonal-cross-1h.mp4"
    cl = [
        "--output", fn, "--slice", "Diagonal", "--sliceage", "1 hour",
        "--log-level", "DEBUG",
        str(CAL_CROSS_IMAGES)
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert frames(fn) == pytest.approx(365, abs=1)  # one a day
    assert fps(fn) == 25

    fn = "diagonal-cross-1h-limited.mp4"
    cl = [
        "--output", fn, "--slice", "Diagonal", "--sliceage", "1 hour",
        "--start-time", "06:00", "--end-time", "18:00", "--log-level", "DEBUG",
        str(CAL_CROSS_IMAGES)
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    # still one a day, just tighter band
    assert frames(fn) == pytest.approx(365, abs=1)
    assert fps(fn) == 25

    caplog.clear()
    fn = "diagonal-cross-auto.mp4"
    cl = [
        "--output", fn, "--slice", "Diagonal", "--log-level", "DEBUG", "--fps",
        "5",
        str(CAL_CROSS_IMAGES)
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert fps(fn) == 5

    copy_tree(".", "/tmp/tmv")
Exemple #6
0
def test_console_fps_speed(setup_module):
    #                                   input           output
    # dur_real  dur_video   speedup     frames          frames
    #                                   @1/60fps_real   @25fps_video
    # 7 days    1 min       x10080      10800           1500               keep 50% of frames
    # 30 days   2 min       x21600      43200           3000               keep 10%
    # 1 year    10 min      x52560      525600          15000              keep 3%
    #
    l = logging.getLogger("tmv.video")
    l.setLevel(logging.DEBUG)
    files = str(TEST_DATA / "3days1h/*.jpg")
    images = files_from_glob([files])
    cl = ["--output", "1-default.mp4", "--log-level", "DEBUG", *images]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    f = frames("1-default.mp4")
    assert f == 72

    cl = [
        "--output", "2-25fps.mp4", "--log-level", "DEBUG", "--fps", "25",
        *images
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert frames("2-25fps.mp4") == 72

    # @25fps the impliciti sp[eedup, as used above is 90000
    # test 9000
    fn = "3-25fps-9000x.mp4"
    cl = [
        "--output", fn, "--log-level", "DEBUG", "--fps", "25", "--speedup",
        "9000", *images
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert frames(fn) == pytest.approx(72 * 10, rel=0.05)
    assert fps(fn) == pytest.approx(25)
    print(os.getcwd())
    print(f"frames({fn}) = {frames(fn)}")
    print(f"fps({fn}) = {fps(fn)}")

    # @25fps the impliciti sp[eedup, as used above is 90000
    # test x180000 (x2 faster)
    fn = "4-25fps-x180000.mp4"
    cl = [
        "--output", fn, "--log-level", "DEBUG", "--fps", "25", "--speedup",
        "180000", *images
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    assert frames(fn) == pytest.approx(72 / 2, abs=5)
    assert fps(fn) == pytest.approx(25)
    print(os.getcwd())
    print(f"frames({fn}) = {frames(fn)}")
    print(f"fps({fn}) = {fps(fn)}")

    # @25fps the impliciti sp[eedup, as used above is 90000
    # use a tenth of that, but half the fps
    #
    fn = "5-x10000.mp4"
    cl = [
        "--output", fn, "--log-level", "DEBUG", "--speedup", "10000", "--fps",
        "12", *images
    ]
    with pytest.raises(SystemExit) as exc:
        video_compile_console(cl)
    assert exc.value.code == 0
    print(os.getcwd())
    print(f"frames({fn}) = {frames(fn)}")
    print(f"fps({fn}) = {fps(fn)}")
    assert frames(fn) == pytest.approx(72 * 9 / 2, rel=20)
    assert fps(fn) == pytest.approx(12)