prpy 0.2.2__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.
- prpy-0.2.2/.github/workflows/main.yml +40 -0
- prpy-0.2.2/.gitignore +132 -0
- prpy-0.2.2/LICENSE +19 -0
- prpy-0.2.2/MANIFEST.in +7 -0
- prpy-0.2.2/PKG-INFO +75 -0
- prpy-0.2.2/README.md +37 -0
- prpy-0.2.2/prpy/__init__.py +19 -0
- prpy-0.2.2/prpy/constants.py +24 -0
- prpy-0.2.2/prpy/ffmpeg/__init__.py +19 -0
- prpy-0.2.2/prpy/ffmpeg/probe.py +86 -0
- prpy-0.2.2/prpy/ffmpeg/readwrite.py +412 -0
- prpy-0.2.2/prpy/ffmpeg/utils.py +81 -0
- prpy-0.2.2/prpy/numpy/__init__.py +19 -0
- prpy-0.2.2/prpy/numpy/face.py +213 -0
- prpy-0.2.2/prpy/numpy/image.py +141 -0
- prpy-0.2.2/prpy/numpy/metric.py +179 -0
- prpy-0.2.2/prpy/numpy/signal.py +649 -0
- prpy-0.2.2/prpy/numpy/stride_tricks.py +182 -0
- prpy-0.2.2/prpy/tensorflow/__init__.py +19 -0
- prpy-0.2.2/prpy/tensorflow/image.py +203 -0
- prpy-0.2.2/prpy/tensorflow/loss.py +104 -0
- prpy-0.2.2/prpy/tensorflow/lr_schedule.py +74 -0
- prpy-0.2.2/prpy/tensorflow/model_saver.py +203 -0
- prpy-0.2.2/prpy/tensorflow/nan.py +226 -0
- prpy-0.2.2/prpy/tensorflow/optimizer.py +233 -0
- prpy-0.2.2/prpy/tensorflow/signal.py +103 -0
- prpy-0.2.2/prpy/torch/__init__.py +19 -0
- prpy-0.2.2/prpy/torch/model_saver.py +208 -0
- prpy-0.2.2/prpy.egg-info/PKG-INFO +75 -0
- prpy-0.2.2/prpy.egg-info/SOURCES.txt +43 -0
- prpy-0.2.2/prpy.egg-info/dependency_links.txt +1 -0
- prpy-0.2.2/prpy.egg-info/requires.txt +27 -0
- prpy-0.2.2/prpy.egg-info/top_level.txt +1 -0
- prpy-0.2.2/pyproject.toml +37 -0
- prpy-0.2.2/setup.cfg +4 -0
- prpy-0.2.2/setup.py +3 -0
- prpy-0.2.2/tests/conftest.py +60 -0
- prpy-0.2.2/tests/test_ffmpeg.py +91 -0
- prpy-0.2.2/tests/test_numpy_face.py +87 -0
- prpy-0.2.2/tests/test_numpy_image.py +76 -0
- prpy-0.2.2/tests/test_numpy_metric.py +63 -0
- prpy-0.2.2/tests/test_numpy_signal.py +283 -0
- prpy-0.2.2/tests/test_numpy_stride_tricks.py +64 -0
- prpy-0.2.2/tests/test_tensorflow.py +574 -0
- prpy-0.2.2/tests/test_torch.py +103 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["main"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["main"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
|
|
12
|
+
runs-on: [ubuntu-latest]
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.8", "3.9", "3.10"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
19
|
+
uses: actions/setup-python@v4
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
- name: Install ffmpeg
|
|
23
|
+
uses: Iamshankhadeep/setup-ffmpeg@v1.2
|
|
24
|
+
with:
|
|
25
|
+
version: "4.4"
|
|
26
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
27
|
+
- name: Checkout prpy
|
|
28
|
+
uses: actions/checkout@v3
|
|
29
|
+
with:
|
|
30
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
31
|
+
- name: Install prpy and dependencies
|
|
32
|
+
run: |
|
|
33
|
+
python -m pip install --upgrade pip
|
|
34
|
+
python -m pip install ".[ffmpeg,numpy,tensorflow,torch,test]"
|
|
35
|
+
- name: Lint with flake8
|
|
36
|
+
run: |
|
|
37
|
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
38
|
+
- name: Test with pytest
|
|
39
|
+
run: |
|
|
40
|
+
pytest
|
prpy-0.2.2/.gitignore
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
target/
|
|
76
|
+
|
|
77
|
+
# Jupyter Notebook
|
|
78
|
+
.ipynb_checkpoints
|
|
79
|
+
|
|
80
|
+
# IPython
|
|
81
|
+
profile_default/
|
|
82
|
+
ipython_config.py
|
|
83
|
+
|
|
84
|
+
# pyenv
|
|
85
|
+
.python-version
|
|
86
|
+
|
|
87
|
+
# pipenv
|
|
88
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
89
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
90
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
91
|
+
# install all needed dependencies.
|
|
92
|
+
#Pipfile.lock
|
|
93
|
+
|
|
94
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
95
|
+
__pypackages__/
|
|
96
|
+
|
|
97
|
+
# Celery stuff
|
|
98
|
+
celerybeat-schedule
|
|
99
|
+
celerybeat.pid
|
|
100
|
+
|
|
101
|
+
# SageMath parsed files
|
|
102
|
+
*.sage.py
|
|
103
|
+
|
|
104
|
+
# Environments
|
|
105
|
+
.env
|
|
106
|
+
.venv
|
|
107
|
+
env/
|
|
108
|
+
venv/
|
|
109
|
+
ENV/
|
|
110
|
+
env.bak/
|
|
111
|
+
venv.bak/
|
|
112
|
+
|
|
113
|
+
# Spyder project settings
|
|
114
|
+
.spyderproject
|
|
115
|
+
.spyproject
|
|
116
|
+
|
|
117
|
+
# Rope project settings
|
|
118
|
+
.ropeproject
|
|
119
|
+
|
|
120
|
+
# mkdocs documentation
|
|
121
|
+
/site
|
|
122
|
+
|
|
123
|
+
# mypy
|
|
124
|
+
.mypy_cache/
|
|
125
|
+
.dmypy.json
|
|
126
|
+
dmypy.json
|
|
127
|
+
|
|
128
|
+
# Pyre type checker
|
|
129
|
+
.pyre/
|
|
130
|
+
|
|
131
|
+
# OS X .DS_Store
|
|
132
|
+
**/.DS_Store
|
prpy-0.2.2/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2024 Philipp Rouast
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
prpy-0.2.2/MANIFEST.in
ADDED
prpy-0.2.2/PKG-INFO
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: prpy
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Collection of Python utils for signal, image, and video processing
|
|
5
|
+
Author-email: Philipp Rouast <philipp@rouast.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
Project-URL: Repository, https://github.com/prouast/prpy.git
|
|
8
|
+
Project-URL: Issues, https://github.com/prouast/prpy/issues
|
|
9
|
+
Keywords: python,numpy,ffmpeg,tensorflow,torch
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Provides-Extra: ffmpeg
|
|
18
|
+
Requires-Dist: ffmpeg-python; extra == "ffmpeg"
|
|
19
|
+
Requires-Dist: numpy; extra == "ffmpeg"
|
|
20
|
+
Provides-Extra: numpy
|
|
21
|
+
Requires-Dist: numpy; extra == "numpy"
|
|
22
|
+
Requires-Dist: scipy; extra == "numpy"
|
|
23
|
+
Requires-Dist: Pillow; extra == "numpy"
|
|
24
|
+
Requires-Dist: opencv-python; extra == "numpy"
|
|
25
|
+
Requires-Dist: scikit-learn; extra == "numpy"
|
|
26
|
+
Provides-Extra: numpy-min
|
|
27
|
+
Requires-Dist: numpy; extra == "numpy-min"
|
|
28
|
+
Requires-Dist: scipy; extra == "numpy-min"
|
|
29
|
+
Requires-Dist: Pillow; extra == "numpy-min"
|
|
30
|
+
Provides-Extra: tensorflow
|
|
31
|
+
Requires-Dist: tensorflow==2.12.1; extra == "tensorflow"
|
|
32
|
+
Requires-Dist: numpy; extra == "tensorflow"
|
|
33
|
+
Provides-Extra: torch
|
|
34
|
+
Requires-Dist: torch==2.1.0; extra == "torch"
|
|
35
|
+
Provides-Extra: test
|
|
36
|
+
Requires-Dist: pytest; extra == "test"
|
|
37
|
+
Requires-Dist: flake8; extra == "test"
|
|
38
|
+
|
|
39
|
+
[](https://github.com/prouast/prpy/actions/workflows/main.yml)
|
|
40
|
+
|
|
41
|
+
# prpy
|
|
42
|
+
|
|
43
|
+
A collection of Python utilities for signal, image, and video processing.
|
|
44
|
+
It contains subpackages for working with `numpy`, `ffmpeg`, `tensorflow`, and `torch`.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
General prerequisites are `python>=3.8` and `ffmpeg` installed and accessible via the `$PATH` environment variable.
|
|
49
|
+
|
|
50
|
+
To install `prpy` and its dependencies:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
git clone https://github.com/prouast/prpy.git
|
|
54
|
+
pip install "./prpy[ffmpeg,numpy,tensorflow,torch,test]"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The above runs a full install of all dependencies.
|
|
58
|
+
It is possible to customize the install of the dependencies by only listing the desired subpackages out of `ffmpeg`, `numpy`, `tensorflow`, `torch`, and `test` in the square brackets above.
|
|
59
|
+
|
|
60
|
+
## Linting and tests
|
|
61
|
+
|
|
62
|
+
To lint and run tests:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
66
|
+
pytest
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Build
|
|
70
|
+
|
|
71
|
+
To build:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
python -m build
|
|
75
|
+
```
|
prpy-0.2.2/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[](https://github.com/prouast/prpy/actions/workflows/main.yml)
|
|
2
|
+
|
|
3
|
+
# prpy
|
|
4
|
+
|
|
5
|
+
A collection of Python utilities for signal, image, and video processing.
|
|
6
|
+
It contains subpackages for working with `numpy`, `ffmpeg`, `tensorflow`, and `torch`.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
General prerequisites are `python>=3.8` and `ffmpeg` installed and accessible via the `$PATH` environment variable.
|
|
11
|
+
|
|
12
|
+
To install `prpy` and its dependencies:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
git clone https://github.com/prouast/prpy.git
|
|
16
|
+
pip install "./prpy[ffmpeg,numpy,tensorflow,torch,test]"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The above runs a full install of all dependencies.
|
|
20
|
+
It is possible to customize the install of the dependencies by only listing the desired subpackages out of `ffmpeg`, `numpy`, `tensorflow`, `torch`, and `test` in the square brackets above.
|
|
21
|
+
|
|
22
|
+
## Linting and tests
|
|
23
|
+
|
|
24
|
+
To lint and run tests:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
28
|
+
pytest
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Build
|
|
32
|
+
|
|
33
|
+
To build:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
python -m build
|
|
37
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (c) 2024 Philipp Rouast
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Copyright (c) 2024 Philipp Rouast
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
|
|
21
|
+
NANOS_PER_SECOND = 1000000000.0
|
|
22
|
+
MICROS_PER_SECOND = 1000000.0
|
|
23
|
+
MILLIS_PER_SECOND = 1000.0
|
|
24
|
+
SECONDS_PER_MINUTE = 60.0
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (c) 2024 Philipp Rouast
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Copyright (c) 2024 Philipp Rouast
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
|
|
21
|
+
import ffmpeg
|
|
22
|
+
from fractions import Fraction
|
|
23
|
+
import logging
|
|
24
|
+
from typing import Tuple
|
|
25
|
+
import os
|
|
26
|
+
|
|
27
|
+
def probe_video(
|
|
28
|
+
path: str
|
|
29
|
+
) -> Tuple[float, int, int, int, str, float, int]:
|
|
30
|
+
"""Probe a video file for metadata.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
path: The path of the video.
|
|
34
|
+
Returns:
|
|
35
|
+
fps: The frame rate of the video
|
|
36
|
+
total_frames: The total number of frames
|
|
37
|
+
width: The width dimension of the video
|
|
38
|
+
height: The height dimension of the video
|
|
39
|
+
codec: The codec of the video
|
|
40
|
+
bitrate: The bitrate of the video
|
|
41
|
+
rotation: The rotation of the video
|
|
42
|
+
"""
|
|
43
|
+
# Check if file exists
|
|
44
|
+
assert isinstance(path, str)
|
|
45
|
+
if not os.path.exists(path):
|
|
46
|
+
raise FileNotFoundError("File {} does not exist".format(path))
|
|
47
|
+
# ffprobe -show_streams -count_frames -pretty video.mp4
|
|
48
|
+
try:
|
|
49
|
+
probe = ffmpeg.probe(filename=path)
|
|
50
|
+
except Exception as e:
|
|
51
|
+
# The exception returned by `ffprobe` is in bytes
|
|
52
|
+
logging.warn("Exception probing video: {}".format(e))
|
|
53
|
+
else:
|
|
54
|
+
video_stream = next(
|
|
55
|
+
(
|
|
56
|
+
stream
|
|
57
|
+
for stream in probe["streams"]
|
|
58
|
+
if stream["codec_type"] == "video"
|
|
59
|
+
),
|
|
60
|
+
None,
|
|
61
|
+
)
|
|
62
|
+
try:
|
|
63
|
+
fps = float(Fraction(video_stream["avg_frame_rate"]))
|
|
64
|
+
except Exception as e:
|
|
65
|
+
fps = 0
|
|
66
|
+
try:
|
|
67
|
+
total_frames = int(video_stream["nb_frames"])
|
|
68
|
+
except Exception as e:
|
|
69
|
+
duration = float(video_stream['duration'])
|
|
70
|
+
total_frames = int(duration*fps)
|
|
71
|
+
width = video_stream["width"]
|
|
72
|
+
height = video_stream["height"]
|
|
73
|
+
codec = video_stream["codec_name"]
|
|
74
|
+
try:
|
|
75
|
+
bitrate = float(video_stream["bit_rate"])/1000.0
|
|
76
|
+
except Exception as e:
|
|
77
|
+
bitrate = 0.0
|
|
78
|
+
rotation = 0
|
|
79
|
+
if 'tags' in video_stream and 'rotate' in video_stream['tags']:
|
|
80
|
+
# Regular
|
|
81
|
+
rotation = int(video_stream['tags']['rotate'])
|
|
82
|
+
elif 'side_data_list' in video_stream and 'rotation' in video_stream['side_data_list'][0]:
|
|
83
|
+
# iPhone
|
|
84
|
+
rotation = int(video_stream['side_data_list'][0]['rotation'])
|
|
85
|
+
return fps, total_frames, width, height, codec, bitrate, rotation
|
|
86
|
+
|