示例#1
0
        public static MontageLog ReadCommands(string filename)
        {
            var log = new MontageLog();
            int version = 0;
            int id = 0;
            using (var reader = new StreamReader(filename))
            {
                var ver=reader.ReadLine(); //version
                if (ver == "Montager v2") version = 1;

                reader.ReadLine(); //empty line
                reader.ReadLine(); //fsync prompt
                log.FaceFileSync = int.Parse(reader.ReadLine());
                reader.ReadLine(); //empty line
                while (true)
                {
                    if (version > 0)
                        reader.ReadLine(); //ID команды

                    var time = reader.ReadLine();
                    if (time == null) break;
                    var action = reader.ReadLine();
                    if (action == null) break;
                    reader.ReadLine();
                    log.Commands.Add(new MontageCommand { Id = id, Time = int.Parse(time), Action = (MontageAction)Enum.Parse(typeof(MontageAction), action) });
                    id++;
                }
            }
            return log;
        }
示例#2
0
 public static void WriteCommands(MontageLog log, string fileName)
 {
     using (var writer = new StreamWriter(fileName))
     {
         WriteVersion(writer);
         WriteFSync(writer, log.FaceFileSync);
         foreach (var e in log.Commands)
             WriteCommand(writer, e);
     }
 }
示例#3
0
 public static void WriteCommands(MontageLog log, string fileName)
 {
     using (var writer = new StreamWriter(fileName))
     {
         WriteVersion(writer);
         WriteFSync(writer, log.FaceFileSync);
         foreach (var e in log.Commands)
         {
             WriteCommand(writer, e);
         }
     }
 }
示例#4
0
        public static MontageLog ReadCommands(string filename)
        {
            var log     = new MontageLog();
            int version = 0;
            int id      = 0;

            using (var reader = new StreamReader(filename))
            {
                var ver = reader.ReadLine(); //version
                if (ver == "Montager v2")
                {
                    version = 1;
                }

                reader.ReadLine(); //empty line
                reader.ReadLine(); //fsync prompt
                log.FaceFileSync = int.Parse(reader.ReadLine());
                reader.ReadLine(); //empty line
                while (true)
                {
                    if (version > 0)
                    {
                        reader.ReadLine(); //ID команды
                    }
                    var time = reader.ReadLine();
                    if (time == null)
                    {
                        break;
                    }
                    var action = reader.ReadLine();
                    if (action == null)
                    {
                        break;
                    }
                    reader.ReadLine();
                    log.Commands.Add(new MontageCommand {
                        Id = id, Time = int.Parse(time), Action = (MontageAction)Enum.Parse(typeof(MontageAction), action)
                    });
                    id++;
                }
            }
            return(log);
        }
示例#5
0
        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;
        }
示例#6
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;
        }
示例#7
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;
 }
示例#8
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);
     }
 }