Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
test(ffmpeg): add unittest for ffmpeg api
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Aug 26, 2019
1 parent 10cef54 commit 620cf3b
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/test_ffmpeg_tools.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 620cf3b

Please sign in to comment.