[Ffmpeg-devel] mpeg2 program stream with LPCM question.

Måns Rullgård mru
Sat Jun 11 01:26:36 CEST 2005

Bill May <wmay at cisco.com> writes:

> Hi,
> I have a couple of question about LPCM in mpeg program stream files.  This
> is for my own program stream reader in mpeg4ip, although ffplay doesn't
> seem to play this particular file (made with Adobe's mpeg encoder).

We'd appreciate a sample of anything that doesn't decode correctly.
Could you please upload a few megabytes?

> 1). What specification covers how to insert these files ?

Most likely, the file you have is made according the DVD method of
storing LPCM in MPEG-PS.

> 2). In the file I have, I'm having trouble resolve PTS in the pes
> header with actual number of samples.  The PTS doesn't seem to
> correspond with the number of bytes in the PES, after removing
> the 3 byte header.  I can extract, then play the PCM, but the
> PTS doesn't seem to line up.
> For example: first PES has PTS of 19203, is 2008 bytes after removing
> the headers.  That should be 502 samples at 48000 or 941 ticks.  The
> PTS of the next pes is 20253 (a difference of 1050).
> When I extract the pcm data by pulling the data out (removing the 3 bytes),
> it plays fine.

The LPCM header is 7 bytes in all, including the substream id.  I
found this description somewhere:

   id                                                     8 bit
   number of frames                                       8 bit
   first acces unit pointer, i.e. start of audio frame   16 bit
   audio emphasis on-off                                  1 bit
   audio mute on-off                                      1 bit
   reserved                                               1 bit
   audio frame number                                     5 bit
   quantization word length                               2 bit
   audio sampling frequency (48khz = 0, 96khz = 1)        2 bit
   reserved                                               1 bit
   number of audio channels - 1 (e.g. stereo = 1)         3 bit
   dynamic range control (0x80 if off)                    8 bit

The PTS refers to the first start of a frame in the PES packet.  One
frame is 150 PTS ticks in length, or 80 samples at 48kHz.  The first
PES packet will contain a little over 6 frames, and the second packet
will begin with the remainder of the 7th frame.  The PTS of the second
packet refers to the start of the 8th frame, the location of which is
specified in the LPCM header.

M?ns Rullg?rd
mru at inprovide.com

More information about the ffmpeg-devel mailing list