Esempio n. 1
0
        public VideoFile(VideoFile video)
        {
            if (video == null)
            {
                throw new ArgumentNullException(nameof(video));
            }

            filePath = video.filePath;
            duration = video.Duration;
            keyFrames = video.keyFrames;
            start = video.start;
            end = video.end;
            groupIndex = video.groupIndex;
        }
Esempio n. 2
0
        private async Task AddFiles(string[] files, VideoFile before = null, int groupIndex = -1)
        {
            var infobox = InfoBox.Show(this, "Retrieving video files details...");

            try
            {
                await Data.AddFiles(files, before, groupIndex);
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(ex.Message, "File format error");
            }

            infobox.Close();
        }
Esempio n. 3
0
        public async Task AddFiles(string[] files, VideoFile before, int groupIndex)
        {
            var error = new List<string>();
            var lastFile = CurrentJob.Files.LastOrDefault();
            var beforeIndex = before != null ? CurrentJob.Files.IndexOf(before) : -1;
            if (groupIndex < 0)
            {
                groupIndex = lastFile?.GroupIndex ?? 0;
            }

            foreach (var filepath in files)
            {
                try
                {
                    var file = await CreateVideoFileObject(filepath);
                    file.GroupIndex = groupIndex;
                    if (before == null)
                    {
                        CurrentJob.Files.Add(file);
                    }
                    else
                    {
                        CurrentJob.Files.Insert(beforeIndex++, file);
                    }
                }
                catch (Exception)
                {
                    error.Add(Path.GetFileName(filepath));
                }
            }

            if (error.Any())
            {
                if (files.Length == error.Count)
                {
                    throw new InvalidOperationException("None of files can be exported by ffmpeg:\r\n" + string.Join("\r\n", error.Select(s => "  " + s)));
                }

                throw new InvalidOperationException("Some files can not be exported by ffmpeg:\r\n" + string.Join("\r\n", error.Select(s => "  " + s)));
            }

            if (string.IsNullOrEmpty(CurrentJob.OutputName) && files.Length > 0)
            {
                CurrentJob.OutputName = Path.GetFileNameWithoutExtension(files[0]) + ".out" + Path.GetExtension(files[0]);
            }
        }
Esempio n. 4
0
        public void SplitCurrentVideo(double currentTime)
        {
            var currentIndex = CurrentJob.Files.IndexOf(CurrentFile);
            var splitTime = CurrentFile.KeyFrames?.Where(f => f > currentTime).DefaultIfEmpty(CurrentFile.Duration).First() ?? currentTime;
            if (splitTime <= CurrentFile.Start || splitTime >= CurrentFile.End)
            {
                return;
            }

            var newFile = new VideoFile(CurrentFile)
            {
                Start = splitTime,
                GroupIndex = CurrentFile.GroupIndex
            };

            CurrentFile.End = splitTime;
            CurrentJob.Files.Insert(currentIndex + 1, newFile);
        }
Esempio n. 5
0
        public void MoveFiles(VideoFile[] files, VideoFile before, int groupIndex)
        {
            if (files == null)
            {
                throw new ArgumentNullException(nameof(files));
            }

            var jobFiles = CurrentJob.Files;
            if (before != null)
            {
                int ind = jobFiles.IndexOf(before);
                while (before != null && files.Contains(before))
                {
                    ind++;
                    before = (ind < jobFiles.Count) ? jobFiles[ind] : null;
                }
            }

            foreach (var file in files)
            {
                jobFiles.Remove(file);
            }

            int insertIndex = (before != null) ? jobFiles.IndexOf(before) : jobFiles.Count;
            var lastFile = jobFiles.LastOrDefault();
            if (groupIndex < 0)
            {
                groupIndex = lastFile?.GroupIndex ?? 0;
            }

            foreach (var file in files)
            {
                jobFiles.Insert(insertIndex++, file);
                file.GroupIndex = groupIndex;
            }

            NormalizeGroups();
        }
Esempio n. 6
0
        private void OpenVideo(VideoFile video)
        {
            storyboard?.Stop(mainGrid);

            storyboard = new Storyboard();
            var timeline = new MediaTimeline(video.FileUri);
            storyboard.Children.Add(timeline);
            Storyboard.SetTarget(timeline, mediaElement);
            storyboard.CurrentTimeInvalidated += Storyboard_CurrentTimeInvalidated;

            Data.CurrentFile = video;
            storyboard.Begin(mainGrid, true);
        }
Esempio n. 7
0
 private void MoveFiles(VideoFile[] files, VideoFile before, int groupIndex)
 {
     Data.MoveFiles(files, before, groupIndex);
     RefreshList();
 }
Esempio n. 8
0
        private void GetBeforeAndGroup(Point point, out VideoFile before, out int groupIndex)
        {
            var result = GetItemAt(filesList, point);
            before = null;
            groupIndex = -1;
            if (result == null)
            {
                return;
            }

            var listItem = result as ListViewItem;
            if (listItem != null)
            {
                before = listItem.Content as VideoFile;
                groupIndex = before.GroupIndex;
                return;
            }

            var group = result as GroupItem;
            if (group == null)
            {
                return;
            }

            var items = (group.Content as CollectionViewGroup).Items;
            before = items.FirstOrDefault() as VideoFile;
            groupIndex = before.GroupIndex - 1;
            if (groupIndex < 0)
            {
                groupIndex = 0;
            }
        }