{"record":{"id":"0816153b821669b2","repo":"pion/webrtc","slug":"data-is-not-a-h265-hevc-bitstream","errorCode":null,"errorMessage":"data is not a H265/HEVC bitstream","messagePattern":"data is not a H265/HEVC bitstream","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/h265reader/h265reader.go","lineNumber":26,"sourceCode":"\t\"bytes\"\n\t\"errors\"\n\t\"io\"\n)\n\n// H265Reader reads data from stream and constructs h265 nal units.\ntype H265Reader struct {\n\tstream                      io.Reader\n\tnalBuffer                   []byte\n\tcountOfConsecutiveZeroBytes int\n\tnalPrefixParsed             bool\n\treadBuffer                  []byte\n\ttmpReadBuf                  []byte\n\tincludeSEI                  bool\n}\n\nvar (\n\terrNilReader           = errors.New(\"stream is nil\")\n\terrDataIsNotH265Stream = errors.New(\"data is not a H265/HEVC bitstream\")\n)\n\nfunc (reader *H265Reader) shouldSkipNAL(naluType NalUnitType) bool {\n\treturn !reader.includeSEI && (naluType == NalUnitTypePrefixSei || naluType == NalUnitTypeSuffixSei)\n}\n\n// NewReader creates new H265Reader.\nfunc NewReader(in io.Reader) (*H265Reader, error) {\n\tif in == nil {\n\t\treturn nil, errNilReader\n\t}\n\n\treader := &H265Reader{\n\t\tstream:          in,\n\t\tnalBuffer:       make([]byte, 0),\n\t\tnalPrefixParsed: false,\n\t\treadBuffer:      make([]byte, 0),\n\t\ttmpReadBuf:      make([]byte, 4096),","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/h265reader/h265reader.go#L8-L44","documentation":"Returned when the head of the stream does not contain a valid H265/HEVC Annex-B start-code prefix: fewer than 3 bytes read, or no 00 00 01 / 00 00 00 01 sequence found by bitStreamStartsWithH265Prefix. The reader rejects data that cannot be an HEVC bitstream before parsing.","triggerScenarios":"First NextNAL/parse call on data lacking HEVC start codes, or a stream shorter than 3 bytes.","commonSituations":"Feeding H264 data to the H265 reader, raw NAL units without start codes, container formats (MP4/HVCC) that are length-prefixed rather than Annex-B, empty/truncated files.","solutions":["Confirm the input is HEVC Annex-B (begins with a start code) before parsing.","If the source is H264, use h264reader; if containerized, convert to Annex-B first.","Check the stream isn't empty or truncated."],"exampleFix":"// before\nrdr, _ := h265reader.NewReader(h264Stream) // wrong codec\n// after\nif !bytes.Contains(head[:4], []byte{0, 0, 1}) {\n    return fmt.Errorf(\"input is not H265/HEVC Annex-B bitstream\")\n}\nrdr, err := h265reader.NewReader(hevcStream)","handlingStrategy":"validation","validationCode":"head := make([]byte, 4)\nn, _ := io.ReadFull(stream, head)\nif n < 4 || head[0] != 0 || head[1] != 0 || head[2] != 1 && head[2] != 0 {\n    return errors.New(\"not an H265/HEVC Annex-B bitstream\")\n}\nstream.Seek(0, io.SeekStart)","typeGuard":null,"tryCatchPattern":"_, err := reader.NextNAL()\nif err == errDataIsNotH265Stream {\n    return fmt.Errorf(\"input is not H265/HEVC Annex-B: %w\", err)\n}","preventionTips":["Verify codec is HEVC before using h265reader (use a probe like ffprobe).","Remux HVCC/MP4 input into Annex-B format before parsing.","Reject empty or sub-4-byte inputs early."],"tags":["go","media","h265","hevc","bitstream-format"],"backgroundTag":"invalid-bitstream-format","analyzedSha":"8c25dc09fa9e7c09aac4309ead88093d760432b0","analyzedAt":"2026-09-03T21:56:56.182Z","contentChangedAt":"2026-09-03T21:56:56.182Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}