code: def _split_mjpeg_stream(s: bytes) -> List[bytes]:
      """Split a concatenated string of JPEG images into individual images."""
      # Jpeg files start with ffd8 and end with ffd9.
      start = b"\xff\xd8"
      end = b"\xff\xd9"
      if not (s.startswith(start) and s.endswith(end)):
          raise ValueError("Stream does not start and end correctly.")
      # Split by the start delimiter.
      parts = s.split(start)
      # The stream begins with the start delimiter so the first part should be empty
      assert not parts[0]
      # split() removes the delimiter, so add it back in.
      parts = [start + p for p in parts[1:]]
      # Check that each part starts and ends with the correct delimiters,
      # and check that the delimiters never occur elsewhere
      ok = all(
          (
              p.startswith(start)
              and p.endswith(end)
              and p.count(start) == p.count(end) == 1
          )
          for p in parts
      )
      if not ok:
          raise ValueError("Parts do not start and end correctly.")
      return parts
  
file_path: datasets/tensorflow_datasets/datasets/webvid/webvid_dataset_builder.py
imports: import io
  import os
  import pathlib
  import subprocess
  from typing import List
  from absl import logging
  from etils import epath
  import tensorflow_datasets.public_api
label_desc: Use image node_id 1 for calling a global function with example usage: _split_mjpeg_stream(s) and returns: parts