Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test

on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- uses: prantlf/setup-v-action@v4
- run: v test .
54 changes: 50 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
# H.264 bitstream parser for V

This module parses the H.264/AVC syntax needed by Vulkan Video applications:
NAL headers, sequence and picture parameter sets (SPS/PPS), video usability
information (VUI), and slice headers.

# h264 Video Decoder
Provides functions to decode h264 video data.
See [ITU-T H.264 (08/2021)](https://www.itu.int/ITU-T/recommendations/rec.aspx?rec=14659) for details.
It is **not** a video decoder: it does not perform entropy decoding, motion
compensation, inverse transforms, or produce pixels. The
[`v_vulkan_video`](https://github.com/antono2/v_vulkan_video) player uses these
parsed structures to prepare hardware decode operations.

## Install
`v install https://github.com/antono2/h264`

```bash
v install https://github.com/antono2/h264
```

## Minimal example

```v
import h264

mut stream := h264.Bitstream{}
stream.init([u8(0x67)]) // forbidden_zero_bit=0, nal_ref_idc=3, type=SPS

mut header := h264.NetworkAbstractionLayerHeader{}
header.read_nal_header(mut stream)
assert header.type == .sequence_parameter_set
```

`Bitstream.init()` expects raw RBSP/NAL bytes in memory. Container extraction,
length prefixes or Annex-B start codes, emulation-prevention removal, frame
reordering, and decoded-picture management remain the caller's responsibility.

## Safety and supported scope

The parser exposes low-level syntax structures rather than a defensive media
API. Some invalid syntax is rejected with assertions, while truncated fields
can read as zero at end of input. Validate untrusted container lengths and NAL
boundaries before parsing them.

The implementation covers the syntax exercised by the Vulkan Video H.264
player and is not yet a claim of complete support for every profile, extension,
bit depth, chroma format, or interlaced stream.

## Tests

The included tests are software-only and require no GPU:

```bash
v test .
```

They cover RBSP look-ahead behavior and representative High-profile SPS/PPS
parsing used by the player.
2 changes: 1 addition & 1 deletion h264.v
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ pub fn (mut sh SliceHeader) read_slice_header(nal &NetworkAbstractionLayerHeader
}
sh.read_ref_pic_list_reordering(mut b)
if pps.weighted_pred_flag != 0
&& ((sh.is_slice_type(SH_SLICE_TYPE.p) || sh.is_slice_type(SH_SLICE_TYPE.sp))
&& (sh.is_slice_type(SH_SLICE_TYPE.p) || sh.is_slice_type(SH_SLICE_TYPE.sp)
|| (pps.weighted_bipred_idc == 1 && sh.is_slice_type(SH_SLICE_TYPE.b))) {
sh.read_pred_weight_table(sps, pps, mut b)
}
Expand Down
4 changes: 2 additions & 2 deletions v.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Module {
name: 'h264'
author: 'Anton Oreskin'
description: 'Decoder for the h264 video format'
description: 'Low-level H.264 bitstream and parameter-set parser'
version: '1.0.0'
repo_url: 'https://github.com/antono2/h264'
vcs: 'git'
tags: ['V','h264','decoder']
tags: ['V','h264','parser','bitstream']
license: 'MIT'
dependencies: []
}