From 620cf3bd3466a7f9ed17b9e4d3b637c40bfad5fb Mon Sep 17 00:00:00 2001 From: felix Date: Mon, 26 Aug 2019 18:51:24 +0800 Subject: [PATCH] test(ffmpeg): add unittest for ffmpeg api --- tests/test_ffmpeg_tools.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/test_ffmpeg_tools.py diff --git a/tests/test_ffmpeg_tools.py b/tests/test_ffmpeg_tools.py new file mode 100644 index 00000000..75f3c2ff --- /dev/null +++ b/tests/test_ffmpeg_tools.py @@ -0,0 +1,68 @@ +import copy +import os +import unittest + +from gnes.preprocessor.io_utils import ffmpeg +from gnes.preprocessor.io_utils import video +from gnes.preprocessor.io_utils import gif +from gnes.preprocessor.io_utils import audio + + +class TestFFmpeg(unittest.TestCase): + def setUp(self): + self.dirname = os.path.dirname(__file__) + + self.video_path = os.path.join(self.dirname, 'videos', 'test.mp4') + self.frames = video.capture_frames(input_fn=self.video_path, fps=10, scale='768:360') + + @unittest.SkipTest + def test_probe(self): + probe = ffmpeg.probe(self.video_path) + self.assertEqual(probe['height'], 720) + self.assertEqual(probe['width'], 1280) + self.assertEqual(probe['fps'], 25.0) + + @unittest.SkipTest + def test_capture_frames(self): + frames1 = video.capture_frames(input_fn=self.video_path, fps=10, scale='768:360') + + with open(self.video_path, 'rb') as f: + data = f.read() + frames2 = video.capture_frames(input_data=data, fps=10, scale='768:360') + + self.assertEqual(frames1.shape, frames2.shape) + + @unittest.SkipTest + def test_scale_video(self): + out = video.scale_video(input_fn=self.video_path, scale='768:360') + meta = ffmpeg.get_media_meta(input_data=out, input_options={'format': 'mp4'}) + self.assertEqual(meta['frame_width'], 768) + self.assertEqual(meta['frame_height'], 360) + + @unittest.SkipTest + def test_encode_video(self): + video_data = video.encode_video(images=list(self.frames)) + meta = ffmpeg.get_media_meta(input_data=video_data, input_options={'format': 'mp4'}) + self.assertEqual(meta['frame_width'], 768) + self.assertEqual(meta['frame_height'], 360) + + @unittest.SkipTest + def test_gif_encode(self): + gif_data = gif.encode_gif(images=list(self.frames), fps=10) + frames = gif.decode_gif(data=gif_data) + self.assertEqual(self.frames.shape, frames.shape) + + @unittest.SkipTest + def test_capture_audio(self): + audio_data1 = audio.capture_audio(input_fn=self.video_path) + with open(self.video_path, 'rb') as f: + data = f.read() + audio_data2 = audio.capture_audio(input_data=data) + + self.assertEqual(audio_data1.shape, audio_data2.shape) + + def test_split_audio(self): + audio.split_audio(input_fn=self.video_path) + with open(self.video_path, 'rb') as f: + data = f.read() + audio.split_audio(input_data=data)