[Bf-blender-cvs] [40e62f271c1] master: FFmpeg: Add regression tests

Sergey Sharybin noreply at git.blender.org
Fri Mar 9 10:53:34 CET 2018


Commit: 40e62f271c137f6bce19c6f6497948d014a7ab17
Author: Sergey Sharybin
Date:   Mon Mar 5 15:32:49 2018 +0100
Branches: master
https://developer.blender.org/rB40e62f271c137f6bce19c6f6497948d014a7ab17

FFmpeg: Add regression tests

Currently only covering handful of files from reports about wrong fps detected.

It will need D3083 applied first to get tests passed, also tests themselves
are to be committed to svn.

But there are some python code which needs to be reviewed, like blendfile
passed to run_blender().

Reviewers: sybren, mont29

Reviewed By: sybren, mont29

Subscribers: mont29

Differential Revision: https://developer.blender.org/D3096

===================================================================

M	tests/python/CMakeLists.txt
A	tests/python/ffmpeg_tests.py
M	tests/python/modules/test_utils.py

===================================================================

diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
index 6419c3f36e2..69761249002 100644
--- a/tests/python/CMakeLists.txt
+++ b/tests/python/CMakeLists.txt
@@ -27,6 +27,7 @@
 set(USE_EXPERIMENTAL_TESTS FALSE)
 
 set(TEST_SRC_DIR ${CMAKE_SOURCE_DIR}/../lib/tests)
+set(TEST_DATA_SRC_DIR ${CMAKE_SOURCE_DIR}/../lib/tests_data)
 set(TEST_OUT_DIR ${CMAKE_BINARY_DIR}/tests)
 
 # ugh, any better way to do this on testing only?
@@ -617,4 +618,13 @@ if(WITH_ALEMBIC)
 	)
 endif()
 
+if(WITH_CODEC_FFMPEG)
+	add_python_test(
+		ffmpeg_tests
+		${CMAKE_CURRENT_LIST_DIR}/ffmpeg_tests.py
+		--blender "$<TARGET_FILE:blender>"
+		--testdir "${TEST_DATA_SRC_DIR}/ffmpeg"
+	)
+endif()
+
 add_subdirectory(collada)
diff --git a/tests/python/ffmpeg_tests.py b/tests/python/ffmpeg_tests.py
new file mode 100755
index 00000000000..9493d6f7a17
--- /dev/null
+++ b/tests/python/ffmpeg_tests.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python3
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import argparse
+import functools
+import shutil
+import pathlib
+import subprocess
+import sys
+import tempfile
+import unittest
+
+from modules.test_utils import AbstractBlenderRunnerTest
+
+
+class AbstractFFmpegTest(AbstractBlenderRunnerTest):
+    @classmethod
+    def setUpClass(cls):
+        cls.blender = args.blender
+        cls.testdir = pathlib.Path(args.testdir)
+
+
+class AbstractFFmpegSequencerTest(AbstractFFmpegTest):
+    def get_script_for_file(self, filename: pathlib.Path) -> str:
+        movie = self.testdir / filename
+        return \
+            "import bpy; " \
+            "bpy.context.scene.sequence_editor_create(); " \
+            "strip = bpy.context.scene.sequence_editor.sequences.new_movie(" \
+            "'test_movie', %r, channel=1, frame_start=1); " \
+            "print(f'fps:{strip.fps}')" % movie.as_posix()
+
+    def get_movie_file_fps(self, filename: pathlib.Path) -> float:
+        script = self.get_script_for_file(filename)
+        output = self.run_blender('', script)
+        for line in output.splitlines():
+            if line.startswith('fps:'):
+                return float(line.split(':')[1])
+        return 0.0
+
+
+class FPSDetectionTest(AbstractFFmpegSequencerTest):
+    def test_T51153(self):
+        self.assertAlmostEqual(
+            self.get_movie_file_fps('T51153_bad_clip_2.mts'), 
+            29.97,
+            places=2)
+
+    def test_T53857(self):
+        self.assertAlmostEqual(
+            self.get_movie_file_fps('T53857_2018-01-22_15-30-49.mkv'),
+            30.0,
+            places=2)
+
+    def test_T54148(self):
+        self.assertAlmostEqual(
+            self.get_movie_file_fps('T54148_magn_0.mkv'),
+            1.0,
+            places=2)
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--blender', required=True)
+    parser.add_argument('--testdir', required=True)
+    args, remaining = parser.parse_known_args()
+
+    unittest.main(argv=sys.argv[0:1] + remaining)
diff --git a/tests/python/modules/test_utils.py b/tests/python/modules/test_utils.py
index 6ca498d8cdf..55ef882c49c 100755
--- a/tests/python/modules/test_utils.py
+++ b/tests/python/modules/test_utils.py
@@ -75,18 +75,24 @@ class AbstractBlenderRunnerTest(unittest.TestCase):
         assert self.blender, "Path to Blender binary is to be set in setUpClass()"
         assert self.testdir, "Path to tests binary is to be set in setUpClass()"
 
-        blendfile = self.testdir / filepath
+        blendfile = self.testdir / filepath if filepath else ""
 
-        command = (
+        command = [
             self.blender,
             '--background',
             '-noaudio',
             '--factory-startup',
             '--enable-autoexec',
-            str(blendfile),
+        ]
+
+        if blendfile:
+            command.append(str(blendfile))
+
+        command.extend([
             '-E', 'CYCLES',
             '--python-exit-code', '47',
             '--python-expr', python_script,
+            ]
         )
 
         proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,



More information about the Bf-blender-cvs mailing list