|
6 | 6 | from unittest.mock import patch |
7 | 7 |
|
8 | 8 | from videomerge.models import Canvas, CodecPlan, Orientation, ToolPaths, VideoFile |
9 | | -from videomerge.transcode import build_video_filter, preprocess_file |
| 9 | +from videomerge.transcode import build_video_filter, preprocess_file, validate_preprocessed_output |
10 | 10 |
|
11 | 11 |
|
12 | 12 | class TranscodeRotationTests(unittest.TestCase): |
@@ -58,9 +58,62 @@ def fake_run_command(args, logger, dry_run=False): # type: ignore[no-untyped-de |
58 | 58 | ) |
59 | 59 |
|
60 | 60 | self.assertLess(captured_args.index("-noautorotate"), captured_args.index("-i")) |
| 61 | + self.assertLess(captured_args.index("-display_rotation:v:0"), captured_args.index("-i")) |
| 62 | + self.assertEqual(captured_args[captured_args.index("-display_rotation:v:0") + 1], "0") |
61 | 63 | self.assertIn("transpose=1", captured_args[captured_args.index("-vf") + 1]) |
62 | 64 | self.assertEqual(captured_args[captured_args.index("-metadata:s:v:0") + 1], "rotate=0") |
63 | 65 |
|
| 66 | + def test_validation_requires_canvas_display_size_and_zero_rotation(self) -> None: |
| 67 | + source = _rotated_video() |
| 68 | + output = _rotated_video().__class__( |
| 69 | + path=Path("out.mp4"), |
| 70 | + container="mp4", |
| 71 | + video_codec="h264", |
| 72 | + audio_codec="aac", |
| 73 | + width=720, |
| 74 | + height=1280, |
| 75 | + display_width=720, |
| 76 | + display_height=1280, |
| 77 | + aspect_ratio="720:1280", |
| 78 | + frame_rate="30/1", |
| 79 | + frame_rate_float=30.0, |
| 80 | + pixel_format="yuv420p", |
| 81 | + duration=32.55, |
| 82 | + has_audio=True, |
| 83 | + orientation=Orientation.portrait, |
| 84 | + rotation=0, |
| 85 | + ) |
| 86 | + |
| 87 | + with patch("videomerge.transcode.probe_file", return_value=output): |
| 88 | + validate_preprocessed_output( |
| 89 | + Path("out.mp4"), |
| 90 | + source, |
| 91 | + Canvas(720, 1280), |
| 92 | + ToolPaths(ffmpeg=Path("ffmpeg"), ffprobe=Path("ffprobe")), |
| 93 | + logging.getLogger("test"), |
| 94 | + ) |
| 95 | + |
64 | 96 |
|
65 | 97 | if __name__ == "__main__": |
66 | 98 | unittest.main() |
| 99 | + |
| 100 | + |
| 101 | +def _rotated_video() -> VideoFile: |
| 102 | + return VideoFile( |
| 103 | + path=Path("11.MP4"), |
| 104 | + container="mp4", |
| 105 | + video_codec="h264", |
| 106 | + audio_codec="aac", |
| 107 | + width=1280, |
| 108 | + height=720, |
| 109 | + display_width=720, |
| 110 | + display_height=1280, |
| 111 | + aspect_ratio="720:1280", |
| 112 | + frame_rate="88830000/2959519", |
| 113 | + frame_rate_float=30.015, |
| 114 | + pixel_format="yuv420p", |
| 115 | + duration=32.55, |
| 116 | + has_audio=True, |
| 117 | + orientation=Orientation.portrait, |
| 118 | + rotation=90, |
| 119 | + ) |
0 commit comments