mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
FFmpeg download function in FFmpegHelper, Moved FFmpegOptionsForm to ScreenCaptureLib
This commit is contained in:
parent
1886ab00b8
commit
2e554cdf92
12 changed files with 204 additions and 123 deletions
|
@ -45,6 +45,9 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\AsyncBridge.Net35.0.2.0\lib\net35-Client\AsyncBridge.Net35.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SevenZipSharp">
|
||||
<HintPath>..\packages\SevenZipSharp.0.64\lib\SevenZipSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
@ -58,7 +61,15 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="Screencast\AVIOptions.cs" />
|
||||
<Compile Include="Screencast\FFmpegOptions.cs" />
|
||||
<Compile Include="Screencast\FFmpegHelper.cs" />
|
||||
<Compile Include="Screencast\FFmpegOptionsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Screencast\FFmpegOptionsForm.Designer.cs">
|
||||
<DependentUpon>FFmpegOptionsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Screencast\ScreencastOptions.cs" />
|
||||
<Compile Include="Screencast\AviWriter.cs" />
|
||||
<Compile Include="Forms\RectangleLight.cs">
|
||||
|
@ -136,6 +147,9 @@
|
|||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Screencast\FFmpegOptionsForm.resx">
|
||||
<DependentUpon>FFmpegOptionsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
38
ScreenCaptureLib/Screencast/AVIOptions.cs
Normal file
38
ScreenCaptureLib/Screencast/AVIOptions.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
#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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ScreenCaptureLib
|
||||
{
|
||||
public class AVIOptions
|
||||
{
|
||||
public AVICOMPRESSOPTIONS CompressOptions;
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using HelpersLib;
|
||||
using SevenZip;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
@ -31,6 +32,7 @@ You should have received a copy of the GNU General Public License
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ScreenCaptureLib
|
||||
|
@ -79,6 +81,69 @@ public bool Record()
|
|||
return result == 0;
|
||||
}
|
||||
|
||||
public static DialogResult DownloadFFmpeg(bool async, DownloaderForm.DownloaderInstallEventHandler installRequested)
|
||||
{
|
||||
string url;
|
||||
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
url = "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.7z";
|
||||
}
|
||||
else
|
||||
{
|
||||
url = "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z";
|
||||
}
|
||||
|
||||
using (DownloaderForm form = new DownloaderForm(url, "ffmpeg.7z"))
|
||||
{
|
||||
form.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||
form.InstallType = InstallType.Event;
|
||||
form.RunInstallerInBackground = async;
|
||||
form.InstallRequested += installRequested;
|
||||
return form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ExtractFFmpeg(string zipPath, string extractPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z-x64.dll"));
|
||||
}
|
||||
else
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z.dll"));
|
||||
}
|
||||
|
||||
Helpers.CreateDirectoryIfNotExist(extractPath);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void ListDevices()
|
||||
{
|
||||
WriteInput("-list_devices true -f dshow -i dummy");
|
||||
|
|
57
ScreenCaptureLib/Screencast/FFmpegOptions.cs
Normal file
57
ScreenCaptureLib/Screencast/FFmpegOptions.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
#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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ScreenCaptureLib
|
||||
{
|
||||
public class FFmpegOptions
|
||||
{
|
||||
public string CLIPath { get; set; }
|
||||
public FFmpegVideoCodec VideoCodec { get; set; }
|
||||
public string Extension { get; set; }
|
||||
public string UserArgs { get; set; }
|
||||
|
||||
// H264
|
||||
public FFmpegPreset Preset { get; set; }
|
||||
public int CRF { get; set; }
|
||||
|
||||
// H263
|
||||
public int qscale { get; set; }
|
||||
|
||||
public FFmpegOptions()
|
||||
{
|
||||
CLIPath = "ffmpeg.exe";
|
||||
VideoCodec = FFmpegVideoCodec.libx264;
|
||||
Preset = FFmpegPreset.medium;
|
||||
CRF = 23;
|
||||
qscale = 3;
|
||||
Extension = "mp4";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace ShareX
|
||||
namespace ScreenCaptureLib
|
||||
{
|
||||
partial class FFmpegOptionsForm
|
||||
{
|
|
@ -37,11 +37,12 @@ You should have received a copy of the GNU General Public License
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ShareX
|
||||
namespace ScreenCaptureLib
|
||||
{
|
||||
public partial class FFmpegOptionsForm : Form
|
||||
{
|
||||
private ScreencastOptions Options = new ScreencastOptions();
|
||||
public ScreencastOptions Options = new ScreencastOptions();
|
||||
public string DefaultToolsPath;
|
||||
|
||||
public FFmpegOptionsForm(FFmpegOptions ffMpegOptions)
|
||||
{
|
||||
|
@ -140,39 +141,16 @@ private void buttonFFmpegHelp_Click(object sender, EventArgs e)
|
|||
|
||||
private void btnDownload_Click(object sender, EventArgs e)
|
||||
{
|
||||
DownloadFFmpeg();
|
||||
FFmpegHelper.DownloadFFmpeg(true, DownloaderForm_InstallRequested);
|
||||
}
|
||||
|
||||
public DialogResult DownloadFFmpeg(bool runInstallerInBackground = true)
|
||||
private void DownloaderForm_InstallRequested(string filePath)
|
||||
{
|
||||
using (DownloaderForm form = new DownloaderForm(FFmpegDownloadLink(), "ffmpeg.7z"))
|
||||
{
|
||||
form.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||
form.InstallType = InstallType.Event;
|
||||
form.RunInstallerInBackground = runInstallerInBackground;
|
||||
form.InstallRequested += form_InstallRequested;
|
||||
return form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public static string FFmpegDownloadLink()
|
||||
{
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
return "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.7z";
|
||||
}
|
||||
|
||||
return "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z";
|
||||
}
|
||||
|
||||
private void form_InstallRequested(string filePath)
|
||||
{
|
||||
string extractPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
||||
bool result = ExtractFFmpeg(filePath, extractPath);
|
||||
bool result = FFmpegHelper.ExtractFFmpeg(filePath, DefaultToolsPath ?? "ffmpeg.exe");
|
||||
|
||||
if (result)
|
||||
{
|
||||
this.InvokeSafe(() => textBoxFFmpegPath.Text = extractPath);
|
||||
this.InvokeSafe(() => textBoxFFmpegPath.Text = DefaultToolsPath);
|
||||
MessageBox.Show("FFmpeg successfully downloaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
|
@ -180,45 +158,5 @@ private void form_InstallRequested(string filePath)
|
|||
MessageBox.Show("Download of FFmpeg failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ExtractFFmpeg(string zipPath, string extractPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z-x64.dll"));
|
||||
}
|
||||
else
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z.dll"));
|
||||
}
|
||||
|
||||
Helpers.CreateDirectoryIfNotExist(extractPath);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -96,34 +96,4 @@ public string GetFFmpegArgs()
|
|||
return args.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public class AVIOptions
|
||||
{
|
||||
public AVICOMPRESSOPTIONS CompressOptions;
|
||||
}
|
||||
|
||||
public class FFmpegOptions
|
||||
{
|
||||
public string CLIPath { get; set; }
|
||||
public FFmpegVideoCodec VideoCodec { get; set; }
|
||||
public string Extension { get; set; }
|
||||
public string UserArgs { get; set; }
|
||||
|
||||
// H264
|
||||
public FFmpegPreset Preset { get; set; }
|
||||
public int CRF { get; set; }
|
||||
|
||||
// H263
|
||||
public int qscale { get; set; }
|
||||
|
||||
public FFmpegOptions()
|
||||
{
|
||||
CLIPath = "ffmpeg.exe";
|
||||
VideoCodec = FFmpegVideoCodec.libx264;
|
||||
Preset = FFmpegPreset.medium;
|
||||
CRF = 23;
|
||||
qscale = 3;
|
||||
Extension = "mp4";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AsyncBridge.Net35" version="0.2.0" targetFramework="net35" />
|
||||
<package id="SevenZipSharp" version="0.64" targetFramework="net35" />
|
||||
<package id="TaskParallelLibrary" version="1.0.2856.0" targetFramework="net35" />
|
||||
</packages>
|
|
@ -101,18 +101,15 @@ public async void StartRecording(TaskSettings TaskSettings)
|
|||
|
||||
if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg && !File.Exists(TaskSettings.CaptureSettings.FFmpegOptions.CLIPath))
|
||||
{
|
||||
if (MessageBox.Show(TaskSettings.CaptureSettings.FFmpegOptions.CLIPath + " does not exist." + Environment.NewLine + Environment.NewLine + "Would you like to automatically download it?",
|
||||
string ffmpegText = string.IsNullOrEmpty(TaskSettings.CaptureSettings.FFmpegOptions.CLIPath) ? "ffmpeg.exe" : TaskSettings.CaptureSettings.FFmpegOptions.CLIPath;
|
||||
|
||||
if (MessageBox.Show(ffmpegText + " does not exist." + Environment.NewLine + Environment.NewLine + "Would you like to automatically download it?",
|
||||
Application.ProductName + " - Missing ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
||||
{
|
||||
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = TaskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
|
||||
TaskSettings.CaptureSettings.FFmpegOptions.CLIPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
||||
|
||||
using (FFmpegOptionsForm form = new FFmpegOptionsForm(TaskSettings.CaptureSettings.FFmpegOptions))
|
||||
if (FFmpegHelper.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK)
|
||||
{
|
||||
if (form.DownloadFFmpeg(false) == DialogResult.Cancel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = TaskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
|
||||
TaskSettings.CaptureSettings.FFmpegOptions.CLIPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -255,6 +252,21 @@ await TaskEx.Run(() =>
|
|||
IsRecording = false;
|
||||
}
|
||||
|
||||
private void DownloaderForm_InstallRequested(string filePath)
|
||||
{
|
||||
string extractPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
||||
bool result = FFmpegHelper.ExtractFFmpeg(filePath, extractPath);
|
||||
|
||||
if (result)
|
||||
{
|
||||
MessageBox.Show("FFmpeg successfully downloaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Download of FFmpeg failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopRecording()
|
||||
{
|
||||
if (IsRecording && screenRecorder != null)
|
||||
|
|
|
@ -77,10 +77,6 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SevenZipSharp, Version=0.64.3890.29348, Culture=neutral, PublicKeyToken=20de82c62b055c88, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SevenZipSharp.0.64\lib\SevenZipSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
|
@ -131,12 +127,6 @@
|
|||
<Compile Include="Forms\ExternalProgramForm.Designer.cs">
|
||||
<DependentUpon>ExternalProgramForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\FFmpegOptionsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\FFmpegOptionsForm.Designer.cs">
|
||||
<DependentUpon>FFmpegOptionsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\FileExistForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -269,9 +259,6 @@
|
|||
<EmbeddedResource Include="Forms\ExternalProgramForm.resx">
|
||||
<DependentUpon>ExternalProgramForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\FFmpegOptionsForm.resx">
|
||||
<DependentUpon>FFmpegOptionsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\FileExistForm.resx">
|
||||
<DependentUpon>FileExistForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
|
|
@ -3,6 +3,5 @@
|
|||
<package id="AsyncBridge.Net35" version="0.2.0" targetFramework="net35" />
|
||||
<package id="MegaApiClient" version="1.0.4" targetFramework="net35" />
|
||||
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net35" />
|
||||
<package id="SevenZipSharp" version="0.64" targetFramework="net35" />
|
||||
<package id="TaskParallelLibrary" version="1.0.2856.0" targetFramework="net35" />
|
||||
</packages>
|
Loading…
Reference in a new issue