ffmpeg-black-split


Nameffmpeg-black-split JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/slhck/ffmpeg-black-split
SummarySplit a video by black frames
upload_time2023-01-16 07:57:41
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 Black Split

[![PyPI version](https://img.shields.io/pypi/v/ffmpeg-black-split.svg)](https://pypi.org/project/ffmpeg-black-split)

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

Split a video based on black frames.

This tool uses the [`blackdetect` filter](http://ffmpeg.org/ffmpeg-filters.html#blackdetect) from ffmpeg to determine the periods of black content.

It can cut the video into segments based on these periods, and also output the detected black and content periods as JSON.

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

Contents:

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
  - [JSON Output](#json-output)
  - [Extended Usage](#extended-usage)
- [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 `ffmpeg` executable in your `$PATH`

## Installation

```bash
pip3 install --user ffmpeg_black_split
```

Or clone this repository, then run the tool with `python3 -m ffmpeg_black_split`.

## Usage

Run:

```bash
ffmpeg-black-split <input-file>
```

This might take a while depending on the length of your input file. It'll then split the video into parts, prefixed by the original filename. The audio and video streams will be copied as-is.

The output will be placed in the current directory, with each file being named `<input>_<start>-<end>.mkv`.

Note that by default, cutting is not that accurate, as stream-copying is used. If you want to re-encode using x264, you can use the `--no-copy` flag. (Future versions may have better options for encoding.)

Pass the `--no-split` option to disable the actual splitting.

### JSON Output

Example to get just the JSON output:

```bash
ffmpeg-black-split input.mkv -p -v --no-split 2>/dev/null
```

Returns:

```json
{
  "black_periods": [
    {
      "start": 0.0,
      "end": 5.0,
      "duration": 5.0
    },
    {
      "start": 10.0,
      "end": 15.0,
      "duration": 5.0
    },
    {
      "start": 20.0,
      "end": 25.0,
      "duration": 5.0
    }
  ],
  "content_periods": [
    {
      "start": 5.0,
      "end": 10.0
    },
    {
      "start": 10.0,
      "end": 20.0
    },
    {
      "start": 20.0,
      "end": null
    }
  ]
}
```

### Extended Usage

See `ffmpeg-black-split -h` for more:

```
usage: ffmpeg-black-split [-h] [-d BLACK_MIN_DURATION] [-r PICTURE_BLACK_RATIO_TH]
                   [-t PIXEL_BLACK_TH] [-o OUTPUT_DIRECTORY] [--no-split]
                   [--no-copy] [-p] [-v]
                   input

ffmpeg-black-split v0.4.0

positional arguments:
  input                 input file

optional arguments:
  -h, --help            show this help message and exit
  -d BLACK_MIN_DURATION, --black-min-duration BLACK_MIN_DURATION
                        Set the minimum detected black duration expressed in
                        seconds. It must be a non-negative floating point
                        number. (default: 2.0)
  -r PICTURE_BLACK_RATIO_TH, --picture-black-ratio-th PICTURE_BLACK_RATIO_TH
                        Set the threshold for considering a picture 'black'
                        (default: 0.98)
  -t PIXEL_BLACK_TH, --pixel-black-th PIXEL_BLACK_TH
                        Set the threshold for considering a pixel 'black'
                        (default: 0.1)
  -o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY
                        Set the output directory. Default is the current
                        working directory. (default: None)
  --no-split            Don't split the video into segments. (default: False)
  --no-copy             Don't stream-copy, but re-encode the video. (default:
                        False)
  -p, --progress        Show a progress bar on stderr (default: False)
  -v, --verbose         Print verbose info to stderr, and JSON of black and
                        content periods to stdout (default: False)
```

## API

The program exposes an API that you can use yourself:

```python
from ffmpeg_black_split import FfmpegBlackSplit

ffbs = FfmpegBlackSplit("input.mkv")
ffbs.detect_black_periods()
ffbs.cut_all_periods("/path/to/output/folder")
```

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


## License

ffmpeg_black_split, Copyright (c) 2022-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-black-split",
    "name": "ffmpeg-black-split",
    "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/c6/42/d5249b31b808e85a6dce3160bff9bbd07380f8320e289d89220a8fd9322a/ffmpeg_black_split-0.4.0.tar.gz",
    "platform": null,
    "description": "# ffmpeg Black Split\n\n[![PyPI version](https://img.shields.io/pypi/v/ffmpeg-black-split.svg)](https://pypi.org/project/ffmpeg-black-split)\n\n[![Python package](https://github.com/slhck/ffmpeg-black-split/actions/workflows/python-package.yml/badge.svg)](https://github.com/slhck/ffmpeg-black-split/actions/workflows/python-package.yml)\n\nSplit a video based on black frames.\n\nThis tool uses the [`blackdetect` filter](http://ffmpeg.org/ffmpeg-filters.html#blackdetect) from ffmpeg to determine the periods of black content.\n\nIt can cut the video into segments based on these periods, and also output the detected black and content periods as JSON.\n\nAuthor: Werner Robitza <werner.robitza@gmail.com>\n\nContents:\n\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [JSON Output](#json-output)\n  - [Extended Usage](#extended-usage)\n- [API](#api)\n- [License](#license)\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 `ffmpeg` executable in your `$PATH`\n\n## Installation\n\n```bash\npip3 install --user ffmpeg_black_split\n```\n\nOr clone this repository, then run the tool with `python3 -m ffmpeg_black_split`.\n\n## Usage\n\nRun:\n\n```bash\nffmpeg-black-split <input-file>\n```\n\nThis might take a while depending on the length of your input file. It'll then split the video into parts, prefixed by the original filename. The audio and video streams will be copied as-is.\n\nThe output will be placed in the current directory, with each file being named `<input>_<start>-<end>.mkv`.\n\nNote that by default, cutting is not that accurate, as stream-copying is used. If you want to re-encode using x264, you can use the `--no-copy` flag. (Future versions may have better options for encoding.)\n\nPass the `--no-split` option to disable the actual splitting.\n\n### JSON Output\n\nExample to get just the JSON output:\n\n```bash\nffmpeg-black-split input.mkv -p -v --no-split 2>/dev/null\n```\n\nReturns:\n\n```json\n{\n  \"black_periods\": [\n    {\n      \"start\": 0.0,\n      \"end\": 5.0,\n      \"duration\": 5.0\n    },\n    {\n      \"start\": 10.0,\n      \"end\": 15.0,\n      \"duration\": 5.0\n    },\n    {\n      \"start\": 20.0,\n      \"end\": 25.0,\n      \"duration\": 5.0\n    }\n  ],\n  \"content_periods\": [\n    {\n      \"start\": 5.0,\n      \"end\": 10.0\n    },\n    {\n      \"start\": 10.0,\n      \"end\": 20.0\n    },\n    {\n      \"start\": 20.0,\n      \"end\": null\n    }\n  ]\n}\n```\n\n### Extended Usage\n\nSee `ffmpeg-black-split -h` for more:\n\n```\nusage: ffmpeg-black-split [-h] [-d BLACK_MIN_DURATION] [-r PICTURE_BLACK_RATIO_TH]\n                   [-t PIXEL_BLACK_TH] [-o OUTPUT_DIRECTORY] [--no-split]\n                   [--no-copy] [-p] [-v]\n                   input\n\nffmpeg-black-split v0.4.0\n\npositional arguments:\n  input                 input file\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -d BLACK_MIN_DURATION, --black-min-duration BLACK_MIN_DURATION\n                        Set the minimum detected black duration expressed in\n                        seconds. It must be a non-negative floating point\n                        number. (default: 2.0)\n  -r PICTURE_BLACK_RATIO_TH, --picture-black-ratio-th PICTURE_BLACK_RATIO_TH\n                        Set the threshold for considering a picture 'black'\n                        (default: 0.98)\n  -t PIXEL_BLACK_TH, --pixel-black-th PIXEL_BLACK_TH\n                        Set the threshold for considering a pixel 'black'\n                        (default: 0.1)\n  -o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY\n                        Set the output directory. Default is the current\n                        working directory. (default: None)\n  --no-split            Don't split the video into segments. (default: False)\n  --no-copy             Don't stream-copy, but re-encode the video. (default:\n                        False)\n  -p, --progress        Show a progress bar on stderr (default: False)\n  -v, --verbose         Print verbose info to stderr, and JSON of black and\n                        content periods to stdout (default: False)\n```\n\n## API\n\nThe program exposes an API that you can use yourself:\n\n```python\nfrom ffmpeg_black_split import FfmpegBlackSplit\n\nffbs = FfmpegBlackSplit(\"input.mkv\")\nffbs.detect_black_periods()\nffbs.cut_all_periods(\"/path/to/output/folder\")\n```\n\nFor more usage please read [the docs](https://htmlpreview.github.io/?https://github.com/slhck/ffmpeg-black-split/blob/master/docs/ffmpeg_black_split.html).\n\n\n## License\n\nffmpeg_black_split, Copyright (c) 2022-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": "Split a video by black frames",
    "version": "0.4.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "43d94855e5dc1ca9d5c8b237fd3ef5b4ffa1d0ea9f0aabed39ea3bd1a2d70513",
                "md5": "8fcc7ecf685dc1d41e3bd924eefab924",
                "sha256": "d9d6d4fac08e984c73baed0cd8cb4d71c4b7537f1c4b2c89dab96de222c18281"
            },
            "downloads": -1,
            "filename": "ffmpeg_black_split-0.4.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8fcc7ecf685dc1d41e3bd924eefab924",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 9438,
            "upload_time": "2023-01-16T07:57:39",
            "upload_time_iso_8601": "2023-01-16T07:57:39.210571Z",
            "url": "https://files.pythonhosted.org/packages/43/d9/4855e5dc1ca9d5c8b237fd3ef5b4ffa1d0ea9f0aabed39ea3bd1a2d70513/ffmpeg_black_split-0.4.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c642d5249b31b808e85a6dce3160bff9bbd07380f8320e289d89220a8fd9322a",
                "md5": "06a1fb30743397ea3c73397a1e4c647c",
                "sha256": "8ab10b446dfe66e80e1216a9c1dab644be431f8e2c56973991e3f10446d8db7f"
            },
            "downloads": -1,
            "filename": "ffmpeg_black_split-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "06a1fb30743397ea3c73397a1e4c647c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8677,
            "upload_time": "2023-01-16T07:57:41",
            "upload_time_iso_8601": "2023-01-16T07:57:41.234637Z",
            "url": "https://files.pythonhosted.org/packages/c6/42/d5249b31b808e85a6dce3160bff9bbd07380f8320e289d89220a8fd9322a/ffmpeg_black_split-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-16 07:57:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "slhck",
    "github_project": "ffmpeg-black-split",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "ffmpeg-black-split"
}
        
Elapsed time: 0.02990s