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;
|
|
|
|
|
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;
|
2014-05-09 22:25:04 +12:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
public partial class FFmpegCLIOptionsForm : Form
|
|
|
|
|
{
|
2014-05-10 20:04:18 +12:00
|
|
|
|
private ScreencastOptions Options = new ScreencastOptions();
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-10 20:04:18 +12:00
|
|
|
|
public FFmpegCLIOptionsForm(FFmpegOptions ffMpegOptions)
|
2014-05-09 15:14:53 +12:00
|
|
|
|
{
|
2014-05-10 20:04:18 +12:00
|
|
|
|
Options.FFmpeg = ffMpegOptions;
|
|
|
|
|
|
2014-05-09 15:14:53 +12:00
|
|
|
|
InitializeComponent();
|
2014-05-10 13:52:09 +12:00
|
|
|
|
|
2014-05-09 15:14:53 +12:00
|
|
|
|
this.Text = string.Format("{0} - FFmpeg CLI Options", Application.ProductName);
|
|
|
|
|
this.Icon = ShareXResources.Icon;
|
2014-05-10 13:52:09 +12:00
|
|
|
|
}
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-10 13:52:09 +12:00
|
|
|
|
public FFmpegCLIOptionsForm(ScreencastOptions options)
|
2014-05-10 20:04:18 +12:00
|
|
|
|
: this(options.FFmpeg)
|
2014-05-10 13:52:09 +12:00
|
|
|
|
{
|
|
|
|
|
Options = options;
|
|
|
|
|
|
|
|
|
|
if (options != null)
|
|
|
|
|
{
|
|
|
|
|
LoadSettings();
|
|
|
|
|
UpdateUI();
|
|
|
|
|
}
|
2014-05-09 15:14:53 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadSettings()
|
|
|
|
|
{
|
|
|
|
|
comboBoxCodec.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegVideoCodec>());
|
2014-05-09 23:45:10 +12:00
|
|
|
|
comboBoxCodec.SelectedIndex = (int)Options.FFmpeg.VideoCodec;
|
|
|
|
|
comboBoxCodec.SelectedIndexChanged += (sender, e) => UpdateUI();
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
comboBoxExtension.Text = Options.FFmpeg.Extension;
|
|
|
|
|
comboBoxExtension.SelectedIndexChanged += (sender, e) => UpdateUI();
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
nudCRF.Value = Options.FFmpeg.CRF.Between((int)nudCRF.Minimum, (int)nudCRF.Maximum);
|
|
|
|
|
nudCRF.ValueChanged += (sender, e) => UpdateUI();
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
|
|
|
|
comboBoxPreset.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegPreset>());
|
2014-05-09 23:45:10 +12:00
|
|
|
|
comboBoxPreset.SelectedIndex = (int)Options.FFmpeg.Preset;
|
|
|
|
|
comboBoxPreset.SelectedIndexChanged += (sender, e) => UpdateUI();
|
2014-05-09 18:41:16 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
nudQscale.Value = Options.FFmpeg.qscale.Between((int)nudQscale.Minimum, (int)nudQscale.Maximum);
|
|
|
|
|
nudQscale.ValueChanged += (sender, e) => UpdateUI();
|
|
|
|
|
|
|
|
|
|
textBoxUserArgs.Text = Options.FFmpeg.UserArgs;
|
|
|
|
|
textBoxUserArgs.TextChanged += (sender, e) => UpdateUI();
|
2014-05-09 20:12:44 +12:00
|
|
|
|
|
2014-05-10 12:23:47 +12:00
|
|
|
|
string cli = "ffmpeg.exe";
|
2014-05-09 23:45:10 +12:00
|
|
|
|
if (string.IsNullOrEmpty(Options.FFmpeg.CLIPath) && File.Exists(cli))
|
2014-05-10 12:23:47 +12:00
|
|
|
|
{
|
2014-05-09 23:45:10 +12:00
|
|
|
|
Options.FFmpeg.CLIPath = cli;
|
2014-05-10 12:23:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
textBoxFFmpegPath.Text = Options.FFmpeg.CLIPath;
|
|
|
|
|
textBoxFFmpegPath.TextChanged += (sender, e) => UpdateUI();
|
2014-05-09 15:14:53 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
public void SaveSettings()
|
2014-05-09 15:14:53 +12:00
|
|
|
|
{
|
2014-05-09 23:45:10 +12:00
|
|
|
|
Options.FFmpeg.VideoCodec = (FFmpegVideoCodec)comboBoxCodec.SelectedIndex;
|
|
|
|
|
Options.FFmpeg.Extension = comboBoxExtension.Text;
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
Options.FFmpeg.CRF = (int)nudCRF.Value;
|
|
|
|
|
Options.FFmpeg.Preset = (FFmpegPreset)comboBoxPreset.SelectedIndex;
|
2014-05-09 20:46:15 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
Options.FFmpeg.qscale = (int)nudQscale.Value;
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
Options.FFmpeg.UserArgs = textBoxUserArgs.Text;
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
Options.FFmpeg.CLIPath = textBoxFFmpegPath.Text;
|
2014-05-09 15:14:53 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
public void UpdateUI()
|
2014-05-09 15:14:53 +12:00
|
|
|
|
{
|
2014-05-09 20:46:15 +12:00
|
|
|
|
SaveSettings();
|
2014-05-09 15:14:53 +12:00
|
|
|
|
|
2014-05-09 23:45:10 +12:00
|
|
|
|
groupBoxH263.Enabled = Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libxvid;
|
|
|
|
|
groupBoxH264.Enabled = Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libx264 || Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libvpx;
|
|
|
|
|
|
|
|
|
|
if ((Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libx264 || Options.FFmpeg.VideoCodec == FFmpegVideoCodec.libxvid) && comboBoxExtension.Text == "webm")
|
|
|
|
|
comboBoxExtension.Text = "mp4";
|
|
|
|
|
else if ((FFmpegVideoCodec)comboBoxCodec.SelectedIndex == FFmpegVideoCodec.libvpx && comboBoxExtension.Text != "webm")
|
|
|
|
|
comboBoxExtension.Text = "webm";
|
|
|
|
|
|
|
|
|
|
textBoxCommandLinePreview.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)
|
|
|
|
|
{
|
|
|
|
|
Helpers.BrowseFile("Browse for ffmpeg.exe", textBoxFFmpegPath, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
|
2014-05-09 23:45:10 +12:00
|
|
|
|
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)
|
2014-05-10 13:52:09 +12:00
|
|
|
|
{
|
|
|
|
|
DownloadFFmpeg();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 16:17:56 +12:00
|
|
|
|
public DialogResult DownloadFFmpeg(bool runInstallerInBackground = true)
|
2014-05-10 12:23:47 +12:00
|
|
|
|
{
|
2014-05-10 16:17:56 +12:00
|
|
|
|
using (DownloaderForm form = new DownloaderForm(FFmpegDownloadLink, "ffmpeg.7z"))
|
2014-05-10 12:23:47 +12:00
|
|
|
|
{
|
2014-05-10 13:52:09 +12:00
|
|
|
|
form.Proxy = ProxyInfo.Current.GetWebProxy();
|
2014-05-10 12:23:47 +12:00
|
|
|
|
form.InstallType = InstallType.Event;
|
2014-05-10 16:17:56 +12:00
|
|
|
|
form.RunInstallerInBackground = runInstallerInBackground;
|
2014-05-10 12:23:47 +12:00
|
|
|
|
form.InstallRequested += form_InstallRequested;
|
2014-05-10 16:17:56 +12:00
|
|
|
|
return form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string FFmpegDownloadLink
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (NativeMethods.Is64Bit())
|
|
|
|
|
{
|
|
|
|
|
return "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.7z";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z";
|
|
|
|
|
}
|
2014-05-10 12:23:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void form_InstallRequested(string filePath)
|
|
|
|
|
{
|
2014-05-10 20:04:18 +12:00
|
|
|
|
string extractPath = Options.FFmpeg.CLIPath;
|
2014-05-10 12:23:47 +12:00
|
|
|
|
bool result = ExtractFFmpeg(filePath, extractPath);
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
2014-05-10 20:04:18 +12:00
|
|
|
|
this.InvokeSafe(() => textBoxFFmpegPath.Text = extractPath);
|
2014-05-10 13:52:09 +12:00
|
|
|
|
MessageBox.Show("FFmpeg successfully downloaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2014-05-10 12:23:47 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-05-10 13:52:09 +12:00
|
|
|
|
MessageBox.Show("Download of FFmpeg failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2014-05-10 12:23:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 16:17:56 +12:00
|
|
|
|
public static bool ExtractFFmpeg(string zipPath, string extractPath)
|
2014-05-10 12:23:47 +12:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (NativeMethods.Is64Bit())
|
|
|
|
|
{
|
|
|
|
|
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z-x64.dll"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z.dll"));
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 20:04:18 +12:00
|
|
|
|
Helpers.CreateDirectoryIfNotExist(extractPath);
|
|
|
|
|
|
2014-05-10 12:23:47 +12:00
|
|
|
|
using (SevenZipExtractor zip = new SevenZipExtractor(zipPath))
|
|
|
|
|
{
|
|
|
|
|
Regex regex = new Regex(@"^ffmpeg-.+\\bin\\ffmpeg\.exe$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
|
|
|
|
|
|
|
|
|
foreach (ArchiveFileInfo item in zip.ArchiveFileData)
|
|
|
|
|
{
|
|
|
|
|
if (regex.IsMatch(item.FileName))
|
|
|
|
|
{
|
|
|
|
|
using (FileStream fs = new FileStream(extractPath, FileMode.Create, FileAccess.Write, FileShare.None))
|
|
|
|
|
{
|
|
|
|
|
zip.ExtractFile(item.Index, fs);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-05-09 15:14:53 +12:00
|
|
|
|
}
|
|
|
|
|
}
|