capturegraph.data.load.types.video
#
VideoFile - Simple container for video path with metadata#
A simple dataclass that bundles a video path with its metadata.
Example
import capturegraph.data as cg
# Wrap a video path with its metadata
video = cg.VideoFile("recording.mov")
print(video.path) # Path("recording.mov")
print(video.duration) # 15.5 (seconds)
print(video.width) # 1920
print(video.height) # 1080
# Generate a thumbnail for Altair tooltips
thumbnail = video.tooltip(64) # base64 data URL
Notes
- Uses OpenCV for video metadata extraction
- Supports MOV and MP4 formats (as saved by iOS PVideo)
- Lazy-loads metadata on first access for efficiency
VideoFile
dataclass
#
A video file with its path and metadata.
A simple container that bundles a Path with video metadata.
Use VideoFile() to create one from a file path.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The path to the video file. |
Properties (lazy-loaded): video_type: Format type ("mov" or "mp4") duration: Video duration in seconds width: Video width in pixels height: Video height in pixels fps: Frames per second frame_count: Total number of frames
Example
video = VideoFile("recording.mov")
video.path # PosixPath('recording.mov')
video.video_type # 'mov'
video.duration # 15.5
video.width # 1920
video.height # 1080
# Extract a frame at a specific time
frame = video.frame_at(5.0) # PIL.Image at 5 seconds
# Generate thumbnail for Altair
tooltip = video.tooltip(64) # 'data:image/png;base64,...'
Source code in capturegraph-lib/capturegraph/data/load/types/video.py
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 | |
video_type
property
#
__init__(path)
#
Create a VideoFile from a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Path to the video file. |
required |
save(path)
#
Copy the video file to a new location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Destination path for the video file. |
required |
Returns:
| Type | Description |
|---|---|
VideoFile
|
New VideoFile pointing to the copied file. |
Source code in capturegraph-lib/capturegraph/data/load/types/video.py
frame_at(time_seconds=0.0)
#
Extract a frame at a specific time and return as PIL Image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_seconds
|
float
|
Time in seconds to extract frame from. Defaults to 0.0 (first frame). |
0.0
|
Returns:
| Type | Description |
|---|---|
Image
|
PIL.Image.Image: The extracted frame. |
Example
Source code in capturegraph-lib/capturegraph/data/load/types/video.py
thumbnail(max_axis=256, frame_time_seconds=0.0)
#
Generate a thumbnail from the first frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_axis
|
int
|
Maximum dimension (width or height) of the thumbnail. |
256
|
Returns:
| Type | Description |
|---|---|
Image
|
PIL.Image.Image: The thumbnail image. |
Source code in capturegraph-lib/capturegraph/data/load/types/video.py
tooltip(max_axis=64, frame_time_seconds=0.0)
#
Create a base64-encoded thumbnail for Altair/Vega tooltips.
Extracts the first frame, resizes so its largest dimension is
max_axis, then encodes as a base64 PNG data URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_axis
|
int
|
Maximum dimension (width or height) of the thumbnail. |
64
|
Returns:
| Type | Description |
|---|---|
str
|
A data URL string like "data:image/png;base64,..." that can be |
str
|
used directly in Altair/Vega tooltip specifications. |
Example
Source code in capturegraph-lib/capturegraph/data/load/types/video.py
load_video_metadata(path)
#
Load video metadata using OpenCV.