ShareX/ScreenCaptureLib/Screencast/FFmpegCLIOptionsForm.cs

100 lines
3.8 KiB
C#
Raw Normal View History

2014-05-09 15:14:53 +12:00
using HelpersLib;
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;
using System.Windows.Forms;
namespace ScreenCaptureLib
{
public partial class FFmpegCLIOptionsForm : Form
{
private ScreencastOptions Options = null;
2014-05-09 15:14:53 +12:00
public FFmpegCLIOptionsForm(ScreencastOptions options)
2014-05-09 15:14:53 +12:00
{
Options = options;
InitializeComponent();
this.Text = string.Format("{0} - FFmpeg CLI Options", Application.ProductName);
this.Icon = ShareXResources.Icon;
LoadSettings();
UpdateUI();
}
private void LoadSettings()
{
comboBoxCodec.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegVideoCodec>());
comboBoxCodec.SelectedIndex = (int)Options.FFmpeg.VideoCodec;
comboBoxCodec.SelectedIndexChanged += (sender, e) => UpdateUI();
2014-05-09 15:14:53 +12:00
comboBoxExtension.Text = Options.FFmpeg.Extension;
comboBoxExtension.SelectedIndexChanged += (sender, e) => UpdateUI();
2014-05-09 15:14:53 +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>());
comboBoxPreset.SelectedIndex = (int)Options.FFmpeg.Preset;
comboBoxPreset.SelectedIndexChanged += (sender, e) => UpdateUI();
2014-05-09 18:41:16 +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
string cli = Path.Combine(Application.StartupPath, "ffmpeg.exe");
if (string.IsNullOrEmpty(Options.FFmpeg.CLIPath) && File.Exists(cli))
Options.FFmpeg.CLIPath = cli;
textBoxFFmpegPath.Text = Options.FFmpeg.CLIPath;
textBoxFFmpegPath.TextChanged += (sender, e) => UpdateUI();
2014-05-09 15:14:53 +12:00
}
public void SaveSettings()
2014-05-09 15:14:53 +12:00
{
Options.FFmpeg.VideoCodec = (FFmpegVideoCodec)comboBoxCodec.SelectedIndex;
Options.FFmpeg.Extension = comboBoxExtension.Text;
2014-05-09 15:14:53 +12:00
Options.FFmpeg.CRF = (int)nudCRF.Value;
Options.FFmpeg.Preset = (FFmpegPreset)comboBoxPreset.SelectedIndex;
Options.FFmpeg.qscale = (int)nudQscale.Value;
2014-05-09 15:14:53 +12:00
Options.FFmpeg.UserArgs = textBoxUserArgs.Text;
2014-05-09 15:14:53 +12:00
Options.FFmpeg.CLIPath = textBoxFFmpegPath.Text;
2014-05-09 15:14:53 +12:00
}
public void UpdateUI()
2014-05-09 15:14:53 +12:00
{
SaveSettings();
2014-05-09 15:14:53 +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));
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-09 15:14:53 +12:00
}
}