Skip to main content

Extract NAL units from H.264 bitstreams

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

h26x-extractor-0.3.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

h26x_extractor-0.3-py2.py3-none-any.whl (11.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file h26x-extractor-0.3.tar.gz.

File metadata

  • Download URL: h26x-extractor-0.3.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for h26x-extractor-0.3.tar.gz
Algorithm Hash digest
SHA256 54f61f1bff359e6dab83858b7a7f86d1c4eb4c5116db8493b1c7f77a8dea207d
MD5 9dc359c14a0d09257906e9779cde9b96
BLAKE2b-256 f8f56e6f5dd286efd9015051ddb6b611e150da9afae7b8c795ce7115fc337f5e

See more details on using hashes here.

File details

Details for the file h26x_extractor-0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: h26x_extractor-0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for h26x_extractor-0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bf72d62746a3f7504a45f3f46c0c872b7bedb8e95b6c94674991b17d99007142
MD5 7f76e3408c1e9cd1f9071a5e6c5322bf
BLAKE2b-256 fd5f082050ce66e409ff085bb065ec37962b5f224ad703ccf7a069a79235a20e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page