Пример #1
0
        private Process GetFfmpegProcess(string inputVideoFileName, string outputVideoFileName, string assaTempFileName, int?passNumber = null, string twoPassBitRate = null)
        {
            var pass = string.Empty;

            if (passNumber.HasValue)
            {
                pass = passNumber.Value.ToString(CultureInfo.InvariantCulture);
            }

            return(VideoPreviewGenerator.GenerateHardcodedVideoFile(
                       Path.GetFileName(inputVideoFileName),
                       assaTempFileName,
                       outputVideoFileName,
                       (int)numericUpDownWidth.Value,
                       (int)numericUpDownHeight.Value,
                       comboBoxVideoEncoding.Text,
                       comboBoxPreset.Text,
                       comboBoxCrf.Text,
                       comboBoxAudioEnc.Text,
                       checkBoxMakeStereo.Checked,
                       comboBoxAudioSampleRate.Text.Replace("Hz", string.Empty).Trim(),
                       comboBoxTune.Text,
                       comboBoxAudioBitRate.Text,
                       pass,
                       twoPassBitRate,
                       OutputHandler));
        }
Пример #2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            buttonOK.Enabled = false;
            var fileName = radioButtonColor.Checked ? "blank_video_solid" : "blank_video_checkered";

            using (var saveDialog = new SaveFileDialog {
                FileName = fileName, Filter = "Matroska|*.mkv"
            })
            {
                if (saveDialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                VideoFileName = saveDialog.FileName;
            }

            if (File.Exists(VideoFileName))
            {
                File.Delete(VideoFileName);
            }

            progressBar1.Style      = ProgressBarStyle.Marquee;
            progressBar1.Visible    = true;
            labelPleaseWait.Visible = true;
            var process = VideoPreviewGenerator.GenerateVideoFile(
                VideoFileName,
                (int)Math.Round(numericUpDownDurationMinutes.Value * 60),
                (int)numericUpDownWidth.Value,
                (int)numericUpDownHeight.Value,
                panelColor.BackColor,
                radioButtonCheckeredImage.Checked,
                decimal.Parse(comboBoxFrameRate.Text)
                );

            process.Start();
            while (!process.HasExited)
            {
                System.Threading.Thread.Sleep(100);
                Application.DoEvents();
                if (_abort)
                {
                    process.Kill();
                }
            }

            progressBar1.Visible    = false;
            labelPleaseWait.Visible = false;
            DialogResult            = _abort ? DialogResult.Cancel : DialogResult.OK;
        }
Пример #3
0
        private bool GeneratePreviewViaMpv()
        {
            var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();

            if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
            {
                return(false);
            }

            if (_mpv == null)
            {
                _mpv = new LibMpvDynamic();
                _mpv.Initialize(pictureBoxPreview, fileName, VideoLoaded, null);
            }
            else
            {
                VideoLoaded(null, null);
            }

            return(true);
        }
Пример #4
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            EnableDisableControls(false);
            var fileName = radioButtonColor.Checked ? "blank_video_solid" : (radioButtonCheckeredImage.Checked ? "blank_video_checkered" : "blank_video_image");

            using (var saveDialog = new SaveFileDialog {
                FileName = fileName, Filter = "MP4|*.mp4|Matroska|*.mkv|WebM|*.webm"
            })
            {
                if (saveDialog.ShowDialog(this) != DialogResult.OK)
                {
                    EnableDisableControls(true);
                    return;
                }

                VideoFileName = saveDialog.FileName;
            }

            if (File.Exists(VideoFileName))
            {
                File.Delete(VideoFileName);
            }

            progressBar1.Visible    = true;
            labelPleaseWait.Visible = true;
            var process = VideoPreviewGenerator.GenerateVideoFile(
                VideoFileName,
                (int)Math.Round(numericUpDownDurationMinutes.Value * 60),
                (int)numericUpDownWidth.Value,
                (int)numericUpDownHeight.Value,
                panelColor.BackColor,
                radioButtonCheckeredImage.Checked,
                decimal.Parse(comboBoxFrameRate.Text),
                radioButtonImage.Checked ? _backgroundImage : null,
                OutputHandler);

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            _totalFrames         = (long)Math.Round(float.Parse(comboBoxFrameRate.Text, CultureInfo.CurrentCulture) * (float)numericUpDownDurationMinutes.Value * 60.0f);
            progressBar1.Maximum = (int)_totalFrames;
            _startTicks          = DateTime.UtcNow.Ticks;
            timer1.Start();
            while (!process.HasExited)
            {
                var v = (int)_processedFrames;
                if (v >= progressBar1.Minimum && v <= progressBar1.Maximum)
                {
                    progressBar1.Value = v;
                }

                System.Threading.Thread.Sleep(100);
                Application.DoEvents();
                if (_abort)
                {
                    process.Kill();
                }
            }

            progressBar1.Visible    = false;
            labelPleaseWait.Visible = false;
            timer1.Stop();
            labelProgress.Text = string.Empty;
            DialogResult       = _abort ? DialogResult.Cancel : DialogResult.OK;
        }
Пример #5
0
        private void buttonPreview_Click(object sender, EventArgs e)
        {
            try
            {
                buttonPreview.Enabled          = false;
                labelPreviewPleaseWait.Visible = true;
                Cursor = Cursors.WaitCursor;

                // generate blank video
                var tempVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".mkv");
                var process           = VideoPreviewGenerator.GenerateVideoFile(
                    tempVideoFileName,
                    2,
                    (int)numericUpDownWidth.Value,
                    (int)numericUpDownHeight.Value,
                    Color.Black,
                    true,
                    25,
                    null);
                process.Start();
                while (!process.HasExited)
                {
                    System.Threading.Thread.Sleep(100);
                    Application.DoEvents();
                }

                // make temp assa file with font
                var assaTempFileName = GetAssaFileName(tempVideoFileName);
                var sub = new Subtitle();
                sub.Header = _assaSubtitle.Header;
                sub.Paragraphs.Add(new Paragraph(GetPreviewParagraph()));

                if (!_isAssa)
                {
                    SetStyleForNonAssa(sub);
                }
                FixRightToLeft(sub);
                FileUtil.WriteAllText(assaTempFileName, new AdvancedSubStationAlpha().ToText(sub, string.Empty), new TextEncoding(Encoding.UTF8, "UTF8"));

                // hardcode subtitle
                var outputVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".mp4");
                process = GetFfmpegProcess(tempVideoFileName, outputVideoFileName, assaTempFileName);
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                while (!process.HasExited)
                {
                    System.Threading.Thread.Sleep(100);
                    Application.DoEvents();
                }

                string bmpFileName;
                try
                {
                    bmpFileName = VideoPreviewGenerator.GetScreenShot(outputVideoFileName, "00:00:01");
                    using (var bmp = new Bitmap(bmpFileName))
                    {
                        using (var form = new ExportPngXmlPreview(bmp))
                        {
                            form.AllowNext                 = false;
                            form.AllowPrevious             = false;
                            labelPreviewPleaseWait.Visible = false;
                            form.ShowDialog(this);
                        }
                    }
                }
                catch
                {
                    if (comboBoxVideoEncoding.Text.EndsWith("_amf"))
                    {
                        MessageBox.Show("Unable to generate video with AMD hardware acceleration!");
                    }
                    else if (comboBoxVideoEncoding.Text.EndsWith("_nvenc"))
                    {
                        MessageBox.Show("Unable to generate video with Nvidia hardware acceleration!");
                    }
                    else
                    {
                        MessageBox.Show("Unable to generate video!");
                    }

                    Cursor = Cursors.Default;
                    buttonPreview.Enabled          = true;
                    labelPreviewPleaseWait.Visible = false;
                    return;
                }


                try
                {
                    File.Delete(tempVideoFileName);
                    File.Delete(assaTempFileName);
                    File.Delete(outputVideoFileName);
                    File.Delete(bmpFileName);
                }
                catch
                {
                    // ignore
                }
            }
            finally
            {
                Cursor = Cursors.Default;
                buttonPreview.Enabled          = true;
                labelPreviewPleaseWait.Visible = false;
            }
        }
        private void buttonPreview_Click(object sender, EventArgs e)
        {
            try
            {
                buttonPreview.Enabled          = false;
                labelPreviewPleaseWait.Visible = true;
                Cursor = Cursors.WaitCursor;

                // generate blank video
                var tempVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".mkv");
                var process           = VideoPreviewGenerator.GenerateVideoFile(
                    tempVideoFileName,
                    2,
                    (int)numericUpDownWidth.Value,
                    (int)numericUpDownHeight.Value,
                    Color.Black,
                    true,
                    25);
                process.Start();
                while (!process.HasExited)
                {
                    System.Threading.Thread.Sleep(100);
                    Application.DoEvents();
                }

                // make temp assa file with font
                var assaTempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".ass");
                var sub = new Subtitle();
                sub.Header = _assaSubtitle.Header;
                sub.Paragraphs.Add(new Paragraph(GetPreviewText(), 0, 10_000));

                if (numericUpDownFontSize.Visible) // not ASSA format
                {
                    SetStyleForNonAssa(sub);
                }
                FixRightToLeft(sub);
                File.WriteAllText(assaTempFileName, new AdvancedSubStationAlpha().ToText(sub, string.Empty));

                // hardcode subtitle
                var outputVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".mp4");
                process = GetFfmpegProcess(tempVideoFileName, outputVideoFileName, assaTempFileName);
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                while (!process.HasExited)
                {
                    System.Threading.Thread.Sleep(100);
                    Application.DoEvents();
                }

                Cursor = Cursors.Default;
                var bmpFileName = VideoPreviewGenerator.GetScreenShot(outputVideoFileName, "00:00:01");
                using (var bmp = new Bitmap(bmpFileName))
                {
                    using (var form = new ExportPngXmlPreview(bmp))
                    {
                        form.AllowNext                 = false;
                        form.AllowPrevious             = false;
                        labelPreviewPleaseWait.Visible = false;
                        form.ShowDialog(this);
                    }
                }

                try
                {
                    File.Delete(tempVideoFileName);
                    File.Delete(assaTempFileName);
                    File.Delete(outputVideoFileName);
                    File.Delete(bmpFileName);
                }
                catch
                {
                    // ignore
                }
            }
            finally
            {
                Cursor = Cursors.Default;
                buttonPreview.Enabled          = true;
                labelPreviewPleaseWait.Visible = false;
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            buttonOK.Enabled = false;
            using (var saveDialog = new SaveFileDialog {
                FileName = string.Empty, Filter = "MP4|*.mp4|Matroska|*.mkv|WebM|*.webm"
            })
            {
                if (saveDialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                VideoFileName = saveDialog.FileName;
            }

            if (File.Exists(VideoFileName))
            {
                File.Delete(VideoFileName);
            }

            if (numericUpDownFontSize.Visible)
            {
                var fontSize = (int)numericUpDownFontSize.Value;
                var style    = AdvancedSubStationAlpha.GetSsaStyle("Default", _assaSubtitle.Header);
                style.FontSize = fontSize;
                var styleLine = style.ToRawAss();
                _assaSubtitle.Header = AdvancedSubStationAlpha.AddTagToHeader("Style", styleLine, "[V4+ Styles]", _assaSubtitle.Header);
            }

            if (Configuration.Settings.General.RightToLeftMode && LanguageAutoDetect.CouldBeRightToLeftLanguage(_assaSubtitle))
            {
                for (var index = 0; index < _assaSubtitle.Paragraphs.Count; index++)
                {
                    var paragraph = _assaSubtitle.Paragraphs[index];
                    if (LanguageAutoDetect.ContainsRightToLeftLetter(paragraph.Text))
                    {
                        paragraph.Text = Utilities.FixRtlViaUnicodeChars(paragraph.Text);
                    }
                }
            }

            SubtitleFormat format           = new AdvancedSubStationAlpha();
            var            assaTempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".ass");

            File.WriteAllText(assaTempFileName, format.ToText(_assaSubtitle, null));

            progressBar1.Style      = ProgressBarStyle.Marquee;
            progressBar1.Visible    = true;
            labelPleaseWait.Visible = true;
            var process = VideoPreviewGenerator.GenerateHardcodedVideoFile(
                _inputVideoFileName,
                assaTempFileName,
                VideoFileName);

            process.Start();
            while (!process.HasExited)
            {
                System.Threading.Thread.Sleep(100);
                Application.DoEvents();
                if (_abort)
                {
                    process.Kill();
                }
            }

            progressBar1.Visible    = false;
            labelPleaseWait.Visible = false;

            try
            {
                File.Delete(assaTempFileName);
            }
            catch
            {
                // ignore
            }

            DialogResult = _abort ? DialogResult.Cancel : DialogResult.OK;
        }