示例#1
0
        public StartWindow()
        {
            InitializeComponent();

            Title += $" {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion}";

            try
            {
                VideoProcessor.SetFFMpegPath();
            }
            catch
            {
                string message = "Failed to initialize FFMpeg. Make sure ffmpeg.exe and ffprobe.exe are located in the ffmpeg folder of this application.";
                MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown();
            }

            PreviousVideo[] previousVideosArray = JsonConvert.DeserializeObject <PreviousVideo[]>(Settings.Default.PreviousVideos);
            previousVideos = new(previousVideosArray);

            if (previousVideos.Count > 0)
            {
                lbxPreviousVideos.ItemsSource = previousVideos;
            }
            else
            {
                lbxPreviousVideos.Visibility   = Visibility.Hidden;
                lblNoPreviousVideos.Visibility = Visibility.Visible;
            }

            workingDirectory = Settings.Default.WorkingDirectory;
            if (workingDirectory.Length == 0)
            {
                workingDirectory = null;
            }
        }
示例#2
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            // Check if _frames directory exists, otherwise create it
            if (Directory.Exists(targetDirectory))
            {
                Directory.Delete(targetDirectory, true);
            }

            Directory.CreateDirectory(targetDirectory);

            // Get user conversion settings
            TimeSpan startTime      = GetStartTime();
            TimeSpan endTime        = GetEndTime();
            int      width          = int.Parse(txtFrameWidth.Text);
            int      height         = int.Parse(txtFrameHeight.Text);
            double   fps            = double.Parse(txtFramesPerSecond.Text);
            int      expectedFrames = (int)(fps * (endTime - startTime).TotalSeconds);

            ConversionInfo info = new(Path.GetFileName(filePath), fps, expectedFrames);

            // Save user conversion string into a file in json format
            string jsonString = JsonSerializer.Serialize(info);

            File.WriteAllText(Path.Join(targetDirectory, "conversion-info.json"), jsonString);

            // Show a progress window and hide this window
            ProgressWindow progress = new("Converting video to images", startWindow);

            progress.Show();
            Visibility = Visibility.Hidden;

            void onProgress(double percentage) => progress.percentage = percentage;

            Thread thread = new(async() =>
            {
                try
                {
                    await VideoProcessor.ConvertToImageSequence(filePath, targetDirectory, startTime, endTime, width,
                                                                height, fps, progress.cts, onProgress);
                }
                catch (OperationCanceledException)
                {
                    Dispatcher.Invoke(() =>
                    {
                        progress.Close();
                        Visibility = Visibility.Visible;
                    });
                }
                finally
                {
                    Dispatcher.Invoke(() =>
                    {
                        progress.cts.Dispose();
                        progress.Close();
                        Close();
                        onFinished();
                    });
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }