Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests of autoprocessing #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
29 changes: 29 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on: [push]

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .
# pip install -r requirements.txt
- name: Install FFmpeg
run: |
sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt-get update
sudo apt-get install ffmpeg
- name: Test with pytest
run: |
pip install pytest
pytest
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool:pytest]
testpaths = tests
Binary file added tests/example_screencast.mp4
Binary file not shown.
28 changes: 28 additions & 0 deletions tests/example_screencast.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[0:v]trim=0.0000:0.2530,setpts=PTS-STARTPTS[v1];
[0:v]trim=0.2530:1.9990,setpts=(PTS-STARTPTS)/8[v2];
[0:v]trim=1.9990:6.4611,setpts=PTS-STARTPTS[v3];
[0:v]trim=6.4611:16.8058,setpts=(PTS-STARTPTS)/8[v4];
[0:v]trim=16.8058:19.3400,setpts=PTS-STARTPTS[v5];
[0:v]trim=19.3400:32.5301,setpts=(PTS-STARTPTS)/8[v6];
[0:v]trim=32.5301:45.8549,setpts=PTS-STARTPTS[v7];
[0:v]trim=45.8549:56.1694,setpts=(PTS-STARTPTS)/8[v8];
[0:v]trim=56.1694:59.8605,setpts=PTS-STARTPTS[v9];
[0:v]trim=59.8605:64.8073,setpts=(PTS-STARTPTS)/8[v10];
[0:v]trim=64.8073:78.2927,setpts=PTS-STARTPTS[v11];
[0:v]trim=78.2927:81.6206,setpts=(PTS-STARTPTS)/8[v12];
[0:v]trim=start=81.6206,setpts=PTS-STARTPTS[v13];
[0:a]atrim=0.0000:0.2530,asetpts=PTS-STARTPTS[a1];
[0:a]atrim=0.2530:1.9990,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a2];
[0:a]atrim=1.9990:6.4611,asetpts=PTS-STARTPTS[a3];
[0:a]atrim=6.4611:16.8058,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a4];
[0:a]atrim=16.8058:19.3400,asetpts=PTS-STARTPTS[a5];
[0:a]atrim=19.3400:32.5301,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a6];
[0:a]atrim=32.5301:45.8549,asetpts=PTS-STARTPTS[a7];
[0:a]atrim=45.8549:56.1694,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a8];
[0:a]atrim=56.1694:59.8605,asetpts=PTS-STARTPTS[a9];
[0:a]atrim=59.8605:64.8073,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a10];
[0:a]atrim=64.8073:78.2927,asetpts=PTS-STARTPTS[a11];
[0:a]atrim=78.2927:81.6206,asetpts=PTS-STARTPTS,atempo=2.0,atempo=2.0,atempo=2.0,volume=1.000[a12];
[0:a]atrim=start=81.6206,asetpts=PTS-STARTPTS[a13];
[v1][a1][v2][a2][v3][a3][v4][a4][v5][a5][v6][a6][v7][a7][v8][a8][v9][a9][v10][a10][v11][a11][v12][a12][v13][a13]concat=n=13:v=1:a=1[v][an];
[an]volume=4.8dB[a]
60 changes: 60 additions & 0 deletions tests/test_example_screencast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import filecmp
import autoscrub
from pathlib import Path

TEST_VIDEO_INPUT = "example_screencast.mp4"
TEST_VIDEO_OUTPUT = "example_screencast_scrub.mp4"
VALID_FILTERGRAPH = "example_screencast.txt"
VALID_DURATION = 48.57
VALID_LOUDNESS = {
"I": -18.1,
"Threshold": -39.2,
"LRA": 7.3,
"LRA low": -23.5,
"LRA high": -16.2,
}

os.chdir(Path(__file__).parent.absolute())


def test_autoprocess(input=TEST_VIDEO_INPUT, filtergraph=VALID_FILTERGRAPH):
"""Runs autoscrub autoprocess --debug on TEST_VIDEO_INPUT

Checks stdout and compares resulting filtergraph to known valid version
"""
# Create output path
suffix = Path(input).suffix
output = input.replace(suffix, "_scrub" + suffix)

# Run autoscrub autoprocess --debug input output
p = autoscrub._agnostic_Popen(
["autoscrub", "autoprocess", "--debug", input, output]
)
_, stderr = autoscrub._agnostic_communicate(p)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #2 in which processing continued indefinitely, a timeout is essential here, akin to subprocess.Popen.communicate. @philipstarkey, is this something that could/should be added to autoscrub._agnostic_communicate or should I be using something else. here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I've set a timeout on the test runner, using pytest-timeout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why, but the test is stalling on Windows at this point (both locally and on Python 2.7 and 3.8).


# Check stdout
stdout = p.stdout.readlines()
assert stdout[-4].strip() == b"[autoscrub:info] Done!"

# Check filtergraph
tmp = Path(stdout[-1].decode("utf8").split("at:")[-1].strip())
assert filecmp.cmp(VALID_FILTERGRAPH, tmp)


def test_duration():
"""Checks duration of processed test video

Checks duration of processed test video produced by autoscrub autoprocess
is as expected.
"""
assert autoscrub.getDuration(TEST_VIDEO_OUTPUT) == VALID_DURATION


def test_loudness():
"""Checks loudness properties of processed test video

Checks loudness of test video produced by autoscrub autoprocess
is as expected.
"""
assert autoscrub.getLoudness(TEST_VIDEO_OUTPUT) == VALID_LOUDNESS