h26x-extractor


Nameh26x-extractor JSON
Version 0.10.1 PyPI version JSON
download
home_pageNone
SummaryExtract NAL units from H.264 bitstreams
upload_time2025-09-01 07:30:24
maintainerNone
docs_urlNone
authorWerner Robitza
requires_python>=3.9
licenseNone
keywords video h264
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # h26x-extractor

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

Author: Werner Robitza, with contributions from @chemag, Paulo Sherring, Thomas Jammet.

Extracts NAL units from H.264 bitstreams and decodes their type and content, if supported.

⚠️ `h26x-extractor` is neither fast nor robust to bitstream errors. It's rather a playground for parsing bitstreams. Use with caution! This program is no longer maintained, PRs are welcome.

Contents:

- [Installation](#installation)
- [Status](#status)
- [Usage](#usage)
- [Programmatic usage (API)](#programmatic-usage-api)
- [API](#api)
- [Alternatives](#alternatives)
- [License](#license)

## Installation

Requirements: Python 3.9 or higher

Via [uv](https://docs.astral.sh/uv/getting-started/installation/):

```bash
uvx h26x-extractor
```

Via [pipx](https://pipx.pypa.io/latest/installation/):

```bash
pipx install h26x-extractor
```

Via pip:

```bash
pip3 install --user h26x_extractor
```

For development, clone the repository and install with uv:

```bash
git clone https://github.com/slhck/h26x-extractor
cd h26x-extractor
uv sync
```

## Status

Currently supported:

- Parsing of H.264 bitstreams
- Parsing of NALU
- Parsing of AUD
- Parsing of CodedSlice(s)
- Parsing of SPS
- Parsing of PPS
- Parsing of Prefix for Scalable Video Coding

Currently planned:

- Parsing of SEI
- Parsing of H.265 bitstreams

## Usage

If you installed the program, you can run it directly:

```bash
h26x-extractor [options] <input-file>...
```

For development, you can also run it via:

```bash
uv run h26x-extractor [options] <input-file>...
```

You can pass the `-v` flag to enable verbose output, e.g. the following. You will get, for each NAL unit:

- The byte position range
- The offset from the start of the stream
- The overall length including start code
- The type (also translated in plaintext)
- Its content in raw bytes, encoded as hex
- Its RBSP content
- A table with its content decoded, if supported

Example:

```
NALU bytepos:   [0, 28]
NALU offset:    0 Bytes
NALU length:    29 Bytes (including start code)
NALU type:      7 (Sequence parameter set)
NALU bytes:     0x0000000167f4000d919b28283f6022000003000200000300641e28532c
NALU RBSP:      0xf4000d919b28283f602200000002000000641e28532c

SPS (payload size: 22.0 Bytes)
+--------------------------------------+---------+
| field                                | value   |
+======================================+=========+
| constraint_set0_flag                 | 0       |
+--------------------------------------+---------+
| constraint_set1_flag                 | 0       |
+--------------------------------------+---------+
....
```

## Programmatic usage (API)

## API

This program has a simple API that can be used to integrate it into other Python programs.

For more information see the [API documentation](https://htmlpreview.github.io/?https://github.com/slhck/h26x-extractor/blob/master/docs/h26x_extractor.html).

Here is an example:

```python
from h26x_extractor.h26x_parser import H26xParser

def do_something(nalu):
    pass
    # do something with the NALU instance

H26xParser.set_callback("nalu", do_something)
H26xParser.parse()
```

The callback is called for each type of info found. Valid callbacks are:

- `sps`
- `pps`
- `slice`
- `aud`
- `nalu`
- `prefix`

The callback returns an instance of the NALU type. You can access the `s` property to get the whole data including the RBSP.
You can use the `set_allcallbacks` method to set callbacks for all types.

You can also call the `nalutypes` classes to decode the individual fields, e.g. `nalutypes.SPS`:

```python
from h26x_extractor.nalutypes import SPS
from bitstring import BitStream

nal_payload = "0x0000000167f4000d919b28283f6022000003000200000300641e28532c"
sps = SPS(BitStream(nal_payload))
sps.print_verbose()
```

See the `tests/test_h26x_extractor.py` file for more examples.

## Alternatives

[h264bitstream](https://github.com/aizvorski/h264bitstream) is a proper H.264 parser.

FFmpeg can also parse bitstream data:

```bash
ffmpeg -i video.h264 -c copy -bsf:v trace_headers -f null - 2> output.txt
```

## License

The MIT License (MIT)

Copyright (c) 2017-2025 h26x-extractor contributors

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": null,
    "name": "h26x-extractor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "video, h264",
    "author": "Werner Robitza",
    "author_email": "Werner Robitza <werner.robitza@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1c/68/0fd259fc2b355c2ad10ba5dbe883b6cb658099f1f7c7ea3d77df06ac5dbf/h26x_extractor-0.10.1.tar.gz",
    "platform": null,
    "description": "# h26x-extractor\n\n[![PyPI version](https://img.shields.io/pypi/v/h26x-extractor.svg)](https://pypi.org/project/h26x-extractor)\n\nAuthor: Werner Robitza, with contributions from @chemag, Paulo Sherring, Thomas Jammet.\n\nExtracts NAL units from H.264 bitstreams and decodes their type and content, if supported.\n\n\u26a0\ufe0f `h26x-extractor` is neither fast nor robust to bitstream errors. It's rather a playground for parsing bitstreams. Use with caution! This program is no longer maintained, PRs are welcome.\n\nContents:\n\n- [Installation](#installation)\n- [Status](#status)\n- [Usage](#usage)\n- [Programmatic usage (API)](#programmatic-usage-api)\n- [API](#api)\n- [Alternatives](#alternatives)\n- [License](#license)\n\n## Installation\n\nRequirements: Python 3.9 or higher\n\nVia [uv](https://docs.astral.sh/uv/getting-started/installation/):\n\n```bash\nuvx h26x-extractor\n```\n\nVia [pipx](https://pipx.pypa.io/latest/installation/):\n\n```bash\npipx install h26x-extractor\n```\n\nVia pip:\n\n```bash\npip3 install --user h26x_extractor\n```\n\nFor development, clone the repository and install with uv:\n\n```bash\ngit clone https://github.com/slhck/h26x-extractor\ncd h26x-extractor\nuv sync\n```\n\n## Status\n\nCurrently supported:\n\n- Parsing of H.264 bitstreams\n- Parsing of NALU\n- Parsing of AUD\n- Parsing of CodedSlice(s)\n- Parsing of SPS\n- Parsing of PPS\n- Parsing of Prefix for Scalable Video Coding\n\nCurrently planned:\n\n- Parsing of SEI\n- Parsing of H.265 bitstreams\n\n## Usage\n\nIf you installed the program, you can run it directly:\n\n```bash\nh26x-extractor [options] <input-file>...\n```\n\nFor development, you can also run it via:\n\n```bash\nuv run h26x-extractor [options] <input-file>...\n```\n\nYou can pass the `-v` flag to enable verbose output, e.g. the following. You will get, for each NAL unit:\n\n- The byte position range\n- The offset from the start of the stream\n- The overall length including start code\n- The type (also translated in plaintext)\n- Its content in raw bytes, encoded as hex\n- Its RBSP content\n- A table with its content decoded, if supported\n\nExample:\n\n```\nNALU bytepos:   [0, 28]\nNALU offset:    0 Bytes\nNALU length:    29 Bytes (including start code)\nNALU type:      7 (Sequence parameter set)\nNALU bytes:     0x0000000167f4000d919b28283f6022000003000200000300641e28532c\nNALU RBSP:      0xf4000d919b28283f602200000002000000641e28532c\n\nSPS (payload size: 22.0 Bytes)\n+--------------------------------------+---------+\n| field                                | value   |\n+======================================+=========+\n| constraint_set0_flag                 | 0       |\n+--------------------------------------+---------+\n| constraint_set1_flag                 | 0       |\n+--------------------------------------+---------+\n....\n```\n\n## Programmatic usage (API)\n\n## API\n\nThis program has a simple API that can be used to integrate it into other Python programs.\n\nFor more information see the [API documentation](https://htmlpreview.github.io/?https://github.com/slhck/h26x-extractor/blob/master/docs/h26x_extractor.html).\n\nHere is an example:\n\n```python\nfrom h26x_extractor.h26x_parser import H26xParser\n\ndef do_something(nalu):\n    pass\n    # do something with the NALU instance\n\nH26xParser.set_callback(\"nalu\", do_something)\nH26xParser.parse()\n```\n\nThe callback is called for each type of info found. Valid callbacks are:\n\n- `sps`\n- `pps`\n- `slice`\n- `aud`\n- `nalu`\n- `prefix`\n\nThe callback returns an instance of the NALU type. You can access the `s` property to get the whole data including the RBSP.\nYou can use the `set_allcallbacks` method to set callbacks for all types.\n\nYou can also call the `nalutypes` classes to decode the individual fields, e.g. `nalutypes.SPS`:\n\n```python\nfrom h26x_extractor.nalutypes import SPS\nfrom bitstring import BitStream\n\nnal_payload = \"0x0000000167f4000d919b28283f6022000003000200000300641e28532c\"\nsps = SPS(BitStream(nal_payload))\nsps.print_verbose()\n```\n\nSee the `tests/test_h26x_extractor.py` file for more examples.\n\n## Alternatives\n\n[h264bitstream](https://github.com/aizvorski/h264bitstream) is a proper H.264 parser.\n\nFFmpeg can also parse bitstream data:\n\n```bash\nffmpeg -i video.h264 -c copy -bsf:v trace_headers -f null - 2> output.txt\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017-2025 h26x-extractor contributors\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",
    "bugtrack_url": null,
    "license": null,
    "summary": "Extract NAL units from H.264 bitstreams",
    "version": "0.10.1",
    "project_urls": {
        "Homepage": "https://github.com/slhck/h26x-extractor",
        "Repository": "https://github.com/slhck/h26x-extractor"
    },
    "split_keywords": [
        "video",
        " h264"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5de4c7d239ba2dab0d20d9d4b48be21f398650a92066b6fd4d8cc3c0dcf198bf",
                "md5": "caa0e7da55014377c1fbbd54d0f8aa37",
                "sha256": "ad26ea1e86aaebf7b379a8b997da59ad0f6be1a7ddebc7835b054ca020cf9246"
            },
            "downloads": -1,
            "filename": "h26x_extractor-0.10.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "caa0e7da55014377c1fbbd54d0f8aa37",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 17274,
            "upload_time": "2025-09-01T07:30:23",
            "upload_time_iso_8601": "2025-09-01T07:30:23.441435Z",
            "url": "https://files.pythonhosted.org/packages/5d/e4/c7d239ba2dab0d20d9d4b48be21f398650a92066b6fd4d8cc3c0dcf198bf/h26x_extractor-0.10.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1c680fd259fc2b355c2ad10ba5dbe883b6cb658099f1f7c7ea3d77df06ac5dbf",
                "md5": "fd28570796e50c5989cd2fd803ba1734",
                "sha256": "a2c6bf245d647d805cfd9169901c2e4aed9ce36d4deca02ffe09f494f2781a3f"
            },
            "downloads": -1,
            "filename": "h26x_extractor-0.10.1.tar.gz",
            "has_sig": false,
            "md5_digest": "fd28570796e50c5989cd2fd803ba1734",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 13326,
            "upload_time": "2025-09-01T07:30:24",
            "upload_time_iso_8601": "2025-09-01T07:30:24.348206Z",
            "url": "https://files.pythonhosted.org/packages/1c/68/0fd259fc2b355c2ad10ba5dbe883b6cb658099f1f7c7ea3d77df06ac5dbf/h26x_extractor-0.10.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-01 07:30:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "slhck",
    "github_project": "h26x-extractor",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "h26x-extractor"
}
        
Elapsed time: 1.13134s