|
1 | 1 | import pytest |
2 | 2 |
|
3 | 3 | from dlclivegui.config import ( |
| 4 | + DEFAULT_RECORDING_FPS, |
4 | 5 | ApplicationSettings, |
5 | 6 | CameraSettings, |
6 | 7 | CameraTriggerSettings, |
7 | 8 | MultiCameraSettings, |
8 | 9 | RecordingSettings, |
9 | 10 | ) |
| 11 | +from dlclivegui.services.video_recorder import build_writegear_options |
10 | 12 |
|
11 | 13 |
|
12 | 14 | @pytest.mark.unit |
@@ -76,43 +78,82 @@ def test_trigger_source_defaults_to_auto(): |
76 | 78 | assert trigger.source == "auto" |
77 | 79 |
|
78 | 80 |
|
79 | | -def test_recording_settings_writegear_options_default(): |
80 | | - settings = RecordingSettings(codec="libx264", crf=23, fast_encoding=False) |
| 81 | +def test_build_writegear_options_default(): |
| 82 | + settings = RecordingSettings( |
| 83 | + codec="libx264", |
| 84 | + crf=23, |
| 85 | + fast_encoding=False, |
| 86 | + ) |
81 | 87 |
|
82 | | - opts = settings.writegear_options(100.0) |
| 88 | + opts = build_writegear_options( |
| 89 | + frame_rate=100.0, |
| 90 | + codec=settings.codec, |
| 91 | + crf=settings.crf, |
| 92 | + overrides=settings.writegear_overrides(), |
| 93 | + ) |
83 | 94 |
|
84 | | - assert opts["-input_framerate"] == "100.000000" |
85 | | - assert opts["-vcodec"] == "libx264" |
86 | | - assert opts["-crf"] == "23" |
87 | | - assert "-preset" not in opts |
88 | | - assert "-tune" not in opts |
| 95 | + assert opts == { |
| 96 | + "-input_framerate": 100.0, |
| 97 | + "-vcodec": "libx264", |
| 98 | + "-crf": 23, |
| 99 | + } |
89 | 100 |
|
90 | 101 |
|
91 | | -def test_recording_settings_writegear_options_fast_encoding_x264(): |
92 | | - settings = RecordingSettings(codec="libx264", crf=23, fast_encoding=True) |
| 102 | +def test_build_writegear_options_fast_encoding_x264(): |
| 103 | + settings = RecordingSettings( |
| 104 | + codec="libx264", |
| 105 | + crf=23, |
| 106 | + fast_encoding=True, |
| 107 | + ) |
93 | 108 |
|
94 | | - opts = settings.writegear_options(100.0) |
| 109 | + opts = build_writegear_options( |
| 110 | + frame_rate=100.0, |
| 111 | + codec=settings.codec, |
| 112 | + crf=settings.crf, |
| 113 | + overrides=settings.writegear_overrides(), |
| 114 | + ) |
95 | 115 |
|
96 | | - assert opts["-input_framerate"] == "100.000000" |
97 | | - assert opts["-vcodec"] == "libx264" |
98 | | - assert opts["-crf"] == "23" |
99 | | - assert opts["-preset"] == "ultrafast" |
100 | | - assert opts["-tune"] == "zerolatency" |
| 116 | + assert opts == { |
| 117 | + "-input_framerate": 100.0, |
| 118 | + "-vcodec": "libx264", |
| 119 | + "-crf": 23, |
| 120 | + "-preset": "ultrafast", |
| 121 | + "-tune": "zerolatency", |
| 122 | + } |
101 | 123 |
|
102 | 124 |
|
103 | | -def test_recording_settings_writegear_options_fast_encoding_nvenc_no_x264_options(): |
104 | | - settings = RecordingSettings(codec="h264_nvenc", crf=23, fast_encoding=True) |
| 125 | +def test_build_writegear_options_fast_encoding_nvenc(): |
| 126 | + settings = RecordingSettings( |
| 127 | + codec="h264_nvenc", |
| 128 | + crf=23, |
| 129 | + fast_encoding=True, |
| 130 | + ) |
105 | 131 |
|
106 | | - opts = settings.writegear_options(100.0) |
| 132 | + opts = build_writegear_options( |
| 133 | + frame_rate=100.0, |
| 134 | + codec=settings.codec, |
| 135 | + crf=settings.crf, |
| 136 | + overrides=settings.writegear_overrides(), |
| 137 | + ) |
107 | 138 |
|
| 139 | + assert opts["-input_framerate"] == 100.0 |
108 | 140 | assert opts["-vcodec"] == "h264_nvenc" |
| 141 | + assert opts["-crf"] == 23 |
109 | 142 | assert "-preset" not in opts |
110 | 143 | assert "-tune" not in opts |
111 | 144 |
|
112 | 145 |
|
113 | | -def test_recording_settings_writegear_options_invalid_fps_falls_back_to_30(): |
114 | | - settings = RecordingSettings(codec="libx264", crf=23) |
| 146 | +def test_build_writegear_options_invalid_fps_uses_default(): |
| 147 | + settings = RecordingSettings( |
| 148 | + codec="libx264", |
| 149 | + crf=23, |
| 150 | + ) |
115 | 151 |
|
116 | | - opts = settings.writegear_options(None) |
| 152 | + opts = build_writegear_options( |
| 153 | + frame_rate=None, |
| 154 | + codec=settings.codec, |
| 155 | + crf=settings.crf, |
| 156 | + overrides=settings.writegear_overrides(), |
| 157 | + ) |
117 | 158 |
|
118 | | - assert opts["-input_framerate"] == "30.000000" |
| 159 | + assert opts["-input_framerate"] == DEFAULT_RECORDING_FPS |
0 commit comments