vidstats 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vidstats-0.1.0/.gitignore +6 -0
- vidstats-0.1.0/LICENSE +21 -0
- vidstats-0.1.0/PKG-INFO +143 -0
- vidstats-0.1.0/README.md +117 -0
- vidstats-0.1.0/pyproject.toml +67 -0
- vidstats-0.1.0/src/vidstats/__init__.py +16 -0
- vidstats-0.1.0/src/vidstats/cli.py +260 -0
- vidstats-0.1.0/src/vidstats/hwaccel.py +31 -0
- vidstats-0.1.0/src/vidstats/metrics.py +80 -0
- vidstats-0.1.0/src/vidstats/output.py +94 -0
- vidstats-0.1.0/src/vidstats/parse.py +87 -0
- vidstats-0.1.0/src/vidstats/probe.py +138 -0
- vidstats-0.1.0/tests/test_metrics.py +73 -0
- vidstats-0.1.0/tests/test_output.py +96 -0
- vidstats-0.1.0/tests/test_parse.py +117 -0
- vidstats-0.1.0/tests/test_probe.py +125 -0
vidstats-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
vidstats-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vidstats
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Extract per-frame colour and luminosity metrics from video via ffprobe signalstats.
|
|
5
|
+
Project-URL: Repository, https://github.com/roaldarbol/vidstats
|
|
6
|
+
Project-URL: Issues, https://github.com/roaldarbol/vidstats/issues
|
|
7
|
+
Author-email: Mikkel Roald-Arbøl <vidstats.ez7zw@passmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: colour,ffprobe,luminosity,signalstats,video
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Multimedia :: Video
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: polars>=0.20
|
|
23
|
+
Requires-Dist: typer>=0.9
|
|
24
|
+
Requires-Dist: typing-extensions>=4.0
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# vidstats
|
|
28
|
+
|
|
29
|
+
Extract per-frame colour and luminosity metrics from video using
|
|
30
|
+
[ffprobe's `signalstats` filter](https://ffmpeg.org/ffmpeg-filters.html#signalstats).
|
|
31
|
+
Output goes to Parquet, CSV, IPC/Feather, or NDJSON.
|
|
32
|
+
|
|
33
|
+
Designed for research pipelines that need a fast, dependency-light way to turn
|
|
34
|
+
a video into a tabular time series — for example, non-contact cardiac monitoring
|
|
35
|
+
in animals via colour/motion video analysis.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
**pixi** (recommended — pulls in ffmpeg automatically):
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pixi global install vidstats
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**uv** (global install):
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
uv tool install vidstats
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**conda**:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
conda install -c conda-forge vidstats
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**pip** (requires ffmpeg on PATH separately):
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install vidstats
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Extract all metrics → Parquet
|
|
67
|
+
vidstats spider_abdomen.mp4 output.parquet
|
|
68
|
+
|
|
69
|
+
# Extract only luminance and saturation averages → CSV
|
|
70
|
+
vidstats spider_abdomen.mp4 output.csv --metrics YAVG,SATAVG
|
|
71
|
+
|
|
72
|
+
# Include both frame number and timestamp in seconds
|
|
73
|
+
vidstats spider_abdomen.mp4 output.parquet --timestamps both
|
|
74
|
+
|
|
75
|
+
# Override FPS when stream metadata is missing or wrong
|
|
76
|
+
vidstats spider_abdomen.mp4 output.parquet --timestamps both --fps 30
|
|
77
|
+
|
|
78
|
+
# Apply a crop region (X Y W H) before extraction
|
|
79
|
+
vidstats spider_abdomen.mp4 output.parquet --crop "10 20 180 180"
|
|
80
|
+
|
|
81
|
+
# Force format regardless of extension
|
|
82
|
+
vidstats spider_abdomen.mp4 output.dat --format csv
|
|
83
|
+
|
|
84
|
+
# Disable hardware acceleration
|
|
85
|
+
vidstats spider_abdomen.mp4 output.parquet --no-hwaccel
|
|
86
|
+
|
|
87
|
+
# List all available metric names and their output column names
|
|
88
|
+
vidstats --list-metrics
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Supported output formats
|
|
92
|
+
|
|
93
|
+
| Extension(s) | Format |
|
|
94
|
+
|--------------------------------|-----------|
|
|
95
|
+
| `.parquet` | Parquet |
|
|
96
|
+
| `.csv` | CSV |
|
|
97
|
+
| `.tsv` | TSV |
|
|
98
|
+
| `.ipc`, `.arrow`, `.feather` | Arrow IPC |
|
|
99
|
+
| `.ndjson`, `.jsonl` | NDJSON |
|
|
100
|
+
|
|
101
|
+
## Available metrics
|
|
102
|
+
|
|
103
|
+
All 25 `signalstats` metrics are extracted by default. Run
|
|
104
|
+
`vidstats --list-metrics` for the full table of ffprobe names, output column
|
|
105
|
+
names, and descriptions. They cover:
|
|
106
|
+
|
|
107
|
+
- **Luminance**: `YMIN`, `YLOW`, `YAVG`, `YHIGH`, `YMAX`
|
|
108
|
+
- **Cb chrominance (U)**: same set of five
|
|
109
|
+
- **Cr chrominance (V)**: same set of five
|
|
110
|
+
- **Saturation**: `SATMIN`, `SATLOW`, `SATAVG`, `SATHIGH`, `SATMAX`
|
|
111
|
+
- **Hue**: `HUEMED`, `HUEAVG`
|
|
112
|
+
- **Quality flags**: `TOUT`, `VREP`, `BRNG`
|
|
113
|
+
|
|
114
|
+
The `--metrics` flag accepts ffprobe names (e.g. `YAVG,SATAVG`).
|
|
115
|
+
Output columns use descriptive snake_case names (e.g. `luminance_mean`,
|
|
116
|
+
`saturation_mean`) — see `--list-metrics` for the full mapping.
|
|
117
|
+
|
|
118
|
+
## Output schema
|
|
119
|
+
|
|
120
|
+
| Column | Type | Condition |
|
|
121
|
+
|-----------|---------|------------------------------------|
|
|
122
|
+
| `frame` | UInt32 | always |
|
|
123
|
+
| `time_s` | Float64 | `--timestamps seconds` or `both` |
|
|
124
|
+
| metrics… | Float32 | selected metrics |
|
|
125
|
+
|
|
126
|
+
`time_s` is computed as `frame / fps`. FPS is read from stream metadata
|
|
127
|
+
automatically; use `--fps` to override it or supply it when metadata is absent.
|
|
128
|
+
|
|
129
|
+
## Hardware acceleration
|
|
130
|
+
|
|
131
|
+
vidstats auto-detects CUDA and passes `-hwaccel cuda` to ffprobe if available.
|
|
132
|
+
This accelerates the **decode** stage only — `signalstats` itself always runs
|
|
133
|
+
on CPU. For small (e.g. 200×200) videos the gain is negligible, but the
|
|
134
|
+
detection is there for larger inputs. Suppress with `--no-hwaccel`.
|
|
135
|
+
|
|
136
|
+
No special CUDA packages or drivers are required beyond what you already have.
|
|
137
|
+
vidstats uses ffprobe's built-in NVDEC hardware decoding, which talks directly
|
|
138
|
+
to the NVIDIA driver on your system — there is no `cudatoolkit`, no
|
|
139
|
+
`pytorch-cuda`, and no GPU-specific installation step.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
MIT
|
vidstats-0.1.0/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# vidstats
|
|
2
|
+
|
|
3
|
+
Extract per-frame colour and luminosity metrics from video using
|
|
4
|
+
[ffprobe's `signalstats` filter](https://ffmpeg.org/ffmpeg-filters.html#signalstats).
|
|
5
|
+
Output goes to Parquet, CSV, IPC/Feather, or NDJSON.
|
|
6
|
+
|
|
7
|
+
Designed for research pipelines that need a fast, dependency-light way to turn
|
|
8
|
+
a video into a tabular time series — for example, non-contact cardiac monitoring
|
|
9
|
+
in animals via colour/motion video analysis.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
**pixi** (recommended — pulls in ffmpeg automatically):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pixi global install vidstats
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**uv** (global install):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv tool install vidstats
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**conda**:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
conda install -c conda-forge vidstats
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**pip** (requires ffmpeg on PATH separately):
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install vidstats
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Extract all metrics → Parquet
|
|
41
|
+
vidstats spider_abdomen.mp4 output.parquet
|
|
42
|
+
|
|
43
|
+
# Extract only luminance and saturation averages → CSV
|
|
44
|
+
vidstats spider_abdomen.mp4 output.csv --metrics YAVG,SATAVG
|
|
45
|
+
|
|
46
|
+
# Include both frame number and timestamp in seconds
|
|
47
|
+
vidstats spider_abdomen.mp4 output.parquet --timestamps both
|
|
48
|
+
|
|
49
|
+
# Override FPS when stream metadata is missing or wrong
|
|
50
|
+
vidstats spider_abdomen.mp4 output.parquet --timestamps both --fps 30
|
|
51
|
+
|
|
52
|
+
# Apply a crop region (X Y W H) before extraction
|
|
53
|
+
vidstats spider_abdomen.mp4 output.parquet --crop "10 20 180 180"
|
|
54
|
+
|
|
55
|
+
# Force format regardless of extension
|
|
56
|
+
vidstats spider_abdomen.mp4 output.dat --format csv
|
|
57
|
+
|
|
58
|
+
# Disable hardware acceleration
|
|
59
|
+
vidstats spider_abdomen.mp4 output.parquet --no-hwaccel
|
|
60
|
+
|
|
61
|
+
# List all available metric names and their output column names
|
|
62
|
+
vidstats --list-metrics
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Supported output formats
|
|
66
|
+
|
|
67
|
+
| Extension(s) | Format |
|
|
68
|
+
|--------------------------------|-----------|
|
|
69
|
+
| `.parquet` | Parquet |
|
|
70
|
+
| `.csv` | CSV |
|
|
71
|
+
| `.tsv` | TSV |
|
|
72
|
+
| `.ipc`, `.arrow`, `.feather` | Arrow IPC |
|
|
73
|
+
| `.ndjson`, `.jsonl` | NDJSON |
|
|
74
|
+
|
|
75
|
+
## Available metrics
|
|
76
|
+
|
|
77
|
+
All 25 `signalstats` metrics are extracted by default. Run
|
|
78
|
+
`vidstats --list-metrics` for the full table of ffprobe names, output column
|
|
79
|
+
names, and descriptions. They cover:
|
|
80
|
+
|
|
81
|
+
- **Luminance**: `YMIN`, `YLOW`, `YAVG`, `YHIGH`, `YMAX`
|
|
82
|
+
- **Cb chrominance (U)**: same set of five
|
|
83
|
+
- **Cr chrominance (V)**: same set of five
|
|
84
|
+
- **Saturation**: `SATMIN`, `SATLOW`, `SATAVG`, `SATHIGH`, `SATMAX`
|
|
85
|
+
- **Hue**: `HUEMED`, `HUEAVG`
|
|
86
|
+
- **Quality flags**: `TOUT`, `VREP`, `BRNG`
|
|
87
|
+
|
|
88
|
+
The `--metrics` flag accepts ffprobe names (e.g. `YAVG,SATAVG`).
|
|
89
|
+
Output columns use descriptive snake_case names (e.g. `luminance_mean`,
|
|
90
|
+
`saturation_mean`) — see `--list-metrics` for the full mapping.
|
|
91
|
+
|
|
92
|
+
## Output schema
|
|
93
|
+
|
|
94
|
+
| Column | Type | Condition |
|
|
95
|
+
|-----------|---------|------------------------------------|
|
|
96
|
+
| `frame` | UInt32 | always |
|
|
97
|
+
| `time_s` | Float64 | `--timestamps seconds` or `both` |
|
|
98
|
+
| metrics… | Float32 | selected metrics |
|
|
99
|
+
|
|
100
|
+
`time_s` is computed as `frame / fps`. FPS is read from stream metadata
|
|
101
|
+
automatically; use `--fps` to override it or supply it when metadata is absent.
|
|
102
|
+
|
|
103
|
+
## Hardware acceleration
|
|
104
|
+
|
|
105
|
+
vidstats auto-detects CUDA and passes `-hwaccel cuda` to ffprobe if available.
|
|
106
|
+
This accelerates the **decode** stage only — `signalstats` itself always runs
|
|
107
|
+
on CPU. For small (e.g. 200×200) videos the gain is negligible, but the
|
|
108
|
+
detection is there for larger inputs. Suppress with `--no-hwaccel`.
|
|
109
|
+
|
|
110
|
+
No special CUDA packages or drivers are required beyond what you already have.
|
|
111
|
+
vidstats uses ffprobe's built-in NVDEC hardware decoding, which talks directly
|
|
112
|
+
to the NVIDIA driver on your system — there is no `cudatoolkit`, no
|
|
113
|
+
`pytorch-cuda`, and no GPU-specific installation step.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vidstats"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Extract per-frame colour and luminosity metrics from video via ffprobe signalstats."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Mikkel Roald-Arbøl", email = "vidstats.ez7zw@passmail.com" }]
|
|
14
|
+
keywords = ["video", "colour", "luminosity", "ffprobe", "signalstats"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
25
|
+
"Topic :: Multimedia :: Video",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"typer>=0.9",
|
|
29
|
+
"polars>=0.20",
|
|
30
|
+
"typing_extensions>=4.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
vidstats = "vidstats.cli:cli"
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Repository = "https://github.com/roaldarbol/vidstats"
|
|
38
|
+
Issues = "https://github.com/roaldarbol/vidstats/issues"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["src/vidstats"]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.sdist]
|
|
44
|
+
include = ["src/", "tests/", "README.md", "LICENSE"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
line-length = 100
|
|
48
|
+
target-version = "py310"
|
|
49
|
+
|
|
50
|
+
[tool.ruff.lint]
|
|
51
|
+
select = ["E", "F", "I", "UP"]
|
|
52
|
+
|
|
53
|
+
[tool.mypy]
|
|
54
|
+
python_version = "3.10"
|
|
55
|
+
strict = true
|
|
56
|
+
ignore_missing_imports = true
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
testpaths = ["tests"]
|
|
60
|
+
|
|
61
|
+
[dependency-groups]
|
|
62
|
+
dev = [
|
|
63
|
+
"pytest>=9.0",
|
|
64
|
+
"pytest-cov",
|
|
65
|
+
"ruff",
|
|
66
|
+
"mypy",
|
|
67
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .metrics import ALL_METRICS, COLUMN_NAMES, METRIC_DESCRIPTIONS
|
|
4
|
+
from .parse import parse
|
|
5
|
+
from .probe import build_command, run
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
__all__ = [
|
|
9
|
+
"__version__",
|
|
10
|
+
"ALL_METRICS",
|
|
11
|
+
"COLUMN_NAMES",
|
|
12
|
+
"METRIC_DESCRIPTIONS",
|
|
13
|
+
"build_command",
|
|
14
|
+
"run",
|
|
15
|
+
"parse",
|
|
16
|
+
]
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Annotated, Optional
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from .hwaccel import detect_hwaccel
|
|
10
|
+
from .metrics import ALL_METRICS, COLUMN_NAMES, METRIC_DESCRIPTIONS, validate_metrics
|
|
11
|
+
from .output import SUPPORTED_FORMATS, infer_format, write
|
|
12
|
+
from .parse import parse
|
|
13
|
+
from .probe import FFprobeError, FFprobeNotFoundError, build_command, get_fps, run
|
|
14
|
+
|
|
15
|
+
app = typer.Typer(
|
|
16
|
+
name="vidstats",
|
|
17
|
+
help=(
|
|
18
|
+
"Extract per-frame colour and luminosity metrics from a video "
|
|
19
|
+
"using ffprobe's signalstats filter."
|
|
20
|
+
),
|
|
21
|
+
add_completion=True,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TimestampMode(str, Enum):
|
|
26
|
+
frames = "frames"
|
|
27
|
+
seconds = "seconds"
|
|
28
|
+
both = "both"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _echo_err(msg: str) -> None:
|
|
32
|
+
typer.echo(msg, err=True)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _abort(msg: str) -> None:
|
|
36
|
+
_echo_err(f"Error: {msg}")
|
|
37
|
+
raise typer.Exit(code=1)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _list_metrics_callback(value: bool | None) -> None:
|
|
41
|
+
if not value:
|
|
42
|
+
return
|
|
43
|
+
ffprobe_w = max(len(m) for m in ALL_METRICS)
|
|
44
|
+
col_w = max(len(COLUMN_NAMES[m]) for m in ALL_METRICS)
|
|
45
|
+
header = f" {'ffprobe name':<{ffprobe_w}} {'output column':<{col_w}} description"
|
|
46
|
+
typer.echo(header)
|
|
47
|
+
typer.echo(" " + "-" * (ffprobe_w + col_w + len(" description") + 4))
|
|
48
|
+
for m in ALL_METRICS:
|
|
49
|
+
typer.echo(
|
|
50
|
+
f" {m:<{ffprobe_w}} {COLUMN_NAMES[m]:<{col_w}} {METRIC_DESCRIPTIONS[m]}"
|
|
51
|
+
)
|
|
52
|
+
raise typer.Exit()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@app.command()
|
|
56
|
+
def main(
|
|
57
|
+
input: Annotated[
|
|
58
|
+
Path,
|
|
59
|
+
typer.Argument(help="Input video file."),
|
|
60
|
+
],
|
|
61
|
+
output: Annotated[
|
|
62
|
+
Path,
|
|
63
|
+
typer.Argument(
|
|
64
|
+
help=(
|
|
65
|
+
"Output file. Format is inferred from the extension "
|
|
66
|
+
f"({', '.join(sorted({'.parquet', '.csv', '.tsv', '.ipc', '.arrow', '.feather', '.ndjson', '.jsonl'}))})."
|
|
67
|
+
)
|
|
68
|
+
),
|
|
69
|
+
],
|
|
70
|
+
metrics: Annotated[
|
|
71
|
+
Optional[str],
|
|
72
|
+
typer.Option(
|
|
73
|
+
"--metrics", "-m",
|
|
74
|
+
help=(
|
|
75
|
+
"Comma-separated list of signalstats metrics to extract "
|
|
76
|
+
"(e.g. YAVG,UAVG,SATAVG). Defaults to all metrics. "
|
|
77
|
+
"Run --list-metrics to see available names."
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
] = None,
|
|
81
|
+
crop: Annotated[
|
|
82
|
+
Optional[str],
|
|
83
|
+
typer.Option(
|
|
84
|
+
"--crop",
|
|
85
|
+
help=(
|
|
86
|
+
"Crop region applied before metric extraction, as 'X Y W H' "
|
|
87
|
+
"(top-left pixel coordinates and dimensions, space-separated)."
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
] = None,
|
|
91
|
+
timestamps: Annotated[
|
|
92
|
+
TimestampMode,
|
|
93
|
+
typer.Option(
|
|
94
|
+
"--timestamps", "-t",
|
|
95
|
+
help=(
|
|
96
|
+
"Timestamp columns to include: "
|
|
97
|
+
"'frames' (zero-based integer, default), "
|
|
98
|
+
"'seconds' (float, requires FPS), or "
|
|
99
|
+
"'both'."
|
|
100
|
+
),
|
|
101
|
+
),
|
|
102
|
+
] = TimestampMode.frames,
|
|
103
|
+
fps: Annotated[
|
|
104
|
+
Optional[float],
|
|
105
|
+
typer.Option(
|
|
106
|
+
"--fps",
|
|
107
|
+
help=(
|
|
108
|
+
"Override frame rate (frames per second) used to compute time_s. "
|
|
109
|
+
"If not provided, FPS is read from the video stream metadata. "
|
|
110
|
+
"Only relevant when --timestamps is 'seconds' or 'both'."
|
|
111
|
+
),
|
|
112
|
+
),
|
|
113
|
+
] = None,
|
|
114
|
+
hwaccel: Annotated[
|
|
115
|
+
Optional[str],
|
|
116
|
+
typer.Option(
|
|
117
|
+
"--hwaccel",
|
|
118
|
+
help=(
|
|
119
|
+
"Hardware acceleration backend for decoding (e.g. 'cuda'). "
|
|
120
|
+
"Auto-detected by default. Only affects the decode stage."
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
] = None,
|
|
124
|
+
no_hwaccel: Annotated[
|
|
125
|
+
bool,
|
|
126
|
+
typer.Option("--no-hwaccel", help="Disable hardware acceleration entirely."),
|
|
127
|
+
] = False,
|
|
128
|
+
format: Annotated[
|
|
129
|
+
Optional[str],
|
|
130
|
+
typer.Option(
|
|
131
|
+
"--format", "-f",
|
|
132
|
+
help=(
|
|
133
|
+
f"Override output format ({', '.join(SUPPORTED_FORMATS)}). "
|
|
134
|
+
"Useful when the output extension does not match the desired format."
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
] = None,
|
|
138
|
+
list_metrics: Annotated[
|
|
139
|
+
Optional[bool],
|
|
140
|
+
typer.Option(
|
|
141
|
+
"--list-metrics",
|
|
142
|
+
help="Print all available metric names and exit.",
|
|
143
|
+
is_eager=True,
|
|
144
|
+
callback=_list_metrics_callback,
|
|
145
|
+
),
|
|
146
|
+
] = None,
|
|
147
|
+
) -> None:
|
|
148
|
+
|
|
149
|
+
# --- validate input file ---
|
|
150
|
+
if not input.exists():
|
|
151
|
+
_abort(f"Input file not found: '{input}'.")
|
|
152
|
+
if not input.is_file():
|
|
153
|
+
_abort(f"Input path is not a file: '{input}'.")
|
|
154
|
+
|
|
155
|
+
# --- validate fps if provided ---
|
|
156
|
+
if fps is not None and fps <= 0:
|
|
157
|
+
_abort("--fps must be a positive number.")
|
|
158
|
+
|
|
159
|
+
# --- resolve metrics ---
|
|
160
|
+
if metrics:
|
|
161
|
+
selected = [m.strip().upper() for m in metrics.split(",") if m.strip()]
|
|
162
|
+
invalid = validate_metrics(selected)
|
|
163
|
+
if invalid:
|
|
164
|
+
_abort(
|
|
165
|
+
f"Unknown metric(s): {', '.join(invalid)}. "
|
|
166
|
+
f"Run --list-metrics to see valid names."
|
|
167
|
+
)
|
|
168
|
+
else:
|
|
169
|
+
selected = ALL_METRICS
|
|
170
|
+
|
|
171
|
+
# --- resolve crop ---
|
|
172
|
+
crop_tuple: tuple[int, int, int, int] | None = None
|
|
173
|
+
if crop is not None:
|
|
174
|
+
try:
|
|
175
|
+
parts = [int(v) for v in crop.split()]
|
|
176
|
+
if len(parts) != 4:
|
|
177
|
+
raise ValueError
|
|
178
|
+
if any(v < 0 for v in parts):
|
|
179
|
+
raise ValueError
|
|
180
|
+
crop_tuple = (parts[0], parts[1], parts[2], parts[3])
|
|
181
|
+
except ValueError:
|
|
182
|
+
_abort("--crop must be four non-negative integers: 'X Y W H'.")
|
|
183
|
+
|
|
184
|
+
# --- resolve output format ---
|
|
185
|
+
try:
|
|
186
|
+
fmt = infer_format(output, format)
|
|
187
|
+
except ValueError as exc:
|
|
188
|
+
_abort(str(exc))
|
|
189
|
+
return # unreachable, satisfies type checker
|
|
190
|
+
|
|
191
|
+
# --- resolve hardware acceleration ---
|
|
192
|
+
resolved_hwaccel: str | None
|
|
193
|
+
if no_hwaccel:
|
|
194
|
+
resolved_hwaccel = None
|
|
195
|
+
elif hwaccel:
|
|
196
|
+
resolved_hwaccel = hwaccel
|
|
197
|
+
_echo_err(f"Hardware acceleration: {resolved_hwaccel} (user-specified).")
|
|
198
|
+
else:
|
|
199
|
+
resolved_hwaccel = detect_hwaccel()
|
|
200
|
+
if resolved_hwaccel:
|
|
201
|
+
_echo_err(f"Hardware acceleration: {resolved_hwaccel} (auto-detected).")
|
|
202
|
+
|
|
203
|
+
# --- resolve fps for time_s column ---
|
|
204
|
+
resolved_fps: float | None = None
|
|
205
|
+
want_seconds = timestamps in (TimestampMode.seconds, TimestampMode.both)
|
|
206
|
+
if want_seconds:
|
|
207
|
+
if fps is not None:
|
|
208
|
+
resolved_fps = fps
|
|
209
|
+
_echo_err(f"FPS: {resolved_fps} (user-specified).")
|
|
210
|
+
else:
|
|
211
|
+
resolved_fps = get_fps(input)
|
|
212
|
+
if resolved_fps is not None:
|
|
213
|
+
_echo_err(f"FPS: {resolved_fps} (from stream metadata).")
|
|
214
|
+
else:
|
|
215
|
+
_echo_err(
|
|
216
|
+
"Warning: could not determine FPS from stream metadata. "
|
|
217
|
+
"time_s column will be omitted. Use --fps to provide it manually."
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
# --- build and run ffprobe ---
|
|
221
|
+
try:
|
|
222
|
+
cmd = build_command(
|
|
223
|
+
input_path=input,
|
|
224
|
+
metrics=selected,
|
|
225
|
+
crop=crop_tuple,
|
|
226
|
+
hwaccel=resolved_hwaccel,
|
|
227
|
+
)
|
|
228
|
+
except FFprobeNotFoundError as exc:
|
|
229
|
+
_abort(str(exc))
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
_echo_err(f"Processing '{input}'...")
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
stdout = run(cmd)
|
|
236
|
+
except FFprobeError as exc:
|
|
237
|
+
_abort(str(exc))
|
|
238
|
+
return
|
|
239
|
+
|
|
240
|
+
# --- parse and write ---
|
|
241
|
+
df = parse(stdout, selected, resolved_fps)
|
|
242
|
+
|
|
243
|
+
if len(df) == 0:
|
|
244
|
+
_echo_err(
|
|
245
|
+
"Warning: no frames were extracted. "
|
|
246
|
+
"Check that the input is a valid video file."
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
_echo_err(f"Extracted {len(df)} frames, {len(df.columns)} columns.")
|
|
250
|
+
|
|
251
|
+
try:
|
|
252
|
+
write(df, output, fmt)
|
|
253
|
+
except Exception as exc:
|
|
254
|
+
_abort(f"Failed to write output: {exc}")
|
|
255
|
+
|
|
256
|
+
_echo_err(f"Written to '{output}'.")
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def cli() -> None:
|
|
260
|
+
app()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
import subprocess
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def detect_hwaccel() -> str | None:
|
|
8
|
+
"""
|
|
9
|
+
Probe ffprobe for available hardware acceleration backends.
|
|
10
|
+
|
|
11
|
+
Returns the backend name (e.g. ``"cuda"``) if CUDA is available,
|
|
12
|
+
otherwise ``None``. Only accelerates the decode stage; signalstats
|
|
13
|
+
itself runs on CPU regardless. Most useful for large or high-fps videos.
|
|
14
|
+
"""
|
|
15
|
+
if shutil.which("ffprobe") is None:
|
|
16
|
+
return None
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
result = subprocess.run(
|
|
20
|
+
["ffprobe", "-hwaccels"],
|
|
21
|
+
capture_output=True,
|
|
22
|
+
text=True,
|
|
23
|
+
timeout=5,
|
|
24
|
+
)
|
|
25
|
+
backends = result.stdout.lower().splitlines()
|
|
26
|
+
if any("cuda" in line for line in backends):
|
|
27
|
+
return "cuda"
|
|
28
|
+
except (subprocess.TimeoutExpired, FileNotFoundError, OSError):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
return None
|