示例#1
0
文件: Program.cs 项目: jokalee/Tuto
        public static PartsList CreateParts(List <string> tracks, MontageLog log, int title)
        {
            // chunk numbers to split after
            var breakChunkNumbers = log.Commands
                                    .Where(z => z.Action == MontageAction.CommitAndSplit)
                                    .Select(z => z.Id)
                                    .ToList();

            var chunks = Montager.Montager.CreateChunks(log, "", "");
            var isFace = new Dictionary <int, bool>
            {
                { 0, true }  // starts with 'face'
            };

            foreach (var chunk in chunks.Where(chunk => !isFace.Keys.Contains(chunk.Id)))
            {
                isFace.Add(chunk.Id, chunk.IsFaceChunk);
            }

            var parts = new PartsList(breakChunkNumbers);

            parts.MakeParts(tracks, isFace, title);

            return(parts);
        }
示例#2
0
        static void Test(MontageLog actions, params Action <Chunk, int>[] checks)
        {
            var chunks = Montager.CreateChunks(actions, faceFile, screenFile);

            Assert.AreEqual(checks.Length, chunks.Count);
            for (int i = 0; i < chunks.Count; i++)
            {
                // Assert.AreEqual(i, chunks[i].Id); по идее, их ID надо проверять отдельно
                checks[i](chunks[i], i);
            }
        }
示例#3
0
        static MontageLog CreateMontageLog(int fileSync, params object[] data)
        {
            var result = new MontageLog();

            result.FaceFileSync = fileSync;
            for (int i = 0; i < data.Length; i += 2)
            {
                result.Commands.Add(new MontageCommand {
                    Id = i, Time = (int)data[i], Action = (MontageAction)data[i + 1]
                });
            }
            return(result);
        }
示例#4
0
        public static List <Chunk> CreateChunks(MontageLog log, string faceFile, string screenFile)
        {
            var commands = log.Commands;

            var result = new List <Chunk>();

            if (commands[0].Action != MontageAction.StartFace)
            {
                throw new Exception("Expected StartFace as the first command");
            }
            int faceLogSync = commands[0].Time;

            if (commands[1].Action != MontageAction.StartScreen)
            {
                throw new Exception("Expected StartScreen as the second command");
            }
            int screenSync = commands[1].Time;


            int  currentTime = screenSync;
            bool isFace      = true;
            int  currentId   = 0;


            for (int i = 2; i < commands.Count; i++)
            {
                if (commands[i].Action == MontageAction.Delete)
                {
                    currentTime = commands[i].Time;
                    continue;
                }

                if (isFace)
                {
                    result.Add(new Chunk
                    {
                        Id          = commands[i].Id,
                        IsFaceChunk = true,
                        VideoSource = new ChunkSource
                        {
                            StartTime = currentTime - faceLogSync + log.FaceFileSync,
                            Duration  = commands[i].Time - currentTime,
                            File      = faceFile
                        }
                    });
                }
                else
                {
                    result.Add(new Chunk
                    {
                        Id          = commands[i].Id,
                        IsFaceChunk = false,
                        VideoSource = new ChunkSource
                        {
                            StartTime = currentTime - screenSync,
                            Duration  = commands[i].Time - currentTime,
                            File      = screenFile
                        },
                        AudioSource = new ChunkSource
                        {
                            StartTime = currentTime - faceLogSync + log.FaceFileSync,
                            Duration  = commands[i].Time - currentTime,
                            File      = faceFile
                        }
                    });
                }

                currentTime = commands[i].Time;
                if (commands[i].Action == MontageAction.Face)
                {
                    isFace = true;
                }
                if (commands[i].Action == MontageAction.Screen)
                {
                    isFace = false;
                }


                if (result[result.Count - 1].VideoSource.Duration == 0)
                {
                    result.RemoveAt(result.Count - 1);
                }
            }
            return(result);
        }