# pydicom.encaps.generate_frames

pydicom.encaps.generate_frames(buffer: bytes | ReadableBuffer, *, number_of_frames: int | None = None, extended_offsets: tuple[list[int], list[int]] | tuple[bytes, bytes] | None = None, endianness: str = '<') → Iterator[bytes]

  Yield complete pixel data frames from buffer.

  Added in version 3.0.

  Note

  When the Basic Offset Table is empty and the Extended Offset Table isn’t supplied then more frames may be yielded than given by number_of_frames provided there are sufficient excess fragments available.

  Parameters:

    - buffer (bytes | readable buffer) – A buffer containing the encapsulated frame data, starting at the first byte of the basic offset table. May be `bytes`, `bytearray` or an object with `read()`, `tell()` and `seek()` methods. If the latter then the final offset position depends on the number of yielded frames.

    - number_of_frames (int, optional) – Required when the Basic Offset Table is empty and the Extended Offset Table has not been supplied. This should be the value of (0028,0008) Number of Frames or the expected number of frames in the encapsulated data.

    - extended_offsets (tuple[list[int], list[int]] or tuple[bytes, bytes], optional) – The (offsets, lengths) of the Extended Offset Table as taken from (7FE0,0001) Extended Offset Table and (7FE0,0002) Extended Offset Table Lengths as either the raw encoded values or a list of their decoded equivalents.

    - endianness (str, optional) – If `"<"` (default) then the encapsulated data uses little endian encoding, otherwise if `">"` it uses big endian encoding.

  Yields:

    bytes – The encoded pixel data, one frame at a time.

  References

  DICOM Standard Part 5, Annex A