ShareX/ScreenCaptureLib/Screencast/FFmpegOptionsForm.cs

176 lines
6.1 KiB
C#
Raw Normal View History

2014-05-10 12:23:47 +12:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (C) 2008-2014 ShareX Developers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using HelpersLib;
2014-05-12 09:40:49 +12:00
using ScreenCaptureLib;
2014-05-10 12:23:47 +12:00
using SevenZip;
2014-05-09 15:14:53 +12:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
2014-05-09 15:14:53 +12:00
using System.Linq;
using System.Text;
2014-05-10 12:23:47 +12:00
using System.Text.RegularExpressions;
2014-05-09 15:14:53 +12:00
using System.Windows.Forms;
namespace ScreenCaptureLib
2014-05-09 15:14:53 +12:00
{
2014-05-10 20:06:43 +12:00
public partial class FFmpegOptionsForm : Form
2014-05-09 15:14:53 +12:00
{
public ScreencastOptions Options = new ScreencastOptions();
public string DefaultToolsPath;
2014-05-09 15:14:53 +12:00
2014-05-10 20:06:43 +12:00
public FFmpegOptionsForm(FFmpegOptions ffMpegOptions)
2014-05-09 15:14:53 +12:00
{
Options.FFmpeg = ffMpegOptions;
2014-05-09 15:14:53 +12:00
InitializeComponent();
2014-05-10 20:06:43 +12:00
this.Text = string.Format("{0} - FFmpeg Options", Application.ProductName);
2014-05-09 15:14:53 +12:00
this.Icon = ShareXResources.Icon;
}
2014-05-09 15:14:53 +12:00
2014-05-10 20:06:43 +12:00
public FFmpegOptionsForm(ScreencastOptions options)
: this(options.FFmpeg)
{
Options = options;
if (options != null)
{
2014-05-12 13:13:42 +12:00
SettingsLoad();
UpdateUI();
}
2014-05-09 15:14:53 +12:00
}
2014-05-12 13:13:42 +12:00
private void SettingsLoad()
2014-05-09 15:14:53 +12:00
{
2014-05-12 13:13:42 +12:00
// General
2014-05-12 11:19:38 +12:00
cbCodec.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegVideoCodec>());
cbCodec.SelectedIndex = (int)Options.FFmpeg.VideoCodec;
cbCodec.SelectedIndexChanged += (sender, e) => UpdateUI();
2014-05-09 15:14:53 +12:00
2014-05-12 11:19:38 +12:00
cbExtension.Text = Options.FFmpeg.Extension;
cbExtension.SelectedIndexChanged += (sender, e) => UpdateUI();
2014-05-09 15:14:53 +12:00
2014-05-12 11:19:38 +12:00
tbUserArgs.Text = Options.FFmpeg.UserArgs;
tbUserArgs.TextChanged += (sender, e) => UpdateUI();
2014-05-09 20:12:44 +12:00
2014-05-10 12:23:47 +12:00
string cli = "ffmpeg.exe";
if (string.IsNullOrEmpty(Options.FFmpeg.CLIPath) && File.Exists(cli))
2014-05-10 12:23:47 +12:00
{
Options.FFmpeg.CLIPath = cli;
2014-05-10 12:23:47 +12:00
}
2014-05-12 11:19:38 +12:00
tbFFmpegPath.Text = Options.FFmpeg.CLIPath;
tbFFmpegPath.TextChanged += (sender, e) => UpdateUI();
2014-05-12 13:13:42 +12:00
// x264
nudx264CRF.Value = Options.FFmpeg.x264CRF.Between((int)nudx264CRF.Minimum, (int)nudx264CRF.Maximum);
nudx264CRF.ValueChanged += (sender, e) => UpdateUI();
cbPreset.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegPreset>());
cbPreset.SelectedIndex = (int)Options.FFmpeg.Preset;
cbPreset.SelectedIndexChanged += (sender, e) => UpdateUI();
// VPx
nudVPxCRF.Value = Options.FFmpeg.VPxCRF.Between((int)nudVPxCRF.Minimum, (int)nudVPxCRF.Maximum);
nudVPxCRF.ValueChanged += (sender, e) => UpdateUI();
// XviD
nudQscale.Value = Options.FFmpeg.qscale.Between((int)nudQscale.Minimum, (int)nudQscale.Maximum);
nudQscale.ValueChanged += (sender, e) => UpdateUI();
2014-05-09 15:14:53 +12:00
}
2014-05-12 13:13:42 +12:00
public void SettingsSave()
2014-05-09 15:14:53 +12:00
{
2014-05-12 13:13:42 +12:00
// General
2014-05-12 11:19:38 +12:00
Options.FFmpeg.VideoCodec = (FFmpegVideoCodec)cbCodec.SelectedIndex;
Options.FFmpeg.Extension = cbExtension.Text;
2014-05-09 15:14:53 +12:00
2014-05-12 13:13:42 +12:00
Options.FFmpeg.UserArgs = tbUserArgs.Text;
Options.FFmpeg.CLIPath = tbFFmpegPath.Text;
2014-05-12 13:13:42 +12:00
// x264
Options.FFmpeg.x264CRF = (int)nudx264CRF.Value;
Options.FFmpeg.Preset = (FFmpegPreset)cbPreset.SelectedIndex;
2014-05-09 15:14:53 +12:00
2014-05-12 13:13:42 +12:00
// VPx
Options.FFmpeg.VPxCRF = (int)nudVPxCRF.Value;
2014-05-09 15:14:53 +12:00
2014-05-12 13:13:42 +12:00
// XviD
Options.FFmpeg.qscale = (int)nudQscale.Value;
2014-05-09 15:14:53 +12:00
}
public void UpdateUI()
2014-05-09 15:14:53 +12:00
{
2014-05-12 13:13:42 +12:00
SettingsSave();
2014-05-12 11:19:38 +12:00
if ((Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libx264 || Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libxvid) && cbExtension.Text == "webm")
{
cbExtension.Text = "mp4";
}
else if (Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libvpx && cbExtension.Text != "webm")
{
cbExtension.Text = "webm";
}
2014-05-12 11:19:38 +12:00
tbCommandLinePreview.Text = Options.GetFFmpegArgs();
2014-05-09 15:14:53 +12:00
}
2014-05-09 18:41:16 +12:00
2014-05-09 20:12:44 +12:00
private void buttonFFmpegBrowse_Click(object sender, EventArgs e)
{
2014-05-12 11:19:38 +12:00
Helpers.BrowseFile("Browse for ffmpeg.exe", tbFFmpegPath, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
UpdateUI();
}
private void buttonFFmpegHelp_Click(object sender, EventArgs e)
{
Helpers.OpenURL("https://www.ffmpeg.org/ffmpeg.html");
2014-05-09 20:12:44 +12:00
}
2014-05-10 12:23:47 +12:00
private void btnDownload_Click(object sender, EventArgs e)
{
FFmpegHelper.DownloadFFmpeg(true, DownloaderForm_InstallRequested);
}
private void DownloaderForm_InstallRequested(string filePath)
2014-05-10 12:23:47 +12:00
{
2014-05-12 11:19:38 +12:00
string extractPath = DefaultToolsPath ?? "ffmpeg.exe";
bool result = FFmpegHelper.ExtractFFmpeg(filePath, extractPath);
2014-05-10 12:23:47 +12:00
if (result)
{
2014-05-12 11:19:38 +12:00
this.InvokeSafe(() => tbFFmpegPath.Text = extractPath);
MessageBox.Show("FFmpeg successfully downloaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
2014-05-10 12:23:47 +12:00
}
else
{
MessageBox.Show("Download of FFmpeg failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
2014-05-10 12:23:47 +12:00
}
}
2014-05-09 15:14:53 +12:00
}
}