Skip to content

Commit

Permalink
added tests, added container check to renderer functions
Browse files Browse the repository at this point in the history
  • Loading branch information
balintlaczko committed Sep 30, 2021
1 parent 6668b2d commit a1c9ba7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
11 changes: 11 additions & 0 deletions musicalgestures/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ def extract_subclip(filename, t1, t2, target_name=None, overwrite=False):
if not overwrite:
target_name = generate_outfilename(target_name)

pass_if_containers_match(filename, target_name)

# avoiding ffmpeg glitch if format is not avi:
if os.path.splitext(filename)[1] != '.avi':
cmd = ['ffmpeg', "-y",
Expand Down Expand Up @@ -607,6 +609,8 @@ def rotate_video(filename, angle, target_name=None, overwrite=False):
if not overwrite:
target_name = generate_outfilename(target_name)

pass_if_containers_match(filename, target_name)

cmds = ['ffmpeg', '-y', '-i', filename, "-vf",
f"rotate={math.radians(angle)}", "-q:v", "3", "-c:a", "copy", target_name]
ffmpeg_cmd(cmds, get_length(filename),
Expand Down Expand Up @@ -635,6 +639,8 @@ def convert_to_grayscale(filename, target_name=None, overwrite=False):
if not overwrite:
target_name = generate_outfilename(target_name)

pass_if_containers_match(filename, target_name)

cmds = ['ffmpeg', '-y', '-i', filename, '-vf',
'hue=s=0', "-q:v", "3", "-c:a", "copy", target_name]
ffmpeg_cmd(cmds, get_length(filename),
Expand Down Expand Up @@ -663,6 +669,7 @@ def framediff_ffmpeg(filename, target_name=None, color=True, overwrite=False):
target_name = of + '_framediff' + fex
if not overwrite:
target_name = generate_outfilename(target_name)
pass_if_containers_match(filename, target_name)
if color == True:
pixformat = 'gbrp'
else:
Expand Down Expand Up @@ -698,6 +705,8 @@ def threshold_ffmpeg(filename, threshold=0.1, target_name=None, binary=False, ov
if not overwrite:
target_name = generate_outfilename(target_name)

pass_if_containers_match(filename, target_name)

width, height = get_widthheight(filename)

thresh_color = matplotlib.colors.to_hex([threshold, threshold, threshold])
Expand Down Expand Up @@ -758,6 +767,8 @@ def motionvideo_ffmpeg(
if not overwrite:
target_name = generate_outfilename(target_name)

pass_if_containers_match(filename, target_name)

cmd_end = ['-q:v', '3', "-c:a", "copy", target_name]

# set color mode
Expand Down
63 changes: 62 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,65 @@ def test_output(self, tmp_path, testvideo_mp4):
testvideo_casted_avi = cast_into_avi(testvideo_mp4, target_name=target_name)
assert os.path.isfile(testvideo_casted_avi) == True
assert os.path.splitext(testvideo_casted_avi)[1] == ".avi"
assert target_name == testvideo_casted_avi
assert target_name == testvideo_casted_avi


class Test_extract_subclip:
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_trimmed.avi"
testvideo_trimmed = extract_subclip(testvideo_avi, 3, 4, target_name=target_name)
assert os.path.isfile(testvideo_trimmed) == True
assert os.path.splitext(testvideo_trimmed)[1] == ".avi"
assert target_name == testvideo_trimmed

def test_length(self, tmp_path):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_trimmed.avi"
testvideo_trimmed = extract_subclip(musicalgestures.examples.dance, 3, 4, target_name=target_name)
fps = get_fps(musicalgestures.examples.dance)
result_framecount = get_framecount(testvideo_trimmed)
assert fps - 1 <= result_framecount <= fps + 1


class Test_rotate_video:
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_rotated.avi"
testvideo_rotated = rotate_video(testvideo_avi, 90, target_name=target_name)
assert os.path.isfile(testvideo_rotated) == True
assert os.path.splitext(testvideo_rotated)[1] == ".avi"
assert target_name == testvideo_rotated


class Test_convert_to_grayscale:
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_grayscale.avi"
testvideo_grayscale = convert_to_grayscale(testvideo_avi, target_name=target_name)
assert os.path.isfile(testvideo_grayscale) == True
assert os.path.splitext(testvideo_grayscale)[1] == ".avi"
assert target_name == testvideo_grayscale


class Test_framediff_ffmpeg:
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_framediff.avi"
testvideo_framediff = framediff_ffmpeg(testvideo_avi, target_name=target_name)
assert os.path.isfile(testvideo_framediff) == True
assert os.path.splitext(testvideo_framediff)[1] == ".avi"
assert target_name == testvideo_framediff


class Test_threshold_ffmpeg:
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_threshold.avi"
testvideo_threshold = threshold_ffmpeg(testvideo_avi, target_name=target_name)
assert os.path.isfile(testvideo_threshold) == True
assert os.path.splitext(testvideo_threshold)[1] == ".avi"
assert target_name == testvideo_threshold


class Test_motionvideo_ffmpeg:
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_motionvideo.avi"
testvideo_motionvideo = motionvideo_ffmpeg(testvideo_avi, target_name=target_name)
assert os.path.isfile(testvideo_motionvideo) == True
assert os.path.splitext(testvideo_motionvideo)[1] == ".avi"
assert target_name == testvideo_motionvideo

0 comments on commit a1c9ba7

Please sign in to comment.