Helper Methods
Backend ¶
Bases: Enum
Selects the underlying capture backend for VideoGear:
Backend.CAMGEAR: CamGear APIBackend.PIGEAR: PiGear APIBackend.FFGEAR: FFGear API
Source code in vidgear/gears/helper.py
logger_handler() ¶
Returns the logger handler
Returns: A logger handler
Source code in vidgear/gears/helper.py
check_CV_version() ¶
Check installed OpenCV version.
Returns: OpenCV's version first bit
check_gstreamer_support(logging=False) ¶
Checks whether OpenCV is compiled with Gstreamer(>=1.0.0) support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logging | bool | enables logging for its operations | False |
Returns: A Boolean value
Source code in vidgear/gears/helper.py
get_supported_resolution(value, logging=False) ¶
Get supported resolution from given FFMPEG stream string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value | string | value to be validated | required |
logging | bool | enables logging for its operations | False |
Returns: Valid stream resolution
Source code in vidgear/gears/helper.py
dimensions_to_resolutions(value) ¶
Convert list of dimensions to list of resolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value | list | list of dimensions (e.g. | required |
Returns: list of resolutions (e.g. 360p)
Source code in vidgear/gears/helper.py
mkdir_safe(dir_path, logging=False) ¶
Safely creates directory at given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path | string | path to the directory | required |
logging | bool | enables logging for its operations | False |
Source code in vidgear/gears/helper.py
delete_ext_safe(dir_path, extensions=None, logging=False) ¶
Safely deletes files with given extensions at given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path | string | path to the directory | required |
extensions | list | list of extensions to be deleted | None |
logging | bool | enables logging for its operations | False |
Source code in vidgear/gears/helper.py
capPropId(property, logging=True) ¶
Retrieves the OpenCV property's Integer(Actual) value from string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property | string | inputs OpenCV property as string. | required |
logging | bool | enables logging for its operations | True |
Returns: Resultant integer value.
Source code in vidgear/gears/helper.py
reducer(frame=None, percentage=0, interpolation=cv2.INTER_LANCZOS4) ¶
Reduces frame size by given percentage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame | ndarray | inputs numpy array(frame). | None |
percentage | int / float | inputs size-reduction percentage. | 0 |
interpolation | int | Change resize interpolation. | INTER_LANCZOS4 |
Returns: A reduced numpy ndarray array.
Source code in vidgear/gears/helper.py
create_blank_frame(frame=None, text='', logging=False) ¶
Create blank frames of given frame size with text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame | ndarray | inputs numpy array(frame). | None |
text | str | Text to be written on frame. | '' |
Returns: A reduced numpy ndarray array.
Source code in vidgear/gears/helper.py
dict2Args(param_dict) ¶
Converts dictionary attributes to list(args).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_dict | dict | Parameters dictionary | required |
Returns: Arguments list
Source code in vidgear/gears/helper.py
get_valid_ffmpeg_path(custom_ffmpeg='', is_windows=False, ffmpeg_download_path='', logging=False) ¶
Validate the given FFmpeg path/binaries, and returns a valid FFmpeg executable path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_ffmpeg | string | path to custom FFmpeg executables | '' |
is_windows | boolean | is running on Windows OS? | False |
ffmpeg_download_path | string | FFmpeg static binaries download location (Windows only) | '' |
logging | bool | enables logging for its operations | False |
Returns: A valid FFmpeg executable path string.
Source code in vidgear/gears/helper.py
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
download_ffmpeg_binaries(path, os_windows=False, os_bit='') ¶
Generates FFmpeg Static Binaries for windows(if not available).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | path for downloading custom FFmpeg executables | required |
os_windows | boolean | is running on Windows OS? | False |
os_bit | string | 32-bit or 64-bit OS? | '' |
Returns: A valid FFmpeg executable path string.
Source code in vidgear/gears/helper.py
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | |
validate_ffmpeg(path, logging=False) ¶
Validate FFmeg Binaries. returns True if tests are passed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | absolute path of FFmpeg binaries | required |
logging | bool | enables logging for its operations | False |
Returns: A boolean value, confirming whether tests passed, or not.
Source code in vidgear/gears/helper.py
check_output(*args, **kwargs) ¶
Returns stdin output from subprocess module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args | list | tuple | arguments | () |
**kwargs | dict | keyword arguments. Also accepts | {} |
Returns: stdin output from subprocess module.
Source code in vidgear/gears/helper.py
generate_auth_certificates(path, overwrite=False, logging=False) ¶
Auto-Generates, and Auto-validates CURVE ZMQ key-pairs for NetGear API's Secure Mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | path for generating CURVE key-pairs | required |
overwrite | boolean | overwrite existing key-pairs or not? | False |
logging | bool | enables logging for its operations | False |
Returns: A valid CURVE key-pairs path as string.
Source code in vidgear/gears/helper.py
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 | |
validate_audio(path, source=None) ¶
Validates audio by retrieving audio-bitrate from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | absolute path of FFmpeg binaries | required |
source | string / list | source to be validated. | None |
Returns: A string value, confirming whether audio is present, or not?.
Source code in vidgear/gears/helper.py
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | |
extract_time(value) ¶
Extract time from give string value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value | string | string value. | required |
Returns: Time (in seconds) as integer.
Source code in vidgear/gears/helper.py
validate_video(path, video_path=None, logging=False) ¶
Validates video by retrieving resolution/size and framerate from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | absolute path of FFmpeg binaries | required |
video_path | string | absolute path to Video. | None |
logging | bool | enables logging for its operations | False |
Returns: A dictionary of retrieved Video resolution (as tuple(width, height)) and framerate (as float).
Source code in vidgear/gears/helper.py
is_valid_url(path, url=None, logging=False) ¶
Checks URL validity by testing its scheme against FFmpeg's supported protocols
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | absolute path of FFmpeg binaries | required |
url | string | URL to be validated | None |
logging | bool | enables logging for its operations | False |
Returns: A boolean value, confirming whether tests passed, or not?.
Source code in vidgear/gears/helper.py
import_dependency_safe(name, error='raise', pkg_name=None, min_version=None, custom_message=None) ¶
Imports specified dependency safely. By default(error = raise), if a dependency is missing, an ImportError with a meaningful message will be raised. Otherwise if error = log a warning will be logged and on error = silent everything will be quit. But If a dependency is present, but older than specified, an error is raised if specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | string | name of dependency to be imported. | required |
error | string | raise or Log or silent ImportError. Possible values are | 'raise' |
pkg_name | string | (Optional) package name of dependency(if different | None |
min_version | string | (Optional) required minimum version of the dependency to be imported. | None |
custom_message | string | (Optional) custom Import error message to be raised or logged. | None |
Returns: The imported module, when found and the version is correct(if specified). Otherwise None.
Raises: ImportError: If the dependency is not found or the version is older than specified.
Source code in vidgear/gears/helper.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 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 299 300 301 302 303 304 305 306 307 308 309 310 | |
get_video_bitrate(width, height, fps, bpp) ¶
Calculate optimum bitrate from resolution, framerate, bits-per-pixels values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width | int | video-width | required |
height | int | video-height | required |
fps | float | video-framerate | required |
bpp | float | bit-per-pixels value | required |
Returns: Video bitrate (in Kbps) as integer.
Source code in vidgear/gears/helper.py
check_WriteAccess(path, is_windows=False, logging=False) ¶
Checks whether given path directory has Write-Access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | absolute path of directory | required |
is_windows | boolean | is running on Windows OS? | False |
logging | bool | enables logging for its operations | False |
Returns: A boolean value, confirming whether Write-Access available, or not?.
Source code in vidgear/gears/helper.py
check_open_port(address, port=22) ¶
Checks whether specified port open at given IP address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address | string | given IP address. | required |
port | int | check if port is open at given address. | 22 |
Returns: A boolean value, confirming whether given port is open at given IP address.
Source code in vidgear/gears/helper.py
delete_file_safe(file_path) ¶
Safely deletes files at given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | string | path to the file | required |
Source code in vidgear/gears/helper.py
get_supported_demuxers(path) ¶
Find and returns FFmpeg's supported demuxers
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | absolute path of FFmpeg binaries | required |
Returns: List of supported demuxers.
Source code in vidgear/gears/helper.py
get_supported_vencoders(path) ¶
Find and returns FFmpeg's supported video encoders
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | absolute path of FFmpeg binaries | required |
Returns: List of supported encoders.
Source code in vidgear/gears/helper.py
validate_auth_keys(path, extension) ¶
Validates, and also maintains generated ZMQ CURVE Key-pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | string | path of generated CURVE key-pairs | required |
extension | string | type of key-pair to be validated | required |
Returns: A boolean value, confirming whether tests passed, or not.
Source code in vidgear/gears/helper.py
run_ffmpeg(cmd, timeout=None, progress=None, cancel=None, echo=False, tail_lines=50, creationflags=0) ¶
Runs a one-shot FFmpeg command to completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd | list | complete FFmpeg command (binary path included). | required |
timeout | float | seconds before FFmpeg is stopped and | None |
progress | callable | called as | None |
cancel | Event | when set, FFmpeg is stopped and its returncode returned ( | None |
echo | bool | mirror FFmpeg's | False |
tail_lines | int | number of trailing | 50 |
creationflags | int | forwarded to | 0 |
Returns: CompletedProcess(cmd, returncode, None, stderr_tail). Raises sp.TimeoutExpired (with .stderr set to the tail) when timeout elapses.
Source code in vidgear/gears/helper.py