public void DoWork(EditorModel model, bool print)
 {
     if (recodeBeforeAssembling)
         RecodeFles(model);
     //AssemblyFromCommandLine(model);
     AssemblyWithExternalFile(model);
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            var srcDirectory = new DirectoryInfo(args[0]);
            //var dstDirectory = srcDirectory.Parent.CreateSubdirectory(srcDirectory.Name + "-converted");
			var dstDirectory = new DirectoryInfo("C:\\users\\user\\AIML-output");
			dstDirectory.Create();
			var input = dstDirectory.CreateSubdirectory("Input");
            var output = dstDirectory.CreateSubdirectory("Output");

            var global = new GlobalData();
            global.AfterLoad(dstDirectory);
            EditorModelIO.Save(global);

            var copying = "";

            
            foreach (var e in srcDirectory.GetDirectories())
            {
                var model = new EditorModel(e, srcDirectory, srcDirectory);
                ObsoleteModelIO.LoadAndConvert(model);
                var modelDst = input.CreateSubdirectory(e.Name);
                model.HackLocations(srcDirectory, modelDst);
                model.Save();
                //copying += string.Format(@"copy ""{0}\{2}"" ""{1}\{2}"""+"\n", e.FullName, modelDst.FullName, "face.mp4");
                //copying += string.Format(@"copy ""{0}\{2}"" ""{1}\{2}"""+"\n", e.FullName, modelDst.FullName, "desktop.avi");
                var files = e.GetFiles();
                copying += string.Format(@"xcopy ""{0}\AIML*.avi"" ""{1}\""" + "\n", e.FullName, output.FullName);
            }

            File.WriteAllText(dstDirectory + "\\copy.bat", copying);
        }
Beispiel #3
0
        public void DoWork(EditorModel model, bool print)
        {
            SrtMaker.WriteSrtFiles(model);
            model.CreateFileChunks();
            var epsodes = ListEpisodes(model.Montage.FileChunks).Select(e => MakeEpisode(model, e)).ToList();

            var episodeNumber = 0;
            foreach (var episode in epsodes)
            {
                var avsContext = new AvsContext();
                episode.SerializeToContext(avsContext);
                var avsScript = avsContext.Serialize(model);
                var avsFile = model.Locations.GetAvsStriptFile(episodeNumber);

                File.WriteAllText(avsFile.FullName, avsScript);

                var videoFile =  model.Locations.GetOutputFile(episodeNumber);
                if (videoFile.Exists) videoFile.Delete();

                var ffmpegCommand = new RenderAvsScript
                {
                    AvsInput = avsFile,
                    VideoOutput = videoFile
                };

                ffmpegCommand.Execute(print);
                episodeNumber++;
            }
        }
Beispiel #4
0
 internal void Load(EditorModel model, int episodeNumber)
 {
     Name = model.Montage.Information.Episodes[episodeNumber].Name;
     Duration = model.Montage.Information.Episodes[episodeNumber].Duration;
     RelativeFileLocation = model.Global.Locations.RelativeToGlobal(model.Locations.GetOutputFile(episodeNumber).FullName);
     RelativeSourceFolderLocation = model.Global.Locations.RelativeToGlobal(model.Locations.LocalFilePath.Directory.FullName);
     EpisodeNumber = episodeNumber;
 }
Beispiel #5
0
 public string Serialize(EditorModel model)
 {
     return string.Format(Format,
         model.Locations.AvsLibrary.FullName,
         model.Locations.AutoLevelsLibrary.FullName,
         model.Locations.VSFilterLibrary.FullName,
         internalData,
         String.Format(AvsNode.Template, 0));  // root of the tree has id 0
 }
Beispiel #6
0
 public static void Save(EditorModel model)
 {
     var container = new FileContainer
     {
         MontageModel = model.Montage,
         WindowState = model.WindowState
     };
     HeadedJsonFormat.Write<FileContainer>(model.Locations.LocalFilePath, localFileHeader, CurrentLocalVersion, container);
 }
Beispiel #7
0
 public static void WriteSrtFiles(EditorModel model)
 {
     int episode = 0;
     foreach(var str in CreateSrtFile(model))
     {
         File.WriteAllText(
             model.Locations.GetSrtFile(episode).FullName,
             str);
         episode++;
     }
 }
Beispiel #8
0
        static bool TryReadModel(EditorModel model)
        {
            var file = model.VideoFolder.GetFiles(Locations.LocalFileName).FirstOrDefault();
            if (file == null) return false;
            var container = HeadedJsonFormat.Read<FileContainer>(file, localFileHeader, CurrentLocalVersion, null, UpdateLocalV1, UpdateLocalV2);

            model.Montage = container.MontageModel;
            model.WindowState = container.WindowState;

            return true;
        }
Beispiel #9
0
 public static IEnumerable<SubtitleFix> ShiftFixes(EditorModel model)
 {
     foreach (var e in model.Montage.SubtitleFixes.OrderBy(z => z.StartTime))
     {
         yield return new SubtitleFix
         {
             StartTime=FindFinalLocation(e.StartTime, model.Montage.Chunks),
             Length=e.Length,
             Text=e.Text
         };
     }
 }
Beispiel #10
0
 public static List<int> CumulativeEpisodesLengthes(EditorModel model)
 {
     var list = new List<int>();
     list.Add(0);
     list.Add(0);
     foreach (var e in model.Montage.Chunks)
     {
         if (e.StartsNewEpisode) list.Add(list[list.Count-1]);
         if (e.IsActive) list[list.Count - 1] += e.Length;
     }
     return list;
 }
Beispiel #11
0
        void AssemblyFromCommandLine(EditorModel model)
        {
            var list = SeparateByEpisode(model);

            for (int i = 0; i < list.Count; i++)
            {
                var endFile = model.Locations.GetOutputFile(i);
                if (endFile.Exists) endFile.Delete();
                var e = list[i];
                var str = e.Select(z => Path.Combine(model.ChunkFolder.FullName, GetChunkFileName(z))).Aggregate((a, b) => a + "|" + b);
                Shell.FFMPEG(false, @"-i ""concat:" + str + @""" -c copy ""{0}""", endFile.FullName);
            }
        }
Beispiel #12
0
        public void DoWork(EditorModel model)
        {
            // model.Locations.PraatVoice.Delete();
            model.Locations.PraatOutput.Delete();

            if (!model.Locations.PraatVoice.Exists)
                Shell.FFMPEG(false, "-i \"{0}\" -vn -q:a 0 \"{1}\"", model.Locations.FaceVideo, model.Locations.PraatVoice);

                Shell.Exec(false, model.Locations.PraatExecutable,
                    String.Format(
                        CultureInfo.InvariantCulture,
                        "\"{0}\" \"{1}\" \"{2}\" {3} {4} {5} {6} {7} {8} {9}",
                        model.Locations.PraatScriptSource,
                        model.Locations.PraatVoice,
                        model.Locations.PraatOutput,
                        SilentLabel,
                        SoundLabel,
                        MinPitch,
                        TimeStep,
                        SilenceThreshold,
                        MinSilentInterval,
                        MinSoundInterval));

            model.Montage.SoundIntervals.Clear();
            using (var reader = new StreamReader(model.Locations.PraatOutput.FullName))
            {

                for (var i = 0; i < 11; i++)
                    reader.ReadLine();

                var intervalCount = int.Parse(reader.ReadLine());
                for (int i = 0; i < intervalCount; i++)
                {
                    var startTime = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);
                    var endTime = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);
                    var hasVoice = reader.ReadLine() == '"' + SoundLabel + '"';
                    model.Montage.SoundIntervals.Add(
                        new SoundInterval(
                            (int)Math.Round(startTime*1000),
                            (int)Math.Round(1000*endTime),
                            hasVoice));
                }
            }

            //  model.Locations.PraatVoice.Delete();
            model.Locations.PraatOutput.Delete();
        }
Beispiel #13
0
 public static IEnumerable<string> CreateSrtFile(EditorModel model)
 {
     var episodesLength=CumulativeEpisodesLengthes(model);
     var subtitles = ShiftFixes(model);
     for (int i=0;i<episodesLength.Count-1;i++)
     {
         var builder = new StringBuilder();
         var number = 1;
         foreach(var fix in subtitles.Where(z=>z.StartTime>=episodesLength[i] && z.StartTime<=episodesLength[i+1]))
             builder.AppendFormat("{0}\r\n{1} --> {2}\r\n{3}\r\n\r\n",
                     number++,
             MsInSrtFormat(fix.StartTime-episodesLength[i]),
             MsInSrtFormat(fix.StartTime-episodesLength[i]+fix.Length),
             fix.Text);
         yield return builder.ToString();
     }
 }
Beispiel #14
0
        public void DoWork(EditorModel model, bool print)
        {
            model.ChunkFolder.Delete(true);
            model.ChunkFolder.Create();
            Thread.Sleep(100); //без этого почему-то вылетают ошибки
            if (File.Exists(model.Locations.FaceVideo.FullName))
                Shell.FFMPEG(print, @"-i ""{0}"" -vf scale=1280:720 -r 25 -q:v 0 -acodec libmp3lame -ar 44100 -ab 32k ""{1}""",
                    model.Locations.FaceVideo.FullName, model.Locations.ConvertedFaceVideo.FullName);

            if (File.Exists(model.Locations.DesktopVideo.FullName))
                Shell.FFMPEG(print, @"-i ""{0}"" -vf scale=1280:720 -r 25 -q:v 0 -an ""{1}""",
                                model.Locations.DesktopVideo.FullName, model.Locations.ConvertedDesktopVideo.FullName);

            foreach (var e in Montager.ProcessingCommands.Processing(model, model.Montage.FileChunks))
            {
                e.Execute(print);
            }
        }
Beispiel #15
0
        public SubfolderViewModel(EditorModel model)
        {
            StartEditorCommand = new RelayCommand(StartEditor);
            ResetMontageCommand = new RelayCommand(ResetMontage);
            OpenFolderCommand = new RelayCommand(OpenFolder);
            FullPath = model.Locations.LocalFilePath.Directory.FullName;
            if (model.Montage.Chunks != null && model.Montage.Chunks.Count > 3)
                Marked = true;

            if (model.Montage.Information != null && model.Montage.Information.Episodes.Count>0)
            {
                TotalDuration = model.Montage.Information.Episodes.Sum(z => z.Duration.TotalMinutes);
                EpisodesNames = model.Montage.Information.Episodes
                    .Select(z=>z.Name)
                    .Aggregate((a, b) => a + "\r\n" + b);
            }
            if (model.Montage.Montaged)
                Montaged = true;
        }
Beispiel #16
0
        public static bool LoadAndConvert(EditorModel model)
        {
            var v4 = Load(model.VideoFolder.FullName);

            if (FilesWereNotFound)
                return false;

            //var model = new EditorModel(v4.VideoFolder, v4.RootFolder, v4.ProgramFolder);

            int index=0;
            foreach (var e in v4.Montage.Chunks)
            {
                var mode = e.Mode;
                if (mode == Mode.Undefined) mode = Mode.Drop;
                model.Montage.Chunks.Mark(e.EndTime, EditorModel.ModeToBools(mode), false);
                if (e.StartsNewEpisode)
                    model.Montage.Chunks.NewEpisode(index);
                index++;
            }

            foreach (var e in v4.Montage.Intervals)
            {
                model.Montage.SoundIntervals.Add(new SoundInterval
                {
                    StartTime = e.StartTime,
                    EndTime = e.EndTime,
                    HasVoice = e.HasVoice
                });
            }
            foreach (var e in v4.Montage.Information.Episodes)
            {
                model.Montage.Information.Episodes.Add(new Tuto.Model.EpisodInfo(Guid.NewGuid())
                {
                    Name = e.Name,
                    Duration = e.Duration
                });
            }
            return true;
        }
Beispiel #17
0
 public static IEnumerable<FFMPEGCommand> Commands(EditorModel model, FileChunk chunk)
 {
     switch (chunk.Mode)
     {
         case Mode.Face:
             yield return new ExtractFaceVideoCommand
             {
                 VideoInput = /*chunk.SourceFilename,*/ model.Locations.ConvertedFaceVideo,
                 StartTime = chunk.StartTime,
                 Duration = chunk.Length,
                 VideoOutput = model.Locations.Make(model.ChunkFolder, chunk.ChunkFilename)
             };
             break;
         case Mode.Screen:
             yield return new ExtractAudioCommand
             {
                 AudioInput = /*chunk.SourceFilename,*/ model.Locations.ConvertedFaceVideo,
                 StartTime = chunk.StartTime,
                 Duration = chunk.Length,
                 AudioOutput = model.Locations.Make(model.ChunkFolder, chunk.AudioFilename)
             };
             yield return new ExtractScreenVideoCommand
             {
                 VideoInput = /*chunk.SourceFilename,*/ model.Locations.ConvertedDesktopVideo,
                 StartTime = chunk.StartTime - model.Montage.SynchronizationShift,
                 Duration = chunk.Length,
                 VideoOutput = model.Locations.Make(model.ChunkFolder, chunk.VideoFilename)
             };
             yield return new MixVideoAudioCommand
             {
                 VideoInput = model.Locations.Make(model.ChunkFolder, chunk.VideoFilename),
                 AudioInput = model.Locations.Make(model.ChunkFolder, chunk.AudioFilename),
                 VideoOutput = model.Locations.Make(model.ChunkFolder, chunk.ChunkFilename)
             };
             break;
     }
 }
        public static bool ProcessCommonKeys(EditorModel model, KeyboardCommandData key)
        {
            if (NavigationKeysProcessing(model, key)) return true;

            var delta = 1000;
            if (key.Shift) delta = 200;
            if (key.Ctrl) delta = 50;

            switch (key.Command)
            {
               
                case KeyboardCommands.Face:
                    model.MarkHere(Mode.Face, key.Ctrl);
                    return true;

                case KeyboardCommands.Desktop:
                    model.MarkHere(Mode.Screen, key.Ctrl);
                    return true;

                case KeyboardCommands.Drop:
                    model.MarkHere(Mode.Drop, key.Ctrl);
                    return true;

                case KeyboardCommands.Clear:
                    model.RemoveChunkHere();
                    return true;

              

                case KeyboardCommands.NewEpisodeHere:
                    model.NewEpisodeHere();
                    return true;

            }
            return false;
        }
        public static bool NavigationKeysProcessing(EditorModel model, KeyboardCommandData key)
            
        {
            var delta = 1000;
            if (key.Shift) delta = 200;
            if (key.Ctrl) delta = 50;


            switch (key.Command)
            {
                case KeyboardCommands.Left:
                    model.WindowState.CurrentPosition = ((int)(model.WindowState.CurrentPosition - delta));
                    return true;

                case KeyboardCommands.Right:
                    model.WindowState.CurrentPosition = ((int)(model.WindowState.CurrentPosition + delta));
                    return true;

                case KeyboardCommands.PauseResume:
                    model.WindowState.Paused = !model.WindowState.Paused;
                    return true;
            }
            return false;
        }
Beispiel #20
0
 static bool TryReadObsolete(EditorModel model)
 {
     return false;
 }
Beispiel #21
0
 static void InitializeEmptyModel(EditorModel model)
 {
     model.Montage = new MontageModel(60 * 60 * 1000); //this is very bad. Need to analyze the video file
     model.WindowState = new WindowState();
 }
Beispiel #22
0
 public Statuses(EditorModel model)
 {
     this.model = model;
 }
Beispiel #23
0
 void RecodeFilesMock(EditorModel model)
 {
     foreach (var file in model.ChunkFolder.GetFiles("end_chunk*.*"))
         file.Delete();
     foreach (var e in model.Montage.FileChunks)
         File.Copy(
             Path.Combine(model.ChunkFolder.FullName, e.ChunkFilename),
             Path.Combine(model.ChunkFolder.FullName, e.EndChunkFileName));
 }
Beispiel #24
0
        private AvsNode MakeEpisode(EditorModel model, EpisodesChunks episode)
        {
            var fileChunks = episode.chunks;
            var avsChunks = new AvsConcatList { Items = new List<AvsNode>() };
            var fps = 25;

            avsChunks.Items.Add(AvsNode.NormalizedNode(model.Locations.Make(model.ChunkFolder, fileChunks[0].ChunkFilename), fps, fileChunks[0].Mode == Mode.Face));
            //making cross-fades
            for (int i = 1; i < fileChunks.Count; i++)
            {
                var currentChunk = fileChunks[i];
                var prevChunk = fileChunks[i - 1];
                AvsNode currentAvsChunk = AvsNode.NormalizedNode(model.Locations.Make(model.ChunkFolder, currentChunk.ChunkFilename), fps, currentChunk.Mode == Mode.Face);
                AvsNode prevAvsChunk = avsChunks.Items[avsChunks.Items.Count - 1];
                if (prevChunk.Mode == Mode.Face && currentChunk.Mode == Mode.Face)
                    avsChunks.Items[avsChunks.Items.Count - 1] = new AvsCrossFade
                    {
                        FadeFrom = prevAvsChunk,
                        FadeTo = currentAvsChunk
                    };
                else
                    avsChunks.Items.Add(currentAvsChunk);
            }

            // intro with fadein and fadeout
            //var intro = new AvsIntro
            //{
            //    VideoReference = model.Locations.Make(model.ChunkFolder, fileChunks[0].ChunkFilename),
            //    ImageFile = model.Locations.IntroImage
            //};
            //var normalizedIntro = AvsNode.NormalizedNode(intro);
            //var fadedIntro = new AvsFadeIn {Payload = new AvsFadeOut {Payload = normalizedIntro}};
            //avsChunks.Items.Insert(0, fadedIntro);

            // fadeout last item
            avsChunks.Items[avsChunks.Items.Count - 1] = new AvsFadeOut { Payload = avsChunks.Items[avsChunks.Items.Count - 1] };

            AvsNode resultedAvs = avsChunks;
            if (!string.IsNullOrEmpty(File.ReadAllText(model.Locations.GetSrtFile(episode.episodeNumber).FullName)))
            {
                resultedAvs = new AvsSubtitle { SrtPath = model.Locations.GetSrtFile(episode.episodeNumber).FullName, Payload = avsChunks };
            }

            // autolevel
            // ???

            return resultedAvs;;

            // watermark
            //return new AvsWatermark
            //{
            //    Payload = avsChunks,
            //    ImageFile = model.Locations.WatermarkImage
            //};

            /*
             * add intro
             * make crossfades
             * add fadein/fadeout
             * add autolevel?
             * add watermark
             */
        }
Beispiel #25
0
 public BorderMode(EditorModel editorModel)
 {
     this.model = editorModel;
     GenerateBorders();
 }
Beispiel #26
0
 void AssemblyWithExternalFile(EditorModel model)
 {
     var list = SeparateByEpisode(model);
     var tempFileName = Path.Combine(model.ChunkFolder.FullName, "temp.txt");
     for (int i = 0; i < list.Count; i++)
     {
         var e = list[i];
         var endFile = model.Locations.GetOutputFile(i);
         if (endFile.Exists) endFile.Delete();
         var str = e.Select(z => "file '" + Path.Combine(model.ChunkFolder.FullName, GetChunkFileName(z)) + "'\r\n").Aggregate((a, b) => a + b);
         File.WriteAllText(tempFileName, str);
         Shell.FFMPEG(false, @"-f concat -i ""{0}"" -q:v 0 -q:a 0 ""{1}""",
             tempFileName, endFile.FullName);
     }
 }
Beispiel #27
0
        void MainWindow_Initialized(object sender, EventArgs e)
        {
            model = (EditorModel)DataContext;
            model.WindowState.PropertyChanged += WindowState_PropertyChanged;

            FaceVideo.Source = new Uri(model.Locations.FaceVideo.FullName);
            ScreenVideo.Source = new Uri(model.Locations.DesktopVideo.FullName);
            FaceVideo.LoadedBehavior = MediaState.Manual;
            ScreenVideo.LoadedBehavior = MediaState.Manual;
            ScreenVideo.Volume = 0;

            ModeChanged();
            PositionChanged();
            PausedChanged();
            RatioChanged();
            videoAvailable = model.Locations.FaceVideo.Exists;

            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(timerInterval);
            timer.Tick += (s, a) => { CheckPlayTime(); };
            timer.Start();

            PreviewKeyDown += MainWindow_KeyDown;
            ModelView.MouseDown += Timeline_MouseDown;
            Slider.MouseDown += Timeline_MouseDown;

            Save.Click += (s, a) =>
            {
                model.Save();
            };

            Montage.Click += (s, a) =>
                {
                    model.Save();
                    RunProcess(Services.Montager,model.VideoFolder);
                };

            Assembly.Click += (s, a) =>
                {
                    model.Save();
                    RunProcess(Services.Assembler, model.VideoFolder);
                };

            RepairFace.Click += (s, a) =>
                {
                    model.Save();
                    IsEnabled = false;
                    new Tuto.TutoServices.RepairService().DoWork(model.Locations.FaceVideo,true);
                    IsEnabled = true;
                };

            RepairDesktop.Click += (s, a) =>
            {
                model.Save();
                IsEnabled = false;
                new Tuto.TutoServices.RepairService().DoWork(model.Locations.DesktopVideo,false);
                IsEnabled = true;
            };

            Help.Click += (s, a) =>
                {
                    var data = HelpCreator.CreateModeHelp();
                    var wnd = new HelpWindow();
                    wnd.DataContext = data;
                    wnd.Show();
                };

            GoTo.Click += (s, a) =>
                {
                    var wnd = new FixWindow();
                    wnd.Title = "Enter time";
                    var result = wnd.ShowDialog();
                    if (!result.HasValue || !result.Value) return;
                    var parts = wnd.Text.Text.Split(',', '.', '-', ' ');
                    int time = 0;
                    try
                    {
                        time = int.Parse(parts[0]) * 60 + int.Parse(parts[1]);
                    }
                    catch
                    {
                        MessageBox.Show("Incorrect string. Expected format is '5-14'");
                        return;
                    }
                    time *= 1000;
                    int current = 0;
                    foreach (var z in model.Montage.Chunks)
                    {
                        if (z.IsNotActive) time += z.Length;
                        current += z.Length;
                        if (current > time) break;
                    }
                    model.WindowState.CurrentPosition = time;
                };

            Synchronize.Click += Synchronize_Click;

            Infos.Click += Infos_Click;
        }
Beispiel #28
0
 internal Locations(EditorModel model)
 {
     this.model = model;
 }
Beispiel #29
0
 public static IEnumerable<FFMPEGCommand> Processing(EditorModel model, List<FileChunk> chunks)
 {
     return chunks.SelectMany(z => Commands(model, z));
 }
Beispiel #30
0
 public GeneralMode(EditorModel edModel)
 {
     this.model = edModel;
     model.WindowState.FaceVideoIsVisible = model.WindowState.DesktopVideoIsVisible = true;
 }
Beispiel #31
0
 List<List<FileChunk>> SeparateByEpisode(EditorModel model)
 {
     List<List<FileChunk>> list = new List<List<FileChunk>>();
     var temp = new List<FileChunk>();
     foreach (var e in model.Montage.FileChunks)
     {
         if (e.StartsNewEpisode) { list.Add(temp); temp = new List<FileChunk>(); }
         temp.Add(e);
     }
     list.Add(temp);
     return list;
 }
Beispiel #32
0
 void RecodeFles(EditorModel model)
 {
     foreach (var file in model.ChunkFolder.GetFiles("end_chunk*.*"))
         file.Delete();
     foreach (var e in model.Montage.FileChunks)
         Shell.FFMPEG(false,
             @"-i ""{0}"" -vf scale=1280:720 -r 30 -q:v 0 -acodec libmp3lame -ar 44100 -ab 32k -copyts ""{1}""",
             Path.Combine(model.ChunkFolder.FullName, e.ChunkFilename),
             Path.Combine(model.ChunkFolder.FullName, e.EndChunkFileName));
 }