# Packetized elementary stream

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Packetized_elementary_stream
> Markdown URL: https://mediated.wiki/source/Packetized_elementary_stream.md
> Source: https://en.wikipedia.org/wiki/Packetized_elementary_stream
> Source revision: 1305271693
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Specification of the MPEG-2 standard}}
<!-- {{context}} -->
'''Packetized Elementary Stream''' ('''PES''') is a [specification](/source/specification) in the [MPEG-2](/source/MPEG-2) Part 1 (Systems) (ISO/IEC 13818-1) and ITU-T H.222.0<ref>{{cite web |url=http://www.itu.int/dms_pubrec/itu-t/rec/h/T-REC-H.222.0-201410-I!!SUM-HTM-E.htm |title=H.222.0 Summary |author=ITU-T |date=November 2014 |access-date=2015-11-17 |archive-date=2015-03-16 |archive-url=https://web.archive.org/web/20150316011112/http://www.itu.int/dms_pubrec/itu-t/rec/h/T-REC-H.222.0-201410-I!!SUM-HTM-E.htm |url-status=dead }}</ref><ref>{{cite web |url=http://www.itu.int/rec/T-REC-H.222.0 |title=H.222.0 : Information technology - Generic coding of moving pictures and associated audio information: Systems |author=ITU-T |access-date=2010-06-03}}</ref> that defines carrying of [elementary stream](/source/elementary_stream)s (usually the output of an audio or video encoder) in packets within [MPEG program streams](/source/MPEG_program_stream) and [MPEG transport streams](/source/MPEG_transport_stream).<ref name="13818-1">{{cite web|title=ISO/IEC 13818-1 — Information technology — Generic coding of moving pictures and associated audio information: Systems|edition=second|date=2000-12-01|url=https://forums.xilinx.com/xlnx/attachments/xlnx/DSPTOOL/15095/1/iso13818-1.pdf|access-date=2009-07-25}}</ref> The elementary stream is [packetized](/source/Packet_(information_technology)) by encapsulating sequential data bytes from the elementary stream inside PES packet headers.

A typical method of transmitting elementary stream data from a video or audio encoder is to first create PES packets from the elementary stream data and then to encapsulate these PES packets inside Transport Stream (TS) packets or Program Stream (PS) packets. The TS packets can then be [multiplexed](/source/multiplexed) and transmitted using broadcasting techniques, such as those used in an [ATSC](/source/ATSC_tuner) and [DVB](/source/Digital_Video_Broadcasting).

Transport Streams and Program Streams are each logically constructed from PES packets. PES packets shall be used to convert between Transport Streams and Program Streams. In some cases the PES packets need not be modified when performing such conversions. PES packets may be much larger than the size of a Transport Stream packet.<ref name="13818-1"/>

== PES packet header ==
{|class="wikitable"
!Name!!Size!!Description
|-
|Packet start code prefix||3 bytes||0x000001
|-
|Stream id||1 byte||Examples: Audio streams (0xC0-0xDF), Video streams (0xE0-0xEF) <ref>{{cite web|url=https://www.etsi.org/deliver/etsi_ts/101100_101199/101154/01.09.01_60/ts_101154v010901p.pdf|title=ETSI TS 101 154 - V1.9.1 - Digital Video Broadcasting (DVB); Specification for the use of Video and Audio Coding in Broadcasting Applications based on the MPEG-2 Transport Stream|date=September 2009|publisher=[ETSI](/source/ETSI)}}</ref><ref>{{cite patent|country=EP|number=1827030|title=Method and apparatus for changing codec to reproduce video and/or audio data streams encoded by different codecs within a channel}}</ref>
|-
| || ||Note: The above 4 bytes is called the 32 bit [start code](/source/start_code).
|-
|PES Packet length||2 bytes||Specifies the number of bytes remaining in the packet after this field. Can be zero. If the PES packet length is set to zero, the PES packet can be of any length. A value of zero for the PES packet length can be used only when the PES packet payload is a video elementary stream.<ref>{{cite web|url=http://happy.emu.id.au/lab/tut/dttb/dtbtut4b.htm#s4p4|title=A guide to digital terrestrial television broadcasting in the VHF/UHF bands|at=sec. 4.4|date=15 January 1996}}</ref> 
|-
|Optional PES header||variable length (length >= 3)||not present in case of Padding stream & Private stream 2 (navigation data)
|-
|Data|| ||See [elementary stream](/source/elementary_stream). In the case of private streams the first byte of the payload is the sub-stream number.
|}

=== Optional PES header ===
{|class="wikitable"
!Name!!Number of Bits!!Description
|-
|Marker bits||2||'''10''' [binary](/source/Binary_numeral_system) or 0x2 [hex](/source/Hexadecimal)
|-
|Scrambling control||2||00 implies not scrambled
|-
|Priority||1||
|-
|Data alignment indicator||1||1 indicates that the PES packet header is immediately followed by the video start code or audio [syncword](/source/syncword)
|-
|Copyright||1||1 implies copyrighted
|-
|Original or Copy||1||1 implies original
|-
|[PTS](/source/Presentation_time_stamp) DTS indicator||2||11 = both present, 01 is forbidden, 10 = only [PTS](/source/Presentation_time_stamp), 00 = no PTS or DTS
|-
|ESCR flag||1||
|-
|ES rate flag||1||
|-
|DSM trick mode flag||1||
|-
|Additional copy info flag||1||
|-
|CRC flag||1||
|-
|extension flag||1||
|-
|PES header length||8||gives the length of the remainder of the PES header in bytes 
|-
|Optional fields||variable length||presence is determined by flag bits above
|-
|Stuffing Bytes||variable length||0xff
|}

While above flags indicate that values are appended into variable length optional fields, they are not just simply written out. For example, PTS (and DTS) is expanded from 33 bits to 5 bytes (40 bits). If only PTS is present, this is done by catenating 0010b, most significant 3 bits from PTS, 1, following next 15 bits, 1, rest 15 bits and 1. If both PTS and DTS are present the same is done, but first 4 bits before start of PTS bits are 0011b (and not 0010b) and first 4 bits before start of DTS bits are 0001b. Other appended bytes have similar but different encoding.

==References==
<references />

==External links==
* http://www.bretl.com/mpeghtml/pespckt.HTM
* https://dvd.sourceforge.net/dvdinfo/pes-hdr.html
* [ISO](/source/International_Organization_for_Standardization)/[IEC](/source/International_Electrotechnical_Commission) standard 13818-1 [https://forums.xilinx.com/xlnx/attachments/xlnx/DSPTOOL/15095/1/iso13818-1.pdf])

{{Compression formats}}

Category:MPEG

---
Adapted from the Wikipedia article [Packetized elementary stream](https://en.wikipedia.org/wiki/Packetized_elementary_stream) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Packetized_elementary_stream?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
