|
| 1 | +from __future__ import ( |
| 2 | + unicode_literals, |
| 3 | + absolute_import, |
| 4 | + print_function, |
| 5 | + division, |
| 6 | + ) |
| 7 | +import os |
| 8 | +import aaf2 |
| 9 | +import common |
| 10 | +import unittest |
| 11 | + |
| 12 | +KEYFRAME_VALUE_MARGIN_OF_ERROR = .1 |
| 13 | + |
| 14 | + |
| 15 | +class TestKeyframeInterpolation(unittest.TestCase): |
| 16 | + def test_normal_bezier(self): |
| 17 | + file = os.path.join(common.test_files_dir(), 'keyframes/normal_bezier.aaf') |
| 18 | + # these values are transcribed by hand from media composer |
| 19 | + expected_result = { |
| 20 | + 0: 0.0, |
| 21 | + 1: 147.50, |
| 22 | + 2: 257.19, |
| 23 | + 3: 343.74, |
| 24 | + 4: 413.91, |
| 25 | + 5: 471.47, |
| 26 | + 6: 518.72, |
| 27 | + 7: 557.20, |
| 28 | + 8: 587.92, |
| 29 | + 9: 611.60, |
| 30 | + 10: 628.70, |
| 31 | + 11: 639.51, |
| 32 | + 12: 644.18, |
| 33 | + 13: 642.68, |
| 34 | + 14: 634.87, |
| 35 | + 15: 620.42, |
| 36 | + 16: 598.80, |
| 37 | + 17: 569.19, |
| 38 | + 18: 530.32, |
| 39 | + 19: 480.22, |
| 40 | + 20: 415.59, |
| 41 | + 21: 330.32, |
| 42 | + 22: 210.33, |
| 43 | + 23: 0.0, |
| 44 | + } |
| 45 | + with aaf2.open(file) as f: |
| 46 | + # Grab the Y position parameter from this AAF |
| 47 | + op_group = next(f.content.compositionmobs()).slots[8].segment.components[1] |
| 48 | + param_y_pos = next( |
| 49 | + param for param in op_group.parameters |
| 50 | + if isinstance(param, aaf2.misc.VaryingValue) |
| 51 | + and param.name == "DVE_POS_Y_U" |
| 52 | + ) |
| 53 | + self.compare_interpolated_values(param_y_pos, expected_result) |
| 54 | + |
| 55 | + def test_handle_past_last_keyframe(self): |
| 56 | + file = os.path.join(common.test_files_dir(), 'keyframes/bezier_handle_past_last_keyframe.aaf') |
| 57 | + # these values are transcribed by hand from media composer |
| 58 | + expected_result = { |
| 59 | + 0: 0.0, |
| 60 | + 1: 40.2, |
| 61 | + 2: 79.92, |
| 62 | + 3: 119.09, |
| 63 | + 4: 157.63, |
| 64 | + 5: 195.45, |
| 65 | + 6: 232.43, |
| 66 | + 7: 268.39, |
| 67 | + 8: 303.14, |
| 68 | + 9: 336.38, |
| 69 | + 10: 367.72, |
| 70 | + 11: 396.57, |
| 71 | + 12: 422.01, |
| 72 | + 13: 442.48, |
| 73 | + 14: 454.99, |
| 74 | + 15: 452.45, |
| 75 | + 16: 409.92, |
| 76 | + 17: 227.30, |
| 77 | + 18: 107.82, |
| 78 | + 19: 55.0, |
| 79 | + 20: 26.25, |
| 80 | + 21: 10.24, |
| 81 | + 22: 2.3, |
| 82 | + 23: 0.0, |
| 83 | + } |
| 84 | + with aaf2.open(file) as f: |
| 85 | + # Grab the Y position parameter from this AAF |
| 86 | + op_group = next(f.content.compositionmobs()).slots[8].segment.components[1] |
| 87 | + param_y_pos = next( |
| 88 | + param for param in op_group.parameters |
| 89 | + if isinstance(param, aaf2.misc.VaryingValue) |
| 90 | + and param.name == "DVE_POS_Y_U" |
| 91 | + ) |
| 92 | + self.compare_interpolated_values(param_y_pos, expected_result) |
| 93 | + |
| 94 | + def compare_interpolated_values(self, parameter, expected_values): |
| 95 | + # Generate the interpolated values |
| 96 | + for frame_num, expected_value in expected_values.items(): |
| 97 | + actual_value = parameter.value_at(frame_num) |
| 98 | + difference = abs(actual_value - expected_value) |
| 99 | + assert difference < KEYFRAME_VALUE_MARGIN_OF_ERROR, \ |
| 100 | + "Expected value of {:.02f} for frame {} but got {:.02f}. Difference: {:.02f}".format( |
| 101 | + expected_value, frame_num, actual_value, difference |
| 102 | + ) |
0 commit comments