The DTS stream is modified by TSMuxerVideo, using DTSAudioOutputStream and PCMAudioOutputStream.
Each DTS frame is embedded into a larger (2048b) PCM frame, and addition space within is zero padded.
The funny thing is that also an LPCM header is generated, but it seems to be never written to the stream.
So, I wonder what the trick is to make the DTS look like PCM format.
I tried various things, but I always loose proper format detection, even with powerful PC-tools.
For reference, I add the code I use to attempt to do the same, based on the Java code in PS3MediaServer. Any pointers from anyone?
- Code: Select all
from array import *
from struct import *
def lpcm_header(nr_channels, sample_freq, bits_sample):
blocksize = 2 * int((nr_channels+1)/2) * sample_freq * bits_sample / 1600
payload = array('B', [0, 0, 49, 0])
payload = ((blocksize >> 8) & 0xff)
payload = ((blocksize+256)%256)
payload = (16*(bits_sample-12))
def pack_dts_as_pcm(infile, outfile):
dts = open(infile, 'rb')
pcm = open(outfile, 'wb')
bits = [16, 16, 20, 20, 0, 24, 24]
data = array('B')
header = array('B')
if header == 0x64 and header == 0x58 and header == 0x20 and header == 0x25:
print "Found DTS-HD frame"
elif header == 0x7f and header == 0xfe and header == 0x80 and header == 0x01:
#print "Found DTS frame"
framesize = ((header & 0x03) << 12) + ((header & 0xff) << 4) + ((header & 0xf0) >> 4) + 1
bitspersample = bits[((header & 0x01) << 2) + ((header & 0xfc) >> 6)]
# Should we prepend the DTS content with a LPCM header?
#lpcm_header(2, 48000, 16).tofile(pcm)
# write DTS header
# write DTS frame
frame = array('B')
frame.fromfile(dts, framesize - 16)
# zero pad to fill frame
array('B', [0 for i in range(PCM_WRAPPED_FRAME_SIZE - framesize)]).tofile(pcm)
print >> sys.stderr, "Content not recognized"