public void StartMuxing(string outPath, BackgroundWorker worker, TsFileType outType, List<ushort> pidsToKeep, TimeSpan ts, TimeSpan te, bool useAsync, PesFile input) { StartMuxing(outPath, worker, outType, pidsToKeep, ts, te, useAsync, false, false, input, null, TimeSpan.Zero, TimeSpan.Zero); }
public void StartMuxing(string outPath, BackgroundWorker worker, TsFileType outType, List<ushort> pidsToKeep, TimeSpan ts, TimeSpan te, bool useAsync, bool processAudio, bool MlpToAc3, PesFile input, PesFile secondary, TimeSpan offset, TimeSpan chapterLen) { inFile = input; bw = worker; List<StreamInfo> sis = new List<StreamInfo>(); PesPacket[] ppa = null; PesPacket[] spa = null; BluRayOutput bo = null; Int64 startTrim = inFile.StartPcr + ((Int64)ts.TotalSeconds * (Int64)Constants.MPEG2TS_CLOCK_RATE); if (startTrim > Constants.MAX_MPEG2TS_CLOCK) startTrim -= Constants.MAX_MPEG2TS_CLOCK; foreach (StreamInfo si in inFile.StreamInfos) if (pidsToKeep.Contains(si.ElementaryPID)) sis.Add(si); if(null != secondary && pidsToKeep.Contains(secondary.StreamInfos[0].ElementaryPID)) sis.Add(secondary.StreamInfos[0]); switch(outType) { case TsFileType.BLU_RAY: bo = new BluRayOutput(outPath, chapterLen); outFile = new BlueMux(Path.Combine(outPath, @"BDMV\STREAM\00001.m2ts"), outType, sis, useAsync, processAudio, MlpToAc3); break; case TsFileType.MKV: outFile = new MkvMux(outPath, sis, useAsync, processAudio); break; case TsFileType.DEMUX: outFile = new DeMux(outPath, sis, useAsync, processAudio); break; default: outFile = new BlueMux(outPath, outType, sis, useAsync, processAudio, MlpToAc3); break; } if (ts.TotalSeconds == 0) inFile.Seek(-1); else inFile.Seek(startTrim); if (te.TotalSeconds > 0) { endTrim = inFile.EndPcr - ((Int64)te.TotalSeconds * (Int64)Constants.MPEG2TS_CLOCK_RATE); if (endTrim < 0) endTrim += Constants.MAX_MPEG2TS_CLOCK; } inFile.SetPcrDelegate(new PcrChanged(UpdatePcr)); inFile.SetPtsDelegate(new PtsChanged(UpdatePts)); startOffset = startTrim + ((Int64)offset.TotalSeconds * (Int64)Constants.MPEG2TS_CLOCK_RATE); if (startOffset > Constants.MAX_MPEG2TS_CLOCK) startOffset -= Constants.MAX_MPEG2TS_CLOCK; for (ppa = inFile.GetNextPesPackets(); ppa != null && ppa.Length > 0 && subtitles == false; ppa = inFile.GetNextPesPackets()) { if (worker.CancellationPending || done) goto leave_routine; foreach (PesPacket pp in ppa) if (null != pp) outFile.MuxPacket(pp); else goto leave_routine; } if (subtitles) { if (null != secondary && ppa != null && ppa.Length > 0) { secondary.Seek(-1); spa = secondary.GetNextPesPackets(); PesPacket sp = spa[0]; PesHeader sh = sp.GetHeader(); PesHeader ph = ppa[0].GetHeader(); while (ph == null || ph.HasPts == false) { if (worker.CancellationPending || done) goto leave_routine; foreach (PesPacket pp in ppa) if (null != pp) outFile.MuxPacket(pp); ppa = inFile.GetNextPesPackets(); if (ppa == null || ppa.Length == 0 || ppa[0] == null) goto leave_routine; ph = ppa[0].GetHeader(); } Int64 ptsOffset = ph.Pts - sh.Pts; bool clock = true; for (; ppa != null && ppa.Length > 0 && ppa[0] != null; ppa = inFile.GetNextPesPackets()) { foreach (PesPacket pp in ppa) { ph = pp.GetHeader(); if (sh != null && ph != null && ph.HasPts) { if (clock) { Int64 time = sh.Pts + ptsOffset; if (time < 0) time += Constants.MAX_PTS_CLOCK; else if (time > Constants.MAX_PTS_CLOCK) time -= Constants.MAX_PTS_CLOCK; sh.Pts = time; for (int i = 9; i < 14; i++) sp[i] = sh[i]; // copy PTS if (sh.HasDts) { time = sh.Dts + ptsOffset; if (time < 0) time += Constants.MAX_PTS_CLOCK; else if (time > Constants.MAX_PTS_CLOCK) time -= Constants.MAX_PTS_CLOCK; sh.Dts = time; for (int i = 14; i < 19; i++) sp[i] = sh[i]; // copy DTS } clock = false; } Int64 delta = sh.Pts - ph.Pts; if (delta > (0 - Constants.PTS_CLOCK_RATE) && delta < Constants.PTS_CLOCK_RATE) { outFile.MuxPacket(sp); spa = secondary.GetNextPesPackets(); if (spa != null && spa.Length > 0 && spa[0] != null) { sp = spa[0]; sh = sp.GetHeader(); clock = true; } } } outFile.MuxPacket(pp); } } } else { for (; ppa != null && ppa.Length > 0; ppa = inFile.GetNextPesPackets()) { if (worker.CancellationPending || done) goto leave_routine; foreach (PesPacket pp in ppa) if (null != pp) outFile.MuxPacket(pp); else goto leave_routine; } } } leave_routine: outFile.Close(); if (outType == TsFileType.BLU_RAY) { bo.Author(outFile.EpData, outFile.Psi, outFile.CurrentPacketNumber); } }
public Coordinator() { inFile = null; outFile = null; done = false; endTrim = -1; bw = null; seconds = 0; subtitles = false; startOffset = 0; }
private void init() { InitializeComponent(); inFile = null; length = new TimeSpan(); pidList = new List<ushort>(); pidsToKeep = new List<ushort>(); OutputFileBrowseButton.Enabled = false; RemuxButton.Enabled = false; OpenOutputFileDialog.OverwritePrompt = false; DisableNumerics(); RemuxButton.Text = "Remux"; AssemblyName an = Assembly.GetExecutingAssembly().GetName(); this.Text = an.Name + " v." + an.Version.ToString(4) + " by dmz, modified by spacecat56 and hobBIT"; state = SaveState.Remux; elmName = string.Empty; elmPid = 0; supPresent = false; supFile = null; // hobBIT _bAutoFilled = false; _LogAddons = new ArrayList(); }
private void RemoveSup() { if (supPresent) { pidList.RemoveAt(pidList.Count - 1); ElementaryStreamsListBox.Items.RemoveAt(ElementaryStreamsListBox.Items.Count - 1); pidsToKeep.Remove(supFile.StreamInfos[0].ElementaryPID); supPresent = false; supFile.CloseFile(); supFile = null; } SupStart = TimeSpan.Zero; DisableSup(); }
private void OpenSupFileDialog_FileOk(object sender, CancelEventArgs e) { RemoveSup(); supFile = PesFile.OpenFile(OpenSupFileDialog.FileName, cbxUseAsyncIO.Checked, backgroundWorker2); if (supFile.FileType != TsFileType.SUP_ELEMENTARY) { MessageBox.Show(String.Format("File \"{0}\" is not a valid SUP file.", OpenSupFileDialog.FileName)); return; } ushort pid = Constants.DEFAULT_PRESENTATION_GRAPHICS_PID; while (PidExists(pid)) pid++; supFile.StreamInfos[0].ElementaryPID = pid; pidList.Add(pid); ElementaryStreamsListBox.Items.Add(String.Format("Presentation Graphics Stream # {0}", supFile.StreamInfos[0].ElementaryPID & 0xf)); ElementaryStreamsListBox.SetItemChecked(ElementaryStreamsListBox.Items.Count - 1, true); EnableSup(); supPresent = true; }
private void OpenFile(string filename) { if (null != inFile) { inFile.CloseFile(); inFile = null; } if (null != supFile) { supFile.CloseFile(); supFile = null; } inFile = PesFile.OpenFile(filename, cbxUseAsyncIO.Checked, backgroundWorker2); }