Skip to content

Commit

Permalink
Merge pull request #22 from brandonschabell/entrypoint-base64-bug
Browse files Browse the repository at this point in the history
Writing binary images instead of base64 through entrypoint
  • Loading branch information
brandonschabell authored Oct 6, 2019
2 parents 62d24ea + dc78df0 commit b10f403
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions tests/test_videotoframes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cv2
import os
import pytest
import shutil
Expand All @@ -9,21 +10,21 @@


def test_main_no_arguments(capsys):
with pytest.raises(SystemExit) as e:
with pytest.raises(SystemExit):
main()
captured = capsys.readouterr()
assert 'videotoframes: error: the following arguments are required: -o, -i' in captured[1]


def test_main_no_output(capsys):
with pytest.raises(SystemExit) as e:
with pytest.raises(SystemExit):
main(['-i', './'])
captured = capsys.readouterr()
assert 'videotoframes: error: the following arguments are required: -o\n' in captured[1]


def test_main_no_input(capsys):
with pytest.raises(SystemExit) as e:
with pytest.raises(SystemExit):
main(['-o', './'])
captured = capsys.readouterr()
assert 'videotoframes: error: the following arguments are required: -i\n' in captured[1]
Expand Down Expand Up @@ -67,6 +68,17 @@ def test_main_max_frames_even_2_frames(tmpdir):
assert set(frames) == set(expected_frames)


def test_main_frame_content(tmpdir):
main(['-i', os.path.join(get_testfiles_path(), 'small.mp4'),
'-o', os.path.join(str(tmpdir), 'frames'),
'--max-frames=1'])
frames = os.listdir(os.path.join(str(tmpdir), 'frames'))
frame_path = os.path.join(str(tmpdir), 'frames', frames[0])
image = cv2.imread(frame_path)
assert image is not None
assert image.shape == (320, 560, 3)


def test_frame_grabber_2_frames_even():
frames = get_frames_to_grab(frame_count=10, max_frames=2)
assert sorted(frames) == [0, 9]
Expand Down Expand Up @@ -118,7 +130,6 @@ def test_multiple_videos(tmpdir):

def test_empty_input(tmpdir):
tmpdir.mkdir('empty')
with pytest.raises(Exception) as e:
with pytest.raises(Exception, match='No video selected.') as e:
main(['-i', os.path.join(str(tmpdir), 'empty'),
'-o', os.path.join(str(tmpdir), 'frames')])
assert 'No video selected.' in str(e)
2 changes: 1 addition & 1 deletion videotoframes/video_to_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def video_to_frames(input_path, output_dir, max_frames, even):
frame_number = frame['frameNumber']
output_path = os.path.join(output_dir, base_filename + '-frame{:03d}.jpg'.format(frame_number))
with open(output_path, 'wb') as file:
file.write(base_64_image)
file.write(base64.b64decode(base_64_image))

return True

Expand Down

0 comments on commit b10f403

Please sign in to comment.