Log in

View Full Version : LPCM in m2ts


ipanema
21st February 2010, 01:53
I have an m2ts file with 48kHz 2 Channel LPCM. The LPCM frames all seem to begin with a 4 byte sequence

0x03 0xC0 0x31 0x40

Is this a well known LPCM header? I can't find any reference to it after a lot of searching.

I *think* the 0x03 0xC0 might be the frame length as a 16-bit big endian value (960 decimal), but I can't be sure, and I've no idea what the 0x31 0x40 is.

Does anyone know?

Also, I'd like to write a program to extract the LPCM and store it in a WAV file. Should I be including or ignoring these 4 bytes when copying the samples into a WAV file?

tebasuna51
21st February 2010, 04:38
LPCM don't have headers is just raw audio data.
I don't know if this headers (inside the m2ts) are documented anywhere.

I make a lot of search without succes but after my test I make Pcm2Tsmu (http://forum.doom9.org/showthread.php?t=138417)
Read the source file .cs

BTW, to extract the LPCM track, from a m2ts, to wav you can use (if the LPCM is the track 2):

eac3to input.m2ts 2: output.wav

drmpeg
21st February 2010, 08:19
I have an m2ts file with 48kHz 2 Channel LPCM. The LPCM frames all seem to begin with a 4 byte sequence

0x03 0xC0 0x31 0x40

Is this a well known LPCM header? I can't find any reference to it after a lot of searching.

I *think* the 0x03 0xC0 might be the frame length as a 16-bit big endian value (960 decimal), but I can't be sure, and I've no idea what the 0x31 0x40 is.

Does anyone know?

Also, I'd like to write a program to extract the LPCM and store it in a WAV file. Should I be including or ignoring these 4 bytes when copying the samples into a WAV file?

It's a header.

size in bytes = 16 bits
channel assignment = 4 bits
sampling frequency = 4 bits
bits per sample = 2 bits
start flag = 1 bit
reserved = 5 bits

channel assignment
1 = mono
3 = stereo
4 = 3/0
5 = 2/1
6 = 3/1
7 = 2/2
8 = 3/2
9 = 3/2+lfe
10 = 3/4
11 = 3/4+lfe

sampling frequency
1 = 48 kHz
4 = 96 kHz
5 = 192 kHz

bits per sample
1 = 16
2 = 20
3 = 24

Your example of 0x03 0xC0 0x31 0x40 is:

960 bytes
stereo
48 kHz
16 bits/sample

Ron

ipanema
21st February 2010, 12:46
Thanks for explaining the header. It doesn't look at all like the LPCM header that is used in the DVD MPEG program stream files.

Is this 4-byte header LPCM part of some other specification - maybe BluRay? And are you always likely to find this header in m2ts files that contain LPCM?

drmpeg
21st February 2010, 13:31
Thanks for explaining the header. It doesn't look at all like the LPCM header that is used in the DVD MPEG program stream files.

Is this 4-byte header LPCM part of some other specification - maybe BluRay? And are you always likely to find this header in m2ts files that contain LPCM?
The m2ts format is only used for Blu-Ray and AVCHD. But AVCHD is based on Blu-Ray, so ipso facto, the LPCM header is from Blu-Ray.

Ron

ipanema
21st February 2010, 14:04
Thanks. One final question.

The PMT entry for the LPCM audio has stream_id 0x80 which is just "private data". How do you determine for sure that the audio stream is really LPCM?

drmpeg
22nd February 2010, 02:25
Thanks. One final question.

The PMT entry for the LPCM audio has stream_id 0x80 which is just "private data". How do you determine for sure that the audio stream is really LPCM?

The PMT stream_type has some additional definitions in Blu-Ray.

0x80 = LPCM
0x81 = AC3
0x82 = DTS
0x83 = MLP
0x84 = DD+
0x85 = DTS-HD
0x86 = DTS-HD with XLL
0xA1 = DD+ for secondary audio
0xA2 = DTS-HD LBR for secondary audio

Ron

ipanema
24th February 2010, 19:45
That's great. Thanks for your help.