Pure-MoonBit ITU-T H.264/AVC Constrained Baseline video decoder, bit-exact FFmpeg-verified YUV420p engine, macroblock/MV inspector, and zero-upload browser player
let res = @h264.decode_annexb(h264_bytes)
for frame in res.frames {
let yuv420p : Bytes = frame.to_yuv420p_bytes()
let rgba8888 : Bytes = frame.to_rgba()
let mb_svg : String = @h264.render_frame_mb_svg(frame.meta)
ignore((yuv420p, rgba8888, mb_svg))
}# Decode Annex B .h264 to raw YUV420p
moon run --target native cmd/main -- decode input.h264 --out output.yuv
# Probe NALU / SPS / PPS / frame summary (text or json)
moon run --target native cmd/main -- probe input.h264 --format text
# Export native SVG macroblock/MV anatomy or bitrate distribution
moon run --target native cmd/main -- inspect input.h264 --frame 0 --mode mb --out frame0.svg
moon run --target native cmd/main -- inspect input.h264 --mode bitrate --out bitrate.svgmoon build --target native --release --deny-warn cmd/main
python3 demo/verify_h264.pypub struct BitReader {
data : Bytes
bit_pos : Int
total_bits : Int
stop_bit_pos : Int
}pub struct DecodedFrame {
width : Int
height : Int
y : Bytes
u : Bytes
v : Bytes
matrix_coefficients : Int
meta : FrameMeta
}pub enum MbKind {
I4x4
I16x16
IPcm
PSkip
P16x16
P16x8
P8x16
P8x8
}pub struct MbMeta {
mb_x : Int
mb_y : Int
kind : MbKind
qp : Int
bits : Int
mv_x : Int
mv_y : Int
intra_mode : Int
}pub struct MmcoOp {
op : Int
arg1 : Int
arg2 : Int
}pub struct NalUnit {
nal_ref_idc : Int
nal_unit_type : Int
byte_offset : Int
raw_size : Int
rbsp : Bytes
}pub struct Pps {
pps_id : Int
sps_id : Int
entropy_coding_mode_flag : Bool
bottom_field_pic_order_in_frame_present_flag : Bool
num_slice_groups_minus1 : Int
num_ref_idx_l0_default_active_minus1 : Int
num_ref_idx_l1_default_active_minus1 : Int
weighted_pred_flag : Bool
weighted_bipred_idc : Int
pic_init_qp_minus26 : Int
pic_init_qs_minus26 : Int
chroma_qp_index_offset : Int
deblocking_filter_control_present_flag : Bool
constrained_intra_pred_flag : Bool
redundant_pic_cnt_present_flag : Bool
}pub struct RefPicListMod {
idc : Int
value : Int
}pub struct SliceHeader {
first_mb_in_slice : Int
slice_type : Int
pps_id : Int
frame_num : Int
is_idr : Bool
nal_ref_idc : Int
idr_pic_id : Int
pic_order_cnt_lsb : Int
delta_pic_order_cnt_0 : Int
delta_pic_order_cnt_1 : Int
num_ref_idx_l0_active : Int
ref_pic_list_mods_l0 : Array[RefPicListMod]
no_output_of_prior_pics_flag : Bool
long_term_reference_flag : Bool
adaptive_ref_pic_marking_mode_flag : Bool
mmco_ops : Array[MmcoOp]
slice_qp_y : Int
disable_deblocking_filter_idc : Int
slice_alpha_c0_offset_div2 : Int
slice_beta_offset_div2 : Int
}pub struct Sps {
sps_id : Int
profile_idc : Int
constraint_set_flags : Int
level_idc : Int
chroma_format_idc : Int
bit_depth_luma : Int
bit_depth_chroma : Int
log2_max_frame_num : Int
pic_order_cnt_type : Int
log2_max_pic_order_cnt_lsb : Int
delta_pic_order_always_zero_flag : Bool
offset_for_non_ref_pic : Int
offset_for_top_to_bottom_field : Int
offset_for_ref_frame : Array[Int]
max_num_ref_frames : Int
gaps_in_frame_num_allowed : Bool
pic_width_in_mbs : Int
pic_height_in_mbs : Int
frame_mbs_only_flag : Bool
direct_8x8_inference_flag : Bool
frame_cropping_flag : Bool
crop_left : Int
crop_right : Int
crop_top : Int
crop_bottom : Int
matrix_coefficients : Int
}fn chroma_qp_from_luma(qp_y : Int, offset : Int) -> Intfn deblock_frame(y_plane : FixedArray[Byte], u_plane : FixedArray[Byte], v_plane : FixedArray[Byte], mb_w : Int, mb_h : Int, mb_is_intra : FixedArray[Bool], mb_qp : FixedArray[Int], mb_slice_id : FixedArray[Int], mb_disable_deblock : FixedArray[Int], mb_alpha_off : FixedArray[Int], mb_beta_off : FixedArray[Int], chroma_qp_offset : Int, nnz_luma : FixedArray[Int], mv_x : FixedArray[Int], mv_y : FixedArray[Int], ref_pic_id : FixedArray[Int]) -> Unitfn dequant_4x4(block : FixedArray[Int], qp : Int, skip_dc : Bool) -> Unitfn ebsp_to_rbsp(data : Bytes, start : Int, end_ : Int) -> Bytesfn error_message(err : Error) -> Stringfn idct_4x4_add(coeffs : FixedArray[Int], plane : FixedArray[Byte], stride : Int, x0 : Int, y0 : Int) -> Unitfn idct_4x4_dc_add(dc_val : Int, plane : FixedArray[Byte], stride : Int, x0 : Int, y0 : Int) -> Unitfn inverse_hadamard_chroma_dc(c : FixedArray[Int], qp_c : Int) -> FixedArray[Int]fn inverse_hadamard_luma_dc(c : FixedArray[Int], qp : Int) -> FixedArray[Int]fn mc_chroma_block(ref_c : FixedArray[Byte], dst_c : FixedArray[Byte], cw : Int, ch : Int, x0 : Int, y0 : Int, bw : Int, bh : Int, mvx : Int, mvy : Int) -> Unitfn mc_luma_block(ref_y : FixedArray[Byte], dst_y : FixedArray[Byte], pic_w : Int, pic_h : Int, x0 : Int, y0 : Int, bw : Int, bh : Int, mvx : Int, mvy : Int) -> Unitfn nal_unit_type_name(nal_type : Int) -> Stringfn predict_intra_16x16(plane : FixedArray[Byte], stride : Int, x0 : Int, y0 : Int, mode : Int, avail_top : Bool, avail_left : Bool) -> Unitfn predict_intra_4x4(plane : FixedArray[Byte], stride : Int, x0 : Int, y0 : Int, mode : Int, avail_top : Bool, avail_left : Bool, avail_top_right : Bool, avail_top_left : Bool) -> Unitfn predict_intra_chroma_8x8(plane : FixedArray[Byte], stride : Int, x0 : Int, y0 : Int, mode : Int, avail_top : Bool, avail_left : Bool) -> Unitfn predict_mv_l0(mv_x : FixedArray[Int], mv_y : FixedArray[Int], ref_idx : FixedArray[Int], mb_slice_id : FixedArray[Int], mb_w : Int, cur_slice_id : Int, bx : Int, by : Int, bw4 : Int, cur_ref : Int, part_mode : Int) -> (Int, Int)fn verify_cavlc_tables_integrity() -> Boolfn yuv420p_to_rgba(y_plane : Bytes, u_plane : Bytes, v_plane : Bytes, width : Int, height : Int, bt709? : Bool) -> Byteslet zigzag_4x4 : FixedArray[Int]Install
Download zipPure-MoonBit ITU-T H.264/AVC Constrained Baseline video decoder, bit-exact FFmpeg-verified YUV420p engine, macroblock/MV inspector, and zero-upload browser player