Skip to main content

h26x-extractor

Author: Werner Robitza

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

Note: This is not a replacement for a proper tool like h264bitstream. h26x-extractor is not fast and not robust, but rather a playground for parsing bitstreams. Use with caution!

Installation

Python 2.7:

pip install h26x-extractor

Python 3.x:

pip3 install h26x-extractor

Status

Currently supported:

  • Parsing of H.264 bitstreams

  • Parsing of NALU

  • Parsing of AUD

  • Parsing of CodedSliceIDR

  • Parsing of CodedSliceNonIDR

  • Parsing of SPS

  • Parsing of PPS

Currently planned:

  • Parsing of SEI

  • Parsing of VUI

  • Parsing of H.265 bitstreams

Usage

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 bye 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

You can also use this library in your code, e.g.:

from h26x_extractor.h26x_parser import H26xParser

H26xParser.set_callback("nalu", do_something)
H26xParser.parse()
def do_something(bytes):
  # do something with the NALU bytes

Valid callbacks are:

  • sps

  • pps

  • slice

  • aud

  • nalu

Raw data for all callbacks includes the RBSP.

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

License

The MIT License (MIT)

Copyright (c) 2017 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

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by `auto-changelog <https://github.com/CookPete/auto-changelog>`__.

Unreleased

Release files for h26x-extractor 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h26x-extractor 0.3
File Size Uploaded
h26x-extractor-0.3.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for h26x-extractor 0.3
File Interpreter ABI Platform
h26x_extractor-0.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 22.0 kB

Release files / h26x-extractor-0.3.tar.gz

Download URL h26x-extractor-0.3.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
54f61f1bff359e6dab83858b7a7f86d1c4eb4c5116db8493b1c7f77a8dea207d
BLAKE2b-256 checksum
How to use checksums
f8f56e6f5dd286efd9015051ddb6b611e150da9afae7b8c795ce7115fc337f5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

Release files / h26x_extractor-0.3-py2.py3-none-any.whl

Download URL h26x_extractor-0.3-py2.py3-none-any.whl
Size 11.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bf72d62746a3f7504a45f3f46c0c872b7bedb8e95b6c94674991b17d99007142
BLAKE2b-256 checksum
How to use checksums
fd5f082050ce66e409ff085bb065ec37962b5f224ad703ccf7a069a79235a20e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

Release history Release notifications | RSS feed

0.11.1

2 release files

0.10.2

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

This release

0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page