From 60692631a0502e6c14643f49891af1ef213a6fe9 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sun, 10 Feb 2013 11:35:09 +0000 Subject: [PATCH] working on vobsub writer... git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1615 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Logic/VobSub/VobSubWriter.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Logic/VobSub/VobSubWriter.cs b/src/Logic/VobSub/VobSubWriter.cs index b846aaf7a..7ddb0cd62 100644 --- a/src/Logic/VobSub/VobSubWriter.cs +++ b/src/Logic/VobSub/VobSubWriter.cs @@ -99,13 +99,17 @@ namespace Nikse.SubtitleEdit.Logic.VobSub // fill out all info but the offets (determined later) - /* header - contains PTM */ - int ptm = (int)paragraph.StartTime.TotalMilliseconds; // should be end time, but STC writes start time? - PacketizedElementaryStreamHeaderBufferFirst[9] = (byte)(((ptm >> 29) & 0x0E) | 0x21); - PacketizedElementaryStreamHeaderBufferFirst[10] = (byte)(ptm >> 22); - PacketizedElementaryStreamHeaderBufferFirst[11] = (byte)((ptm >> 14) | 1); - PacketizedElementaryStreamHeaderBufferFirst[12] = (byte)(ptm >> 7); - PacketizedElementaryStreamHeaderBufferFirst[13] = (byte)(ptm * 2 + 1); + // PTM + const string pre = "0011"; // 0011 or 0010 ? + long newPts = (long)(paragraph.StartTime.TotalSeconds * 90000.0 + 0.5); + string bString = Convert.ToString(newPts, 2).PadLeft(33, '0'); + string fiveBytesString = pre + bString.Substring(0, 3) + "1" + bString.Substring(3, 15) + "1" + bString.Substring(18, 15) + "1"; + for (int i = 0; i < 5; i++) + { + byte b = Convert.ToByte(fiveBytesString.Substring((i * 8), 8), 2); + PacketizedElementaryStreamHeaderBufferFirst[9+i] = b; + } + // create control header // palette (store reversed) @@ -233,6 +237,7 @@ namespace Nikse.SubtitleEdit.Logic.VobSub else buf[ofs++] = twoPartBuffer.Buffer2[i - twoPartBuffer.Buffer1.Length]; } + int ofsRLE = tmp; // fill gap in first packet with (parts of) control header @@ -434,7 +439,8 @@ langidx: 0 # " + _languageName + @" id: " + _languageNameShort + @", index: 0 # Decomment next line to activate alternative name in DirectVobSub / Windows Media Player 6.x -# alt: English"); +# alt: English +# Vob/Cell ID: 1, 1 (PTS: 0)"); return sb; }