Get the optimal default downscale factor based on a video's resolution (currently only the width in pixels is considered). The resulting effective width of the video will be between frame_width and 1.5 * frame_width pixels (e.g. if frame_width is 200, the range of effective widths will
(frame_width: int, effective_width: int = DEFAULT_MIN_WIDTH)
| 121 | |
| 122 | |
| 123 | def compute_downscale_factor(frame_width: int, effective_width: int = DEFAULT_MIN_WIDTH) -> float: |
| 124 | """Get the optimal default downscale factor based on a video's resolution (currently only |
| 125 | the width in pixels is considered). |
| 126 | |
| 127 | The resulting effective width of the video will be between frame_width and 1.5 * frame_width |
| 128 | pixels (e.g. if frame_width is 200, the range of effective widths will be between 200 and 300). |
| 129 | |
| 130 | Arguments: |
| 131 | frame_width: Actual width of the video frame in pixels. |
| 132 | effective_width: Desired minimum width in pixels. |
| 133 | |
| 134 | Returns: |
| 135 | int: The default downscale factor to use to achieve at least the target effective_width. |
| 136 | """ |
| 137 | assert frame_width > 0 and effective_width > 0 |
| 138 | if frame_width < effective_width: |
| 139 | return 1 |
| 140 | return frame_width / float(effective_width) |
| 141 | |
| 142 | |
| 143 | def get_scenes_from_cuts( |