Пример #1
0
        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
                                   ));
                    }
        }
Пример #2
0
        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);
        }
Пример #3
0
        private async Task <ClipEntry> CompileDocumentClip(CompilingProgressManager reporter, DocumentClipDescriptor clip, DirectoryInfo pesDir)
        {
            byte tId          = 0;
            var  tPgsTaskList = new List <Task <PgsEntryDescriptor> >();

            foreach (var iTrack in clip.Tracks)
            {
                tPgsTaskList.Add(Task.Run(
                                     () => CompileTrack(reporter, clip, iTrack, pesDir, Muxer.GetPgsPid(tId++))
                                     ));
            }
            await Task.WhenAll(tPgsTaskList);

            TimeSpan  tMaxLength = tPgsTaskList.Max(xPgsTask => xPgsTask.Result.Length);
            ClipEntry tClipEntry = new ClipEntry(clip.ClipId, clip.InTimeOffset, clip.InTimeOffset + tMaxLength);

            foreach (var iPgsTask in tPgsTaskList)
            {
                var tPgsDesc = iPgsTask.Result;
                var tPgs     = new PgsEntry(tPgsDesc.Pid, tPgsDesc.PesFile, tPgsDesc.Lang);
                tClipEntry.AddPgs(tPgs);
            }

            return(tClipEntry);
        }