Video#
Video
#
Class that provides a simple and pythonic way to interact with video.
It returns regular OpenCV frames which enables the usage of the huge number of tools OpenCV provides to modify images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
camera |
Optional[int]
|
An integer representing the device id of the camera to be used as the video source. Webcams tend to have an id of |
None
|
input_path |
Optional[str]
|
A string consisting of the path to the video file to be used as the video source. Arguments |
None
|
output_path |
str
|
The path to the output video to be generated. Can be a folder were the file will be created or a full path with a file name. |
'.'
|
output_fps |
Optional[float]
|
The frames per second at which to encode the output video file. If not provided it is set to be equal to the input video source's fps. This argument is useful when using live video cameras as a video source, where the user may know the input fps, but where the frames are being fed to the output video at a rate that is lower than the video source's fps, due to the latency added by the detector. |
None
|
label |
str
|
Label to add to the progress bar that appears when processing the current video. |
''
|
output_fourcc |
Optional[str]
|
OpenCV encoding for output video file.
By default we use |
None
|
output_extension |
str
|
File extension used for the output video. Ignored if |
'mp4'
|
Examples:
>>> video = Video(input_path="video.mp4")
>>> for frame in video:
>>> # << Your modifications to the frame would go here >>
>>> video.write(frame)
Source code in norfair/video.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
write(frame)
#
Write one frame to the output video.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
ndarray
|
The OpenCV frame to write to file. |
required |
Returns:
Type | Description |
---|---|
int
|
description |
Source code in norfair/video.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
show(frame, downsample_ratio=1.0)
#
Display a frame through a GUI. Usually used inside a video inference loop to show the output video.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
ndarray
|
The OpenCV frame to be displayed. |
required |
downsample_ratio |
float
|
How much to downsample the frame being show. Useful when streaming the GUI video display through a slow internet connection using something like X11 forwarding on an ssh connection. |
1.0
|
Returns:
Type | Description |
---|---|
int
|
description |
Source code in norfair/video.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
get_output_file_path()
#
Calculate the output path being used in case you are writing your frames to a video file.
Useful if you didn't set output_path
, and want to know what the autogenerated output file path by Norfair will be.
Returns:
Type | Description |
---|---|
str
|
The path to the file. |
Source code in norfair/video.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
abbreviate_description(description)
#
Conditionally abbreviate description so that progress bar fits in small terminals
Source code in norfair/video.py
286 287 288 289 290 291 292 293 294 295 296 297 298 |
|