{"record":{"id":"2c6798901d416482","repo":"commaai/openpilot","slug":"slice-type-must-be-0-1-or-2","errorCode":null,"errorMessage":"slice_type must be 0, 1, or 2","messagePattern":"slice_type must be 0, 1, or 2","errorType":"exception","errorClass":"VideoFileInvalid","httpStatus":null,"severity":"error","filePath":"openpilot/tools/lib/vidindex.py","lineNumber":258,"sourceCode":"  # in bitstreams conforming to this version of this Specification. Other values for num_extra_slice_header_bits are reserved\n  # for future use by ITU-T | ISO/IEC. However, decoders shall allow num_extra_slice_header_bits to have any value.\n  # TODO: get from PPS_NUT pic_parameter_set_rbsp( ) for corresponding slice_pic_parameter_set_id\n  num_extra_slice_header_bits = 0\n  skip_bits += num_extra_slice_header_bits\n\n  # 7.4.7.1 General slice segment header semantics\n  # slice_type specifies the coding type of the slice according to Table 7-7.\n  # Table 7-7 - Name association to slice_type\n  # slice_type | Name of slice_type\n  #     0      | B (B slice)\n  #     1      | P (P slice)\n  #     2      | I (I slice)\n  # unsigned integer 0-th order Exp-Golomb-coded syntax element with the left bit first\n  slice_type, _ = get_ue(dat, rbsp_start, skip_bits)\n  if DEBUG:\n    print(\"  slice_type:\", slice_type, f\"(first slice: {is_first_slice})\")\n  if slice_type > 2:\n    raise VideoFileInvalid(\"slice_type must be 0, 1, or 2\")\n  return slice_type, is_first_slice\n\ndef hevc_index(hevc_file_name: str, allow_corrupt: bool=False) -> tuple[list, int, bytes]:\n  with FileReader(hevc_file_name) as f:\n    dat = f.read()\n\n  if len(dat) < NAL_UNIT_START_CODE_SIZE + 1:\n    raise VideoFileInvalid(\"data is too short\")\n\n  if dat[0] != 0x00:\n    raise VideoFileInvalid(\"first byte must be 0x00\")\n\n  prefix_dat = b\"\"\n  frame_types = []\n\n  i = 1 # skip past first byte 0x00\n  try:\n    while i < len(dat):","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/tools/lib/vidindex.py#L240-L276","documentation":"Raised in get_hevc_slice_type() when the first ue(v) Exp-Golomb element of a slice segment header decodes to a value greater than 2. Per H.265 Table 7-7 only slice_type 0 (B), 1 (P), 2 (I) exist; all other values (3-9 are H.264-era repeat flags that HEVC removed) indicate the bit reader is misaligned — the stream is parsed at the wrong bit offset, usually due to a corrupt slice, wrong first-slice handling, or a file that is not HEVC.","triggerScenarios":"hevc_index() reaches a NAL typed as a slice (VCL NAL unit) and get_ue() at rbsp_start + skip_bits returns > 2. Happens with bitstream corruption, when emulation-prevention bytes were removed/added incorrectly upstream, or when an H.264 stream is fed to the HEVC indexer.","commonSituations":"Corrupt dashboard-camera segments (SD card wear, interrupted writes), processing a renamed H.264 qcamera file through the HEVC path, or indexing partially-uploaded cloud routes. Sometimes a single bad frame in an otherwise good route.","solutions":["Retry with allow_corrupt=True — hevc_index wraps the parse loop so a bad slice can be skipped.","Confirm the file is actually HEVC (check the SPS/parameter-set prefix data or run ffprobe) and not H.264 or an MP4 container.","If one segment of a route fails, re-download it; cloud-stored segments are sometimes incomplete on first fetch.","Inspect with an independent parser (ffprobe -show_frames) to confirm the file itself is damaged rather than a vidindex bug."],"exampleFix":"# before\nframes, prefix, prefix_dat = hevc_index(path)\n\n# after\ntry:\n    frames, prefix, prefix_dat = hevc_index(path)\nexcept VideoFileInvalid:\n    frames, prefix, prefix_dat = hevc_index(path, allow_corrupt=True)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    frames, prefix, prefix_dat = hevc_index(path)\nexcept VideoFileInvalid as e:\n    if 'slice_type' in str(e):\n        # bitstream desync: retry tolerating corruption, or re-fetch the segment\n        frames, prefix, prefix_dat = hevc_index(path, allow_corrupt=True)\n    else:\n        raise","preventionTips":["Validate with ffprobe that the file is HEVC and decodes before running vidindex.","Keep container->Annex-B conversions lossless (use -bsf:v hevc_mp4toannexb, never re-encode).","For cloud routes, verify segment upload completed before indexing."],"tags":["video","hevc","bitstream","corruption","openpilot"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}