# video-fft
[![PyPI version](https://img.shields.io/pypi/v/video-fft.svg)](https://pypi.org/project/video-fft)
[![Python package](https://github.com/slhck/video-fft/actions/workflows/python-package.yml/badge.svg)](https://github.com/slhck/video-fft/actions/workflows/python-package.yml)
Calculate the magnitude spectrum of a video sequence, via Fast Fourier Transform, to detect the actual resolution.
**Contents:**
- [What this does](#what-this-does)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [Limitations](#limitations)
- [Acknowledgements](#acknowledgements)
- [License](#license)
## What this does
The package calculates the magnitude spectrum of each frame's luminance data.
This allows, for example, identifying upscaled parts of a video, such as when someone upscaled HD content to UHD. By analyzing the spectrum, you can see that the actual high frequencies that would be expected for "real" UHD content are not present, or not as present as you'd normally see.
![](example.png)
The above example shows three sources (each source is one row), with the left image corresponding to the HD version of the source, upscaled to UHD, and the right image being the actual UHD source. The grey "boxes" in the left column tell you that the actual content is merely HD.
The package also outputs the azimuthally averaged 1D power spectrum, from which the high frequencies are extracted and summed up to give one "score" per frame.
## Requirements
- Python 3.8 or higher
- FFmpeg libraries (to run `pyav`)
Under Ubuntu, to get ffmpeg libraries:
sudo apt install libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libavfilter-dev libswscale-dev libavresample-dev
Under macOS, it is recommended to install ffmpeg via [Homebrew](https://brew.sh):
brew install ffmpeg
## Installation
```
pip3 install video-fft
```
## Usage
To run it, simply call `video-fft` with the path to your video file:
```bash
video-fft /path/to/video.mp4
```
This will output a progress bar for each frame, and finally output the statistics as JSON.
You can enable output of magnitude spectrum images via three options:
- `-r`/`--first-frame`: Only output the first frame of the video
- `-a`/`--all-frames`: Output all frames
- `-m`/`--mean`: Output an averaged magnitude spectrum for all frames
The images will be saved next to the input file, unless you choose a different output path (via `-o`/`--output`).
For more info, see `video-fft -h`:
```
usage: video-fft [-h] [-o OUTPUT] [-n NUM_FRAMES] [-of {json,csv}] [-r] [-a] [-m] [-s SCALE] [-q] input
positional arguments:
input Input video file
optional arguments:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output path for the images, default: same as input video file (default: None)
-n NUM_FRAMES, --num-frames NUM_FRAMES
Number of frames to calculate (default: None)
-of {json,csv}, --output-format {json,csv}
Select output format (default: json)
-r, --first-frame Render image for radial profile of the first frame (default: False)
-a, --all-frames Render image for radial profile of all frames (default: False)
-m, --mean Render image for mean/average radial profile of the entire sequence (default: False)
-s SCALE, --scale SCALE
Image scaling, adjust to increase/decrease rendered image size (default: 1)
-q, --quiet Do not show progress bar (default: False)
```
## API
The program exposes an API that you can use yourself:
```python
from video_fft import VideoFftCalculator
vid_fft = VideoFftCalculator(
"input.mp4",
output="/path/to/output"
)
vid_fft.calc_fft()
print(vid_fft.get_formatted_stats())
```
For more usage please read [the docs](https://htmlpreview.github.io/?https://github.com/slhck/video-fft/blob/master/docs/video_fft.html).
## Limitations
The absolute value of the FFT is not meaningful on its own and cannot be linked to the resolution of the input video. The plots also do not indicate any kind of resolution.
## Acknowledgements
This tool is based on initial work from Julian Zebelein and Steve Göring (TU Ilmenau).
The concept is based on the following paper: Katsavounidis, Ioannis, Anne Aaron, and David Ronca. "Native resolution detection of video sequences." SMPTE 2015 Annual Technical Conference And Exhibition. SMPTE, 2015.
## License
The MIT License (MIT)
Copyright (c) 2021-2023 Werner Robitza
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Changelog
## v0.3.0 (2023-01-10)
* Various improvements.
add API, types, github workflows
## v0.2.0 (2022-08-02)
* Fix version variable name.
* Update python requirements.
* Fix pip install command.
* Fix badge link.
## v0.1.0 (2021-05-08)
* Initial commit.
Raw data
{
"_id": null,
"home_page": "https://github.com/slhck/video-fft",
"name": "video-fft",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "ffmpeg,video",
"author": "Werner Robitza",
"author_email": "werner.robitza@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e0/cc/bdf07c798454dc85be10e282fd2e994ab7c6954a0a3d77c12e91f383047b/video_fft-0.3.0.tar.gz",
"platform": null,
"description": "# video-fft\n\n[![PyPI version](https://img.shields.io/pypi/v/video-fft.svg)](https://pypi.org/project/video-fft)\n\n[![Python package](https://github.com/slhck/video-fft/actions/workflows/python-package.yml/badge.svg)](https://github.com/slhck/video-fft/actions/workflows/python-package.yml)\n\nCalculate the magnitude spectrum of a video sequence, via Fast Fourier Transform, to detect the actual resolution.\n\n**Contents:**\n\n- [What this does](#what-this-does)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n- [Limitations](#limitations)\n- [Acknowledgements](#acknowledgements)\n- [License](#license)\n\n## What this does\n\nThe package calculates the magnitude spectrum of each frame's luminance data.\n\nThis allows, for example, identifying upscaled parts of a video, such as when someone upscaled HD content to UHD. By analyzing the spectrum, you can see that the actual high frequencies that would be expected for \"real\" UHD content are not present, or not as present as you'd normally see.\n\n![](example.png)\n\nThe above example shows three sources (each source is one row), with the left image corresponding to the HD version of the source, upscaled to UHD, and the right image being the actual UHD source. The grey \"boxes\" in the left column tell you that the actual content is merely HD.\n\nThe package also outputs the azimuthally averaged 1D power spectrum, from which the high frequencies are extracted and summed up to give one \"score\" per frame.\n\n## Requirements\n\n- Python 3.8 or higher\n- FFmpeg libraries (to run `pyav`)\n\nUnder Ubuntu, to get ffmpeg libraries:\n\n sudo apt install libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libavfilter-dev libswscale-dev libavresample-dev\n\nUnder macOS, it is recommended to install ffmpeg via [Homebrew](https://brew.sh):\n\n brew install ffmpeg\n\n## Installation\n\n```\npip3 install video-fft\n```\n\n## Usage\n\nTo run it, simply call `video-fft` with the path to your video file:\n\n```bash\nvideo-fft /path/to/video.mp4\n```\n\nThis will output a progress bar for each frame, and finally output the statistics as JSON.\n\nYou can enable output of magnitude spectrum images via three options:\n\n- `-r`/`--first-frame`: Only output the first frame of the video\n- `-a`/`--all-frames`: Output all frames\n- `-m`/`--mean`: Output an averaged magnitude spectrum for all frames\n\nThe images will be saved next to the input file, unless you choose a different output path (via `-o`/`--output`).\n\nFor more info, see `video-fft -h`:\n\n```\nusage: video-fft [-h] [-o OUTPUT] [-n NUM_FRAMES] [-of {json,csv}] [-r] [-a] [-m] [-s SCALE] [-q] input\n\npositional arguments:\n input Input video file\n\noptional arguments:\n -h, --help show this help message and exit\n -o OUTPUT, --output OUTPUT\n Output path for the images, default: same as input video file (default: None)\n -n NUM_FRAMES, --num-frames NUM_FRAMES\n Number of frames to calculate (default: None)\n -of {json,csv}, --output-format {json,csv}\n Select output format (default: json)\n -r, --first-frame Render image for radial profile of the first frame (default: False)\n -a, --all-frames Render image for radial profile of all frames (default: False)\n -m, --mean Render image for mean/average radial profile of the entire sequence (default: False)\n -s SCALE, --scale SCALE\n Image scaling, adjust to increase/decrease rendered image size (default: 1)\n -q, --quiet Do not show progress bar (default: False)\n```\n\n## API\n\nThe program exposes an API that you can use yourself:\n\n```python\nfrom video_fft import VideoFftCalculator\n\nvid_fft = VideoFftCalculator(\n \"input.mp4\",\n output=\"/path/to/output\"\n)\nvid_fft.calc_fft()\nprint(vid_fft.get_formatted_stats())\n```\n\nFor more usage please read [the docs](https://htmlpreview.github.io/?https://github.com/slhck/video-fft/blob/master/docs/video_fft.html).\n\n## Limitations\n\nThe absolute value of the FFT is not meaningful on its own and cannot be linked to the resolution of the input video. The plots also do not indicate any kind of resolution.\n\n## Acknowledgements\n\nThis tool is based on initial work from Julian Zebelein and Steve G\u00f6ring (TU Ilmenau).\n\nThe concept is based on the following paper: Katsavounidis, Ioannis, Anne Aaron, and David Ronca. \"Native resolution detection of video sequences.\" SMPTE 2015 Annual Technical Conference And Exhibition. SMPTE, 2015.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2021-2023 Werner Robitza\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n# Changelog\n\n\n## v0.3.0 (2023-01-10)\n\n* Various improvements.\n\n add API, types, github workflows\n\n\n## v0.2.0 (2022-08-02)\n\n* Fix version variable name.\n\n* Update python requirements.\n\n* Fix pip install command.\n\n* Fix badge link.\n\n\n## v0.1.0 (2021-05-08)\n\n* Initial commit.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Calculate the magnitude spectrum of a video sequence, via Fast Fourier Transform",
"version": "0.3.0",
"split_keywords": [
"ffmpeg",
"video"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e4813167c08fa86b73a97b1ff29b2dadd1aab241f84d89e520e0d363b0d12d7d",
"md5": "19aa9fe235de6f8df3714dd84f68ff72",
"sha256": "df2751fc101f8123425c114d6e1c3a18ca73e5929cb0f36319812945eb5f942e"
},
"downloads": -1,
"filename": "video_fft-0.3.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "19aa9fe235de6f8df3714dd84f68ff72",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.8",
"size": 9084,
"upload_time": "2023-01-10T08:16:19",
"upload_time_iso_8601": "2023-01-10T08:16:19.493337Z",
"url": "https://files.pythonhosted.org/packages/e4/81/3167c08fa86b73a97b1ff29b2dadd1aab241f84d89e520e0d363b0d12d7d/video_fft-0.3.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e0ccbdf07c798454dc85be10e282fd2e994ab7c6954a0a3d77c12e91f383047b",
"md5": "f697a2ba21be138d4eb1ef9aedabe784",
"sha256": "3de21a66bb61524f1dee5a918eee2207ed430058948c3eb3a1997931c6fb579b"
},
"downloads": -1,
"filename": "video_fft-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "f697a2ba21be138d4eb1ef9aedabe784",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 16308,
"upload_time": "2023-01-10T08:16:21",
"upload_time_iso_8601": "2023-01-10T08:16:21.103482Z",
"url": "https://files.pythonhosted.org/packages/e0/cc/bdf07c798454dc85be10e282fd2e994ab7c6954a0a3d77c12e91f383047b/video_fft-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-10 08:16:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "slhck",
"github_project": "video-fft",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "av",
"specs": []
},
{
"name": "tqdm",
"specs": []
},
{
"name": "numpy",
"specs": []
},
{
"name": "matplotlib",
"specs": []
}
],
"lcname": "video-fft"
}