code: def to_packets(pages, strict=False):
          
  
          serial = pages[0].serial
          sequence = pages[0].sequence
          packets = []
  
          if strict:
              if pages[0].continued:
                  raise ValueError("first packet is continued")
              if not pages[-1].complete:
                  raise ValueError("last packet does not complete")
          elif pages and pages[0].continued:
              packets.append([b""])
  
          for page in pages:
              if serial != page.serial:
                  raise ValueError("invalid serial number in %r" % page)
              elif sequence != page.sequence:
                  raise ValueError("bad sequence number in %r" % page)
              else:
                  sequence += 1
  
              if page.continued:
                  packets[-1].append(page.packets[0])
              else:
                  packets.append([page.packets[0]])
              packets.extend([p] for p in page.packets[1:])
  
          return [b"".join(p) for p in packets]
docs: Construct a list of packet data from a list of Ogg pages.
  
          If strict is true, the first page must start a new packet,
          and the last page must end the last packet.