private int EncodePgs(DocumentClipDescriptor clip, EsTrackDescriptor track, Stream output, Spp2PgsNet.IProgressReporter reporter) { int maxFrameCount = 1; using (var tCtx = s2pEncoder.CreateSubPicProviderContext()) using (var tOutput = s2pEncoder.CreatePgsEncoder(output, clip.Format, clip.Rate)) { tOutput.RegistAnchor(0); foreach (var iEsEntry in track) { if (iEsEntry == null) { continue; } using (var tSpp = s2pEncoder.CreateSubPicProvider(tCtx, iEsEntry.Source)) { var tOffset = (int)FrameCountFromTime(iEsEntry.SyncOffset, clip.Rate); using (var tAdv = s2pEncoder.CreateSppFrameStreamAdvisor( tSpp, clip.Format, clip.Rate, -1, -1, tOffset, null) ) { maxFrameCount = Math.Max(tAdv.LastPossibleImage, tOffset + 1); using (var tInput = s2pEncoder.CreateFrameStream(tSpp, tAdv)) { s2pEncoder.Encode(tInput, tOutput, reporter); } } } } tOutput.FlushAnchor(); } return(maxFrameCount); }
private PgsEntryDescriptor CompileTrack(CompilingProgressManager reporter, DocumentClipDescriptor clip, EsTrackDescriptor track, DirectoryInfo pesDir, ushort pid) { const string PesFileNameFmt = "{0:00000}.{1:x4}.pes"; using (var tPgsStreamServer = new AnonymousPipeServerStream(PipeDirection.Out)) using (var tPgsStream = new AnonymousPipeClientStream(PipeDirection.In, tPgsStreamServer.ClientSafePipeHandle)) using (var tReporter = reporter.CreatePgsProgressReporter()) { Func <int> tEncodeTaskAction = () => { using (tPgsStreamServer) { return(EncodePgs(clip, track, tPgsStreamServer, tReporter)); } }; var tEncodeTask = Task.Run(tEncodeTaskAction); var tPesFileName = string.Format(PesFileNameFmt, clip.ClipId, pid); FileInfo tPesFile = pesDir.PickFile(tPesFileName); Pgs2Pes(tPgsStream, tPesFile); return(new PgsEntryDescriptor( pid, tPesFile.FullName, TimeFromFrameCount(tEncodeTask.Result, clip.Rate), track.Track.Lang )); } }