ffmpeg-bitrate-stats


Nameffmpeg-bitrate-stats JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/slhck/ffmpeg-bitrate-stats
SummaryCalculate bitrate statistics using FFmpeg
upload_time2023-08-16 11:13:15
maintainer
docs_urlNone
authorWerner Robitza
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FFmpeg Bitrate Stats

[![PyPI version](https://img.shields.io/pypi/v/ffmpeg_bitrate_stats.svg)](https://pypi.org/project/ffmpeg_bitrate_stats)

[![Python package](https://github.com/slhck/ffmpeg-bitrate-stats/actions/workflows/python-package.yml/badge.svg)](https://github.com/slhck/ffmpeg-bitrate-stats/actions/workflows/python-package.yml)

Simple script for calculating bitrate statistics using FFmpeg.

Author: Werner Robitza <werner.robitza@gmail.com>

**Note:** Previous versions installed a `ffmpeg_bitrate_stats` executable. To harmonize it with other tools, now the executable is called `ffmpeg-bitrate-stats`. Please ensure you remove the old executable (e.g. run `which ffmpeg_bitrate_stats` and remove the file).

Contents:

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Output](#output)
- [Plotting](#plotting)
- [API](#api)
- [License](#license)

------

## Requirements

- Python 3.8 or higher
- FFmpeg:
    - download a static build from [their website](http://ffmpeg.org/download.html)
    - put the `ffprobe` executable in your `$PATH`

## Installation

```bash
pip3 install ffmpeg_bitrate_stats
```

Or clone this repository, then run the tool with `python -m ffmpeg_bitrate_stats`

## Usage

The script outputs a bunch of bitrate statistics, including aggregations for pre-defined windows. These windows can either be time-based or GOP-based (for video streams). When choosing a time-based window, you can specify the size of the chunks in seconds.

Output is to STDOUT so you can redirect that to a file or another script.

See `ffmpeg-bitrate-stats -h`:

```
usage: __main__.py [-h] [-n] [-v] [-s {video,audio}] [-a {time,gop}]
                   [-c CHUNK_SIZE] [-rs READ_START] [-rd READ_DURATION]
                   [-of {json,csv}] [-p] [-pw PLOT_WIDTH] [-ph PLOT_HEIGHT]
                   input

ffmpeg_bitrate_stats v1.0.2

positional arguments:
  input                 input file

options:
  -h, --help            show this help message and exit
  -n, --dry-run         Do not run command, just show what would be done
                        (default: False)
  -v, --verbose         Show verbose output (default: False)
  -s {video,audio}, --stream-type {video,audio}
                        Stream type to analyze (default: video)
  -a {time,gop}, --aggregation {time,gop}
                        Window for aggregating statistics, either time-based
                        (per-second) or per GOP (default: time)
  -c CHUNK_SIZE, --chunk-size CHUNK_SIZE
                        Custom aggregation window size in seconds (default:
                        1.0)
  -rs READ_START, --read-start READ_START
                        Time to wait before sampling video (in HH:MM:SS.msec
                        or seconds) (default: None)
  -rd READ_DURATION, --read-duration READ_DURATION
                        Duration for sampling stream (in HH:MM:SS.msec or
                        seconds). Note that seeking is not accurate, see
                        ffprobe documentation on '-read_intervals'. (default:
                        None)
  -of {json,csv}, --output-format {json,csv}
                        output in which format (default: json)
  -p, --plot            Plot the bitrate over time (to STDERR) (default:
                        False)
  -pw PLOT_WIDTH, --plot-width PLOT_WIDTH
                        Plot width (default: 70)
  -ph PLOT_HEIGHT, --plot-height PLOT_HEIGHT
                        Plot height (default: 18)
```

## Output

The output can be JSON, which includes individual fields for each chunk, or CSV, which repeats each line for each chunk. The CSV adheres to the “tidy” data concept, so it's a little redundant.

Rates are given in kilobit per second, using SI prefixes (i.e., kilo = 1000).

Explanation of the fields:

- `input_file`: Path to the input file
- `stream_type`: Type of stream used (video, audio)
- `avg_fps`: Average FPS (number of frames divided by duration)
- `num_frames`: Number of frames
- `avg_bitrate`: Average bitrate
- `avg_bitrate_over_chunks`: Average bitrate calculated over the chunks
- `max_bitrate`: Maximum bitrate calculated over the chunks
- `min_bitrate`: Minimum bitrate calculated over the chunks
- `max_bitrate_factor`: Relation between peak and average
- `bitrate_per_chunk`: Individual bitrates for each chunk
- `aggregation`: Type of aggregation used
- `chunk_size`: Size of the chunk (when aggregation is "time")
- `duration`: Total duration of the stream. It is the sum of all frame durations, where each frame's duration is either based on `duration_time` field in ffmpeg, or the difference between the current and previous frame's PTS.

JSON example:

```bash
ffmpeg-bitrate-stats -a time -c 30 -of json BigBuckBunny.mp4
```

This returns:
```json
{
    "input_file": "BigBuckBunny.mp4",
    "stream_type": "video",
    "avg_fps": 60.002,
    "num_frames": 38072,
    "avg_bitrate": 8002.859,
    "avg_bitrate_over_chunks": 7849.263,
    "max_bitrate": 14565.117,
    "min_bitrate": 3876.533,
    "max_bitrate_factor": 1.82,
    "bitrate_per_chunk": [
        8960.89,
        8036.678,
        6099.959,
        4247.879,
        7276.979,
        5738.383,
        7740.339,
        7881.705,
        7572.594,
        8387.719,
        9634.343,
        9939.488,
        9365.104,
        5061.071,
        14565.117,
        9725.483,
        4573.873,
        7765.041,
        9796.135,
        12524.024,
        3876.533,
        3914.455
    ],
    "aggregation": "time",
    "chunk_size": 30.0,
    "duration": 634.517
}
```

CSV example:

```
➜  ffmpeg-bitrate-stats -a time -c 30 -of csv BigBuckBunny.mp4
input_file,chunk_index,stream_type,avg_fps,num_frames,avg_bitrate,avg_bitrate_over_chunks,max_bitrate,min_bitrate,max_bitrate_factor,bitrate_per_chunk,aggregation,chunk_size,duration
BigBuckBunny.mp4,0,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,8960.89,time,30.0,634.517
BigBuckBunny.mp4,1,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,8036.678,time,30.0,634.517
BigBuckBunny.mp4,2,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,6099.959,time,30.0,634.517
BigBuckBunny.mp4,3,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,4247.879,time,30.0,634.517
BigBuckBunny.mp4,4,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7276.979,time,30.0,634.517
BigBuckBunny.mp4,5,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,5738.383,time,30.0,634.517
BigBuckBunny.mp4,6,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7740.339,time,30.0,634.517
BigBuckBunny.mp4,7,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7881.705,time,30.0,634.517
BigBuckBunny.mp4,8,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7572.594,time,30.0,634.517
BigBuckBunny.mp4,9,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,8387.719,time,30.0,634.517
BigBuckBunny.mp4,10,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9634.343,time,30.0,634.517
BigBuckBunny.mp4,11,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9939.488,time,30.0,634.517
BigBuckBunny.mp4,12,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9365.104,time,30.0,634.517
BigBuckBunny.mp4,13,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,5061.071,time,30.0,634.517
BigBuckBunny.mp4,14,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,14565.117,time,30.0,634.517
BigBuckBunny.mp4,15,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9725.483,time,30.0,634.517
BigBuckBunny.mp4,16,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,4573.873,time,30.0,634.517
BigBuckBunny.mp4,17,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7765.041,time,30.0,634.517
BigBuckBunny.mp4,18,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9796.135,time,30.0,634.517
BigBuckBunny.mp4,19,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,12524.024,time,30.0,634.517
BigBuckBunny.mp4,20,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,3876.533,time,30.0,634.517
BigBuckBunny.mp4,21,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,3914.455,time,30.0,634.517
```

## Plotting

To enable plots, pass the `-p` or `--plot` flag. This will plot the bitrate over time to STDERR. You can redirect this to a file, or pipe it to another program. Or you can disable STDOUT output with `>/dev/null` to only see the plot:

```bash
ffmpeg-bitrate-stats -a time -c 30 -p BigBuckBunny.mp4 >/dev/null
```

This might output a plot like this:

```console
  7474.000 |
  6975.733 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡎⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  6477.467 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠁⢱⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  5979.200 | ⡇⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡎⠀⠈⡆⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  5480.933 | ⡧⡀⠀⠀⢰⢱⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠁⠀⠀⠱⠊⠱⡀⠀⠀⠀⠀⢀⠤⡀⠀⠀⠀⠀⠀⠀⢀⡄⠀⠀⢠⠊⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  4982.667 | ⡇⠈⢆⠀⡜⠀⢣⠀⠀⠀⠀⠀⠀⡠⠒⠙⡄⠀⠀⡀⠀⠀⢀⡀⠀⢠⢢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⢣⠀⢀⣀⠤⠊⠀⠈⠑⠢⢄⠀⠀⢠⠊⠘⡄⡰⠁⠀⠀⠈⢢⠀⠀⠀⣀⠤⠤⡀⠀⠀⠀⠀
  4484.400 | ⡇⠀⠈⢶⠁⠀⠈⠦⣀⠀⠀⠀⡔⠁⠀⠀⠱⡀⢰⠙⡄⢀⠎⠈⠒⠁⠀⠱⡀⠀⠀⠀⢠⠓⡄⢀⠤⡀⢰⠁⠀⠀⠀⠀⠀⠀⠀⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠁⠀⠀⠘⠁⠀⠀⠀⠀⠀⠑⠒⠊⠀⠀⠀⠈⠢⠤⡄⠀
  3986.133 | ⡇⠀⠀⠀⠀⠀⠀⠀⠈⢢⠀⡸⠀⠀⠀⠀⠀⢣⠃⠀⠘⠎⠀⠀⠀⠀⠀⠀⠈⢆⡀⠀⡎⠀⠈⠁⠀⠱⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢱⠀
  3487.867 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⢢⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄
  2989.600 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇
  2491.333 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
  1993.067 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈
  1494.800 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
   996.533 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
   498.267 | ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
     0.000 | ⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀
-----------|-|---------|---------|---------|---------|---------|---------|---------|---------|-> (Time (s))
           | 0.000     5.760     11.520    17.280    23.040    28.800    34.560    40.320    46.080
```

## API

The program exposes an API that you can use yourself:

```python
from ffmpeg_bitrate_stats import BitrateStats

ffbs = BitrateStats("path/to/ref")
ffbs.calculate_statistics()
ffbs.print_statistics()
```

For more usage please read [the docs](https://htmlpreview.github.io/?https://github.com/slhck/ffmpeg-bitrate-stats/blob/master/docs/ffmpeg_bitrate_stats.html).

## License

ffmpeg_bitrate_stats, Copyright (c) 2019-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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/slhck/ffmpeg-bitrate-stats",
    "name": "ffmpeg-bitrate-stats",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Werner Robitza",
    "author_email": "werner.robitza@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/09/87/4d89944f9b6a68385780dc8525c37db41dac89eb9076ace8857ebb4a41ac/ffmpeg_bitrate_stats-1.1.0.tar.gz",
    "platform": null,
    "description": "# FFmpeg Bitrate Stats\n\n[![PyPI version](https://img.shields.io/pypi/v/ffmpeg_bitrate_stats.svg)](https://pypi.org/project/ffmpeg_bitrate_stats)\n\n[![Python package](https://github.com/slhck/ffmpeg-bitrate-stats/actions/workflows/python-package.yml/badge.svg)](https://github.com/slhck/ffmpeg-bitrate-stats/actions/workflows/python-package.yml)\n\nSimple script for calculating bitrate statistics using FFmpeg.\n\nAuthor: Werner Robitza <werner.robitza@gmail.com>\n\n**Note:** Previous versions installed a `ffmpeg_bitrate_stats` executable. To harmonize it with other tools, now the executable is called `ffmpeg-bitrate-stats`. Please ensure you remove the old executable (e.g. run `which ffmpeg_bitrate_stats` and remove the file).\n\nContents:\n\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Output](#output)\n- [Plotting](#plotting)\n- [API](#api)\n- [License](#license)\n\n------\n\n## Requirements\n\n- Python 3.8 or higher\n- FFmpeg:\n    - download a static build from [their website](http://ffmpeg.org/download.html)\n    - put the `ffprobe` executable in your `$PATH`\n\n## Installation\n\n```bash\npip3 install ffmpeg_bitrate_stats\n```\n\nOr clone this repository, then run the tool with `python -m ffmpeg_bitrate_stats`\n\n## Usage\n\nThe script outputs a bunch of bitrate statistics, including aggregations for pre-defined windows. These windows can either be time-based or GOP-based (for video streams). When choosing a time-based window, you can specify the size of the chunks in seconds.\n\nOutput is to STDOUT so you can redirect that to a file or another script.\n\nSee `ffmpeg-bitrate-stats -h`:\n\n```\nusage: __main__.py [-h] [-n] [-v] [-s {video,audio}] [-a {time,gop}]\n                   [-c CHUNK_SIZE] [-rs READ_START] [-rd READ_DURATION]\n                   [-of {json,csv}] [-p] [-pw PLOT_WIDTH] [-ph PLOT_HEIGHT]\n                   input\n\nffmpeg_bitrate_stats v1.0.2\n\npositional arguments:\n  input                 input file\n\noptions:\n  -h, --help            show this help message and exit\n  -n, --dry-run         Do not run command, just show what would be done\n                        (default: False)\n  -v, --verbose         Show verbose output (default: False)\n  -s {video,audio}, --stream-type {video,audio}\n                        Stream type to analyze (default: video)\n  -a {time,gop}, --aggregation {time,gop}\n                        Window for aggregating statistics, either time-based\n                        (per-second) or per GOP (default: time)\n  -c CHUNK_SIZE, --chunk-size CHUNK_SIZE\n                        Custom aggregation window size in seconds (default:\n                        1.0)\n  -rs READ_START, --read-start READ_START\n                        Time to wait before sampling video (in HH:MM:SS.msec\n                        or seconds) (default: None)\n  -rd READ_DURATION, --read-duration READ_DURATION\n                        Duration for sampling stream (in HH:MM:SS.msec or\n                        seconds). Note that seeking is not accurate, see\n                        ffprobe documentation on '-read_intervals'. (default:\n                        None)\n  -of {json,csv}, --output-format {json,csv}\n                        output in which format (default: json)\n  -p, --plot            Plot the bitrate over time (to STDERR) (default:\n                        False)\n  -pw PLOT_WIDTH, --plot-width PLOT_WIDTH\n                        Plot width (default: 70)\n  -ph PLOT_HEIGHT, --plot-height PLOT_HEIGHT\n                        Plot height (default: 18)\n```\n\n## Output\n\nThe output can be JSON, which includes individual fields for each chunk, or CSV, which repeats each line for each chunk. The CSV adheres to the \u201ctidy\u201d data concept, so it's a little redundant.\n\nRates are given in kilobit per second, using SI prefixes (i.e., kilo = 1000).\n\nExplanation of the fields:\n\n- `input_file`: Path to the input file\n- `stream_type`: Type of stream used (video, audio)\n- `avg_fps`: Average FPS (number of frames divided by duration)\n- `num_frames`: Number of frames\n- `avg_bitrate`: Average bitrate\n- `avg_bitrate_over_chunks`: Average bitrate calculated over the chunks\n- `max_bitrate`: Maximum bitrate calculated over the chunks\n- `min_bitrate`: Minimum bitrate calculated over the chunks\n- `max_bitrate_factor`: Relation between peak and average\n- `bitrate_per_chunk`: Individual bitrates for each chunk\n- `aggregation`: Type of aggregation used\n- `chunk_size`: Size of the chunk (when aggregation is \"time\")\n- `duration`: Total duration of the stream. It is the sum of all frame durations, where each frame's duration is either based on `duration_time` field in ffmpeg, or the difference between the current and previous frame's PTS.\n\nJSON example:\n\n```bash\nffmpeg-bitrate-stats -a time -c 30 -of json BigBuckBunny.mp4\n```\n\nThis returns:\n```json\n{\n    \"input_file\": \"BigBuckBunny.mp4\",\n    \"stream_type\": \"video\",\n    \"avg_fps\": 60.002,\n    \"num_frames\": 38072,\n    \"avg_bitrate\": 8002.859,\n    \"avg_bitrate_over_chunks\": 7849.263,\n    \"max_bitrate\": 14565.117,\n    \"min_bitrate\": 3876.533,\n    \"max_bitrate_factor\": 1.82,\n    \"bitrate_per_chunk\": [\n        8960.89,\n        8036.678,\n        6099.959,\n        4247.879,\n        7276.979,\n        5738.383,\n        7740.339,\n        7881.705,\n        7572.594,\n        8387.719,\n        9634.343,\n        9939.488,\n        9365.104,\n        5061.071,\n        14565.117,\n        9725.483,\n        4573.873,\n        7765.041,\n        9796.135,\n        12524.024,\n        3876.533,\n        3914.455\n    ],\n    \"aggregation\": \"time\",\n    \"chunk_size\": 30.0,\n    \"duration\": 634.517\n}\n```\n\nCSV example:\n\n```\n\u279c  ffmpeg-bitrate-stats -a time -c 30 -of csv BigBuckBunny.mp4\ninput_file,chunk_index,stream_type,avg_fps,num_frames,avg_bitrate,avg_bitrate_over_chunks,max_bitrate,min_bitrate,max_bitrate_factor,bitrate_per_chunk,aggregation,chunk_size,duration\nBigBuckBunny.mp4,0,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,8960.89,time,30.0,634.517\nBigBuckBunny.mp4,1,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,8036.678,time,30.0,634.517\nBigBuckBunny.mp4,2,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,6099.959,time,30.0,634.517\nBigBuckBunny.mp4,3,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,4247.879,time,30.0,634.517\nBigBuckBunny.mp4,4,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7276.979,time,30.0,634.517\nBigBuckBunny.mp4,5,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,5738.383,time,30.0,634.517\nBigBuckBunny.mp4,6,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7740.339,time,30.0,634.517\nBigBuckBunny.mp4,7,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7881.705,time,30.0,634.517\nBigBuckBunny.mp4,8,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7572.594,time,30.0,634.517\nBigBuckBunny.mp4,9,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,8387.719,time,30.0,634.517\nBigBuckBunny.mp4,10,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9634.343,time,30.0,634.517\nBigBuckBunny.mp4,11,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9939.488,time,30.0,634.517\nBigBuckBunny.mp4,12,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9365.104,time,30.0,634.517\nBigBuckBunny.mp4,13,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,5061.071,time,30.0,634.517\nBigBuckBunny.mp4,14,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,14565.117,time,30.0,634.517\nBigBuckBunny.mp4,15,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9725.483,time,30.0,634.517\nBigBuckBunny.mp4,16,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,4573.873,time,30.0,634.517\nBigBuckBunny.mp4,17,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,7765.041,time,30.0,634.517\nBigBuckBunny.mp4,18,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,9796.135,time,30.0,634.517\nBigBuckBunny.mp4,19,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,12524.024,time,30.0,634.517\nBigBuckBunny.mp4,20,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,3876.533,time,30.0,634.517\nBigBuckBunny.mp4,21,video,60.002,38072,8002.859,7849.263,14565.117,3876.533,1.82,3914.455,time,30.0,634.517\n```\n\n## Plotting\n\nTo enable plots, pass the `-p` or `--plot` flag. This will plot the bitrate over time to STDERR. You can redirect this to a file, or pipe it to another program. Or you can disable STDOUT output with `>/dev/null` to only see the plot:\n\n```bash\nffmpeg-bitrate-stats -a time -c 30 -p BigBuckBunny.mp4 >/dev/null\n```\n\nThis might output a plot like this:\n\n```console\n  7474.000 |\n  6975.733 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u284e\u2846\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n  6477.467 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28b0\u2801\u28b1\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n  5979.200 | \u2847\u2800\u2800\u2800\u2800\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u284e\u2800\u2808\u2846\u2800\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u2844\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n  5480.933 | \u2867\u2840\u2800\u2800\u28b0\u28b1\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28b0\u2801\u2800\u2800\u2831\u280a\u2831\u2840\u2800\u2800\u2800\u2800\u2880\u2824\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u2844\u2800\u2800\u28a0\u280a\u2808\u2846\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n  4982.667 | \u2847\u2808\u2886\u2800\u285c\u2800\u28a3\u2800\u2800\u2800\u2800\u2800\u2800\u2860\u2812\u2819\u2844\u2800\u2800\u2840\u2800\u2800\u2880\u2840\u2800\u28a0\u28a2\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u284e\u2800\u2800\u2800\u2800\u2800\u2800\u28a3\u2800\u2880\u28c0\u2824\u280a\u2800\u2808\u2811\u2822\u2884\u2800\u2800\u28a0\u280a\u2818\u2844\u2870\u2801\u2800\u2800\u2808\u28a2\u2800\u2800\u2800\u28c0\u2824\u2824\u2840\u2800\u2800\u2800\u2800\n  4484.400 | \u2847\u2800\u2808\u28b6\u2801\u2800\u2808\u2826\u28c0\u2800\u2800\u2800\u2854\u2801\u2800\u2800\u2831\u2840\u28b0\u2819\u2844\u2880\u280e\u2808\u2812\u2801\u2800\u2831\u2840\u2800\u2800\u2800\u28a0\u2813\u2844\u2880\u2824\u2840\u28b0\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u280b\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2809\u2809\u2801\u2800\u2800\u2818\u2801\u2800\u2800\u2800\u2800\u2800\u2811\u2812\u280a\u2800\u2800\u2800\u2808\u2822\u2824\u2844\u2800\n  3986.133 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u28a2\u2800\u2878\u2800\u2800\u2800\u2800\u2800\u28a3\u2803\u2800\u2818\u280e\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u2886\u2840\u2800\u284e\u2800\u2808\u2801\u2800\u2831\u284e\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28b1\u2800\n  3487.867 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u28a2\u2803\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u281a\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2818\u2844\n  2989.600 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2847\n  2491.333 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28b8\n  1993.067 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\n  1494.800 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n   996.533 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n   498.267 | \u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\n     0.000 | \u28c7\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\u28c0\n-----------|-|---------|---------|---------|---------|---------|---------|---------|---------|-> (Time (s))\n           | 0.000     5.760     11.520    17.280    23.040    28.800    34.560    40.320    46.080\n```\n\n## API\n\nThe program exposes an API that you can use yourself:\n\n```python\nfrom ffmpeg_bitrate_stats import BitrateStats\n\nffbs = BitrateStats(\"path/to/ref\")\nffbs.calculate_statistics()\nffbs.print_statistics()\n```\n\nFor more usage please read [the docs](https://htmlpreview.github.io/?https://github.com/slhck/ffmpeg-bitrate-stats/blob/master/docs/ffmpeg_bitrate_stats.html).\n\n## License\n\nffmpeg_bitrate_stats, Copyright (c) 2019-2023 Werner Robitza\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Calculate bitrate statistics using FFmpeg",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/slhck/ffmpeg-bitrate-stats"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e190c4155915dfc95766dff5856cc6041c7e9d076deb248c117f464141f8e35d",
                "md5": "e7f3ba260295987b0125d181af376706",
                "sha256": "486a618f6f9f00214d2022ac999baeca255689dcd43ca2fe684ad3cd903a4e73"
            },
            "downloads": -1,
            "filename": "ffmpeg_bitrate_stats-1.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e7f3ba260295987b0125d181af376706",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 13544,
            "upload_time": "2023-08-16T11:13:14",
            "upload_time_iso_8601": "2023-08-16T11:13:14.197518Z",
            "url": "https://files.pythonhosted.org/packages/e1/90/c4155915dfc95766dff5856cc6041c7e9d076deb248c117f464141f8e35d/ffmpeg_bitrate_stats-1.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "09874d89944f9b6a68385780dc8525c37db41dac89eb9076ace8857ebb4a41ac",
                "md5": "6333e738c4144a0cd0691750d18f77fd",
                "sha256": "7781d460ada907149a00c685ec7bd0e63d474e8329bc709f09dd093b51eb6db3"
            },
            "downloads": -1,
            "filename": "ffmpeg_bitrate_stats-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6333e738c4144a0cd0691750d18f77fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16387,
            "upload_time": "2023-08-16T11:13:15",
            "upload_time_iso_8601": "2023-08-16T11:13:15.850942Z",
            "url": "https://files.pythonhosted.org/packages/09/87/4d89944f9b6a68385780dc8525c37db41dac89eb9076ace8857ebb4a41ac/ffmpeg_bitrate_stats-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-16 11:13:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "slhck",
    "github_project": "ffmpeg-bitrate-stats",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "ffmpeg-bitrate-stats"
}
        
Elapsed time: 0.12055s