From 39c169771dec8f61a882a0bebb17cab731af211d Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 15 Mar 2023 11:23:38 +0300 Subject: [PATCH] Added bitrate option to video converter --- .../Forms/VideoConverterForm.Designer.cs | 120 +++-- ShareX.MediaLib/Forms/VideoConverterForm.cs | 39 +- ShareX.MediaLib/Forms/VideoConverterForm.resx | 439 +++++++++++------- ShareX.MediaLib/VideoConverterOptions.cs | 85 +++- .../StickerImageListViewRenderer.cs | 0 .../ShareX.ScreenCaptureLib.csproj | 2 +- 6 files changed, 444 insertions(+), 241 deletions(-) rename ShareX.ScreenCaptureLib/{Forms => Helpers}/StickerImageListViewRenderer.cs (100%) diff --git a/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs b/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs index 2101461ed..55c89db78 100644 --- a/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs +++ b/ShareX.MediaLib/Forms/VideoConverterForm.Designer.cs @@ -37,19 +37,23 @@ private void InitializeComponent() this.btnOutputFolderBrowse = new System.Windows.Forms.Button(); this.lblOutputFileName = new System.Windows.Forms.Label(); this.txtOutputFileName = new System.Windows.Forms.TextBox(); - this.lblVideoCodec = new System.Windows.Forms.Label(); - this.cbVideoCodec = new System.Windows.Forms.ComboBox(); + this.cbVideoEncoder = new System.Windows.Forms.ComboBox(); this.lblVideoQuality = new System.Windows.Forms.Label(); this.btnEncode = new System.Windows.Forms.Button(); this.txtArguments = new System.Windows.Forms.TextBox(); + this.cbAutoOpenFolder = new System.Windows.Forms.CheckBox(); + this.pbProgress = new ShareX.HelpersLib.BlackStyleProgressBar(); + this.cbUseCustomArguments = new System.Windows.Forms.CheckBox(); + this.lblVideoEncoder = new System.Windows.Forms.Label(); this.tbVideoQuality = new System.Windows.Forms.TrackBar(); this.lblVideoQualityValue = new System.Windows.Forms.Label(); this.lblVideoQualityHigher = new System.Windows.Forms.Label(); this.lblVideoQualityLower = new System.Windows.Forms.Label(); - this.cbAutoOpenFolder = new System.Windows.Forms.CheckBox(); - this.pbProgress = new ShareX.HelpersLib.BlackStyleProgressBar(); - this.cbUseCustomArguments = new System.Windows.Forms.CheckBox(); + this.nudVideoQualityBitrate = new System.Windows.Forms.NumericUpDown(); + this.lblVideoQualityBitrateHint = new System.Windows.Forms.Label(); + this.cbVideoQualityUseBitrate = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.tbVideoQuality)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudVideoQualityBitrate)).BeginInit(); this.SuspendLayout(); // // lblInputFilePath @@ -99,18 +103,13 @@ private void InitializeComponent() this.txtOutputFileName.Name = "txtOutputFileName"; this.txtOutputFileName.TextChanged += new System.EventHandler(this.txtOutputFileName_TextChanged); // - // lblVideoCodec + // cbVideoEncoder // - resources.ApplyResources(this.lblVideoCodec, "lblVideoCodec"); - this.lblVideoCodec.Name = "lblVideoCodec"; - // - // cbVideoCodec - // - this.cbVideoCodec.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbVideoCodec.FormattingEnabled = true; - resources.ApplyResources(this.cbVideoCodec, "cbVideoCodec"); - this.cbVideoCodec.Name = "cbVideoCodec"; - this.cbVideoCodec.SelectedIndexChanged += new System.EventHandler(this.cbVideoCodec_SelectedIndexChanged); + this.cbVideoEncoder.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbVideoEncoder.FormattingEnabled = true; + resources.ApplyResources(this.cbVideoEncoder, "cbVideoEncoder"); + this.cbVideoEncoder.Name = "cbVideoEncoder"; + this.cbVideoEncoder.SelectedIndexChanged += new System.EventHandler(this.cbVideoEncoder_SelectedIndexChanged); // // lblVideoQuality // @@ -130,6 +129,32 @@ private void InitializeComponent() this.txtArguments.Name = "txtArguments"; this.txtArguments.TextChanged += new System.EventHandler(this.txtArguments_TextChanged); // + // cbAutoOpenFolder + // + resources.ApplyResources(this.cbAutoOpenFolder, "cbAutoOpenFolder"); + this.cbAutoOpenFolder.Name = "cbAutoOpenFolder"; + this.cbAutoOpenFolder.UseVisualStyleBackColor = true; + this.cbAutoOpenFolder.CheckedChanged += new System.EventHandler(this.cbAutoOpenFolder_CheckedChanged); + // + // pbProgress + // + resources.ApplyResources(this.pbProgress, "pbProgress"); + this.pbProgress.ForeColor = System.Drawing.Color.White; + this.pbProgress.Name = "pbProgress"; + this.pbProgress.ShowPercentageText = true; + // + // cbUseCustomArguments + // + resources.ApplyResources(this.cbUseCustomArguments, "cbUseCustomArguments"); + this.cbUseCustomArguments.Name = "cbUseCustomArguments"; + this.cbUseCustomArguments.UseVisualStyleBackColor = true; + this.cbUseCustomArguments.CheckedChanged += new System.EventHandler(this.cbUseCustomArguments_CheckedChanged); + // + // lblVideoEncoder + // + resources.ApplyResources(this.lblVideoEncoder, "lblVideoEncoder"); + this.lblVideoEncoder.Name = "lblVideoEncoder"; + // // tbVideoQuality // resources.ApplyResources(this.tbVideoQuality, "tbVideoQuality"); @@ -153,26 +178,38 @@ private void InitializeComponent() resources.ApplyResources(this.lblVideoQualityLower, "lblVideoQualityLower"); this.lblVideoQualityLower.Name = "lblVideoQualityLower"; // - // cbAutoOpenFolder + // nudVideoQualityBitrate // - resources.ApplyResources(this.cbAutoOpenFolder, "cbAutoOpenFolder"); - this.cbAutoOpenFolder.Name = "cbAutoOpenFolder"; - this.cbAutoOpenFolder.UseVisualStyleBackColor = true; - this.cbAutoOpenFolder.CheckedChanged += new System.EventHandler(this.cbAutoOpenFolder_CheckedChanged); + resources.ApplyResources(this.nudVideoQualityBitrate, "nudVideoQualityBitrate"); + this.nudVideoQualityBitrate.Maximum = new decimal(new int[] { + 100000, + 0, + 0, + 0}); + this.nudVideoQualityBitrate.Minimum = new decimal(new int[] { + 100, + 0, + 0, + 0}); + this.nudVideoQualityBitrate.Name = "nudVideoQualityBitrate"; + this.nudVideoQualityBitrate.Value = new decimal(new int[] { + 3000, + 0, + 0, + 0}); + this.nudVideoQualityBitrate.ValueChanged += new System.EventHandler(this.nudVideoQualityBitrate_ValueChanged); // - // pbProgress + // lblVideoQualityBitrateHint // - resources.ApplyResources(this.pbProgress, "pbProgress"); - this.pbProgress.ForeColor = System.Drawing.Color.White; - this.pbProgress.Name = "pbProgress"; - this.pbProgress.ShowPercentageText = true; + resources.ApplyResources(this.lblVideoQualityBitrateHint, "lblVideoQualityBitrateHint"); + this.lblVideoQualityBitrateHint.Name = "lblVideoQualityBitrateHint"; // - // cbUseCustomArguments + // cbVideoQualityUseBitrate // - resources.ApplyResources(this.cbUseCustomArguments, "cbUseCustomArguments"); - this.cbUseCustomArguments.Name = "cbUseCustomArguments"; - this.cbUseCustomArguments.UseVisualStyleBackColor = true; - this.cbUseCustomArguments.CheckedChanged += new System.EventHandler(this.cbUseCustomArguments_CheckedChanged); + resources.ApplyResources(this.cbVideoQualityUseBitrate, "cbVideoQualityUseBitrate"); + this.cbVideoQualityUseBitrate.Name = "cbVideoQualityUseBitrate"; + this.cbVideoQualityUseBitrate.UseVisualStyleBackColor = true; + this.cbVideoQualityUseBitrate.CheckedChanged += new System.EventHandler(this.cbVideoQualityUseBitrate_CheckedChanged); // // VideoConverterForm // @@ -180,6 +217,10 @@ private void InitializeComponent() resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BackColor = System.Drawing.SystemColors.Window; + this.Controls.Add(this.cbVideoQualityUseBitrate); + this.Controls.Add(this.lblVideoQualityBitrateHint); + this.Controls.Add(this.nudVideoQualityBitrate); + this.Controls.Add(this.lblVideoEncoder); this.Controls.Add(this.lblVideoQualityValue); this.Controls.Add(this.cbUseCustomArguments); this.Controls.Add(this.cbAutoOpenFolder); @@ -187,10 +228,9 @@ private void InitializeComponent() this.Controls.Add(this.lblVideoQualityLower); this.Controls.Add(this.txtOutputFileName); this.Controls.Add(this.lblOutputFileName); - this.Controls.Add(this.lblVideoCodec); this.Controls.Add(this.tbVideoQuality); this.Controls.Add(this.btnOutputFolderBrowse); - this.Controls.Add(this.cbVideoCodec); + this.Controls.Add(this.cbVideoEncoder); this.Controls.Add(this.lblOutputFolder); this.Controls.Add(this.lblVideoQuality); this.Controls.Add(this.txtOutputFolder); @@ -207,6 +247,7 @@ private void InitializeComponent() this.DragDrop += new System.Windows.Forms.DragEventHandler(this.VideoConverterForm_DragDrop); this.DragEnter += new System.Windows.Forms.DragEventHandler(this.VideoConverterForm_DragEnter); ((System.ComponentModel.ISupportInitialize)(this.tbVideoQuality)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudVideoQualityBitrate)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -222,17 +263,20 @@ private void InitializeComponent() private System.Windows.Forms.Button btnOutputFolderBrowse; private System.Windows.Forms.Label lblOutputFileName; private System.Windows.Forms.TextBox txtOutputFileName; - private System.Windows.Forms.Label lblVideoCodec; - private System.Windows.Forms.ComboBox cbVideoCodec; + private System.Windows.Forms.ComboBox cbVideoEncoder; private System.Windows.Forms.Label lblVideoQuality; private System.Windows.Forms.Button btnEncode; private System.Windows.Forms.TextBox txtArguments; + private HelpersLib.BlackStyleProgressBar pbProgress; + private System.Windows.Forms.CheckBox cbAutoOpenFolder; + private System.Windows.Forms.CheckBox cbUseCustomArguments; + private System.Windows.Forms.Label lblVideoEncoder; private System.Windows.Forms.TrackBar tbVideoQuality; private System.Windows.Forms.Label lblVideoQualityValue; private System.Windows.Forms.Label lblVideoQualityHigher; private System.Windows.Forms.Label lblVideoQualityLower; - private HelpersLib.BlackStyleProgressBar pbProgress; - private System.Windows.Forms.CheckBox cbAutoOpenFolder; - private System.Windows.Forms.CheckBox cbUseCustomArguments; + private System.Windows.Forms.NumericUpDown nudVideoQualityBitrate; + private System.Windows.Forms.Label lblVideoQualityBitrateHint; + private System.Windows.Forms.CheckBox cbVideoQualityUseBitrate; } } \ No newline at end of file diff --git a/ShareX.MediaLib/Forms/VideoConverterForm.cs b/ShareX.MediaLib/Forms/VideoConverterForm.cs index 797e158d3..b94f9bb7d 100644 --- a/ShareX.MediaLib/Forms/VideoConverterForm.cs +++ b/ShareX.MediaLib/Forms/VideoConverterForm.cs @@ -53,9 +53,11 @@ public VideoConverterForm(string ffmpegFilePath, VideoConverterOptions options) txtInputFilePath.Text = Options.InputFilePath; txtOutputFolder.Text = Options.OutputFolderPath; txtOutputFileName.Text = Options.OutputFileName; - cbVideoCodec.Items.AddRange(Helpers.GetEnumDescriptions()); - cbVideoCodec.SelectedIndex = (int)Options.VideoCodec; + cbVideoEncoder.Items.AddRange(Helpers.GetEnumDescriptions()); + cbVideoEncoder.SelectedIndex = (int)Options.VideoCodec; + cbVideoQualityUseBitrate.Checked = Options.VideoQualityUseBitrate; tbVideoQuality.SetValue(tbVideoQuality.Minimum + tbVideoQuality.Maximum - Options.VideoQuality); + nudVideoQualityBitrate.SetValue(Options.VideoQualityBitrate); cbAutoOpenFolder.Checked = Options.AutoOpenFolder; @@ -76,8 +78,11 @@ private void UpdateOptions() Options.InputFilePath = txtInputFilePath.Text; Options.OutputFolderPath = txtOutputFolder.Text; Options.OutputFileName = txtOutputFileName.Text; - Options.VideoCodec = (ConverterVideoCodecs)cbVideoCodec.SelectedIndex; + Options.VideoCodec = (ConverterVideoCodecs)cbVideoEncoder.SelectedIndex; + Options.VideoQualityUseBitrate = cbVideoQualityUseBitrate.Checked; + Options.VideoQualityBitrate = (int)nudVideoQualityBitrate.Value; Options.UseCustomArguments = cbUseCustomArguments.Checked; + if (Options.UseCustomArguments) { Options.CustomArguments = txtArguments.Text; @@ -91,12 +96,14 @@ private void UpdateOptions() case ConverterVideoCodecs.vp8: case ConverterVideoCodecs.vp9: case ConverterVideoCodecs.xvid: - lblVideoQuality.Visible = tbVideoQuality.Visible = lblVideoQualityValue.Visible = lblVideoQualityLower.Visible = - lblVideoQualityHigher.Visible = !Options.UseCustomArguments; + lblVideoQuality.Visible = cbVideoQualityUseBitrate.Visible = !Options.UseCustomArguments; + tbVideoQuality.Visible = lblVideoQualityValue.Visible = lblVideoQualityLower.Visible = lblVideoQualityHigher.Visible = + !Options.UseCustomArguments && !Options.VideoQualityUseBitrate; + nudVideoQualityBitrate.Visible = lblVideoQualityBitrateHint.Visible = !Options.UseCustomArguments && Options.VideoQualityUseBitrate; break; default: - lblVideoQuality.Visible = tbVideoQuality.Visible = lblVideoQualityValue.Visible = lblVideoQualityLower.Visible = - lblVideoQualityHigher.Visible = false; + lblVideoQuality.Visible = cbVideoQualityUseBitrate.Visible = tbVideoQuality.Visible = lblVideoQualityValue.Visible = lblVideoQualityLower.Visible = + lblVideoQualityHigher.Visible = nudVideoQualityBitrate.Visible = lblVideoQualityBitrateHint.Visible = false; break; } @@ -124,8 +131,8 @@ private void UpdateOptions() break; } - lblVideoQualityLower.Text = tbVideoQuality.Maximum + " <- " + Resources.LowerQualitySize; - lblVideoQualityHigher.Text = Resources.HigherQualitySize + " -> " + tbVideoQuality.Minimum; + lblVideoQualityLower.Text = tbVideoQuality.Maximum + " ← " + Resources.LowerQualitySize; + lblVideoQualityHigher.Text = Resources.HigherQualitySize + " → " + tbVideoQuality.Minimum; if (formReady) { @@ -146,7 +153,7 @@ private void UpdateOptions() } } - lblVideoCodec.Visible = cbVideoCodec.Visible = !Options.UseCustomArguments; + lblVideoEncoder.Visible = cbVideoEncoder.Visible = !Options.UseCustomArguments; txtArguments.Visible = Options.UseCustomArguments; btnEncode.Enabled = !string.IsNullOrEmpty(Options.InputFilePath) && !string.IsNullOrEmpty(Options.OutputFolderPath) && @@ -247,7 +254,12 @@ private void txtOutputFileName_TextChanged(object sender, EventArgs e) UpdateOptions(); } - private void cbVideoCodec_SelectedIndexChanged(object sender, EventArgs e) + private void cbVideoEncoder_SelectedIndexChanged(object sender, EventArgs e) + { + UpdateOptions(); + } + + private void cbVideoQualityUseBitrate_CheckedChanged(object sender, EventArgs e) { UpdateOptions(); } @@ -257,6 +269,11 @@ private void tbVideoQuality_ValueChanged(object sender, EventArgs e) UpdateOptions(); } + private void nudVideoQualityBitrate_ValueChanged(object sender, EventArgs e) + { + UpdateOptions(); + } + private void cbAutoOpenFolder_CheckedChanged(object sender, EventArgs e) { Options.AutoOpenFolder = cbAutoOpenFolder.Checked; diff --git a/ShareX.MediaLib/Forms/VideoConverterForm.resx b/ShareX.MediaLib/Forms/VideoConverterForm.resx index 606fa0434..2278737af 100644 --- a/ShareX.MediaLib/Forms/VideoConverterForm.resx +++ b/ShareX.MediaLib/Forms/VideoConverterForm.resx @@ -144,13 +144,13 @@ $this - 16 + 19 - 162, 12 + 160, 12 - 342, 20 + 344, 20 1 @@ -165,7 +165,7 @@ $this - 15 + 18 512, 11 @@ -178,7 +178,6 @@ ... - @Invariant btnInputFilePathBrowse @@ -190,13 +189,13 @@ $this - 14 + 17 - 162, 36 + 160, 36 - 342, 20 + 344, 20 4 @@ -211,7 +210,7 @@ $this - 13 + 16 True @@ -238,7 +237,7 @@ $this - 11 + 14 512, 35 @@ -251,7 +250,6 @@ ... - @Invariant btnOutputFolderBrowse @@ -263,7 +261,7 @@ $this - 9 + 12 True @@ -290,13 +288,13 @@ $this - 6 + 10 - 162, 60 + 160, 60 - 342, 20 + 344, 20 7 @@ -311,61 +309,34 @@ $this - 5 - - - True - - - 13, 96 - - - 70, 13 - - - 8 - - - Video codec: - - - lblVideoCodec - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 7 - - - 120, 92 - - - 120, 21 - - 9 - - cbVideoCodec + + 160, 84 - + + 120, 21 + + + 9 + + + cbVideoEncoder + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 10 + + 13 True - 13, 128 + 13, 112 70, 13 @@ -386,7 +357,7 @@ $this - 12 + 15 Microsoft Sans Serif, 9.75pt @@ -398,7 +369,7 @@ 184, 32 - 18 + 21 Start encoding @@ -413,7 +384,7 @@ $this - 17 + 20 Verdana, 9.75pt @@ -425,10 +396,10 @@ True - 526, 80 + 528, 72 - 15 + 18 txtArguments @@ -440,124 +411,19 @@ $this - 19 - - - False - - - 112, 123 - - - 398, 22 - - - 11 - - - tbVideoQuality - - - System.Windows.Forms.TrackBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 8 - - - True - - - 515, 126 - - - 13, 13 - - - 12 - - - 0 - @Invariant - - - lblVideoQualityValue - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - - - 323, 146 - - - 182, 22 - - - 14 - - - Xxxxxxxxxxxxxxxxxxxxxxxxxxxx -> 99 - @Invariant - - - TopRight - - - lblVideoQualityHigher - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 3 - - - 117, 146 - - - 192, 22 - - - 13 - - - 99 <- Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - @Invariant - - - lblVideoQualityLower - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 4 + 22 True - 16, 200 + 16, 192 152, 17 - 17 + 20 Open folder after encoding @@ -572,7 +438,7 @@ $this - 2 + 6 Arial, 11.25pt @@ -584,7 +450,7 @@ 336, 32 - 19 + 22 @@ -594,25 +460,25 @@ pbProgress - ShareX.HelpersLib.BlackStyleProgressBar, ShareX.HelpersLib, Version=14.1.2.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.BlackStyleProgressBar, ShareX.HelpersLib, Version=15.0.1.0, Culture=neutral, PublicKeyToken=null $this - 18 + 21 True - 16, 176 + 16, 168 134, 17 - 16 + 19 Use custom arguments @@ -627,8 +493,227 @@ $this + 5 + + + True + + + 13, 88 + + + 79, 13 + + + 8 + + + Video encoder: + + + lblVideoEncoder + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + False + + + NoControl + + + 153, 112 + + + 359, 24 + + + 11 + + + tbVideoQuality + + + System.Windows.Forms.TrackBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 11 + + + True + + + NoControl + + + 512, 117 + + + 13, 13 + + + 12 + + + 0 + + + lblVideoQualityValue + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + + + NoControl + + + 316, 139 + + + 192, 18 + + + 14 + + + xxxxxxxxxxxxxxxxxxxxxxxxxxxx -> 99 + + + TopRight + + + lblVideoQualityHigher + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + + + NoControl + + + 157, 139 + + + 192, 18 + + + 13 + + + 99 <- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + + lblVideoQualityLower + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 8 + + + 160, 112 + + + 80, 20 + + + 15 + + + Center + + + nudVideoQualityBitrate + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + True + + + 245, 116 + + + 34, 13 + + + 16 + + + kbit/s + + + lblVideoQualityBitrateHint + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 1 + + True + + + 16, 136 + + + 77, 17 + + + 17 + + + Use bitrate + + + cbVideoQualityUseBitrate + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + True diff --git a/ShareX.MediaLib/VideoConverterOptions.cs b/ShareX.MediaLib/VideoConverterOptions.cs index dbb6c86f1..e1815067c 100644 --- a/ShareX.MediaLib/VideoConverterOptions.cs +++ b/ShareX.MediaLib/VideoConverterOptions.cs @@ -52,6 +52,8 @@ public string OutputFilePath public ConverterVideoCodecs VideoCodec { get; set; } = ConverterVideoCodecs.x264; public int VideoQuality { get; set; } = 23; + public bool VideoQualityUseBitrate { get; set; } = false; + public int VideoQualityBitrate { get; set; } = 3000; public bool UseCustomArguments { get; set; } = false; public string CustomArguments { get; set; } = ""; @@ -81,54 +83,109 @@ public string GetFFmpegArgs() // Input file path args.Append($"-i \"{InputFilePath}\" "); - // Video codec + // Video encoder switch (VideoCodec) { case ConverterVideoCodecs.x264: // https://trac.ffmpeg.org/wiki/Encode/H.264 - args.Append($"-c:v libx264 -preset medium -crf {VideoQuality.Clamp(FFmpegCLIManager.x264_min, FFmpegCLIManager.x264_max)} "); - args.Append("-pix_fmt yuv420p -movflags +faststart "); // For browser support + args.Append("-c:v libx264 "); + args.Append("-preset medium "); + if (VideoQualityUseBitrate) + { + args.Append($"-b:v {VideoQualityBitrate}k "); + } + else + { + args.Append($"-crf {VideoQuality.Clamp(FFmpegCLIManager.x264_min, FFmpegCLIManager.x264_max)} "); + } + args.Append("-pix_fmt yuv420p "); + args.Append("-movflags +faststart "); break; case ConverterVideoCodecs.x265: // https://trac.ffmpeg.org/wiki/Encode/H.265 - args.Append($"-c:v libx265 -preset medium -crf {VideoQuality.Clamp(FFmpegCLIManager.x265_min, FFmpegCLIManager.x265_max)} "); + args.Append("-c:v libx265 "); + args.Append("-preset medium "); + if (VideoQualityUseBitrate) + { + args.Append($"-b:v {VideoQualityBitrate}k "); + } + else + { + args.Append($"-crf {VideoQuality.Clamp(FFmpegCLIManager.x265_min, FFmpegCLIManager.x265_max)} "); + } break; case ConverterVideoCodecs.vp8: // https://trac.ffmpeg.org/wiki/Encode/VP8 - args.Append($"-c:v libvpx -crf {VideoQuality.Clamp(FFmpegCLIManager.vp8_min, FFmpegCLIManager.vp8_max)} -b:v 0 "); + args.Append("-c:v libvpx "); + if (VideoQualityUseBitrate) + { + args.Append($"-b:v {VideoQualityBitrate}k "); + } + else + { + args.Append($"-crf {VideoQuality.Clamp(FFmpegCLIManager.vp8_min, FFmpegCLIManager.vp8_max)} "); + args.Append("-b:v 100M "); + } break; case ConverterVideoCodecs.vp9: // https://trac.ffmpeg.org/wiki/Encode/VP9 - args.Append($"-c:v libvpx-vp9 -crf {VideoQuality.Clamp(FFmpegCLIManager.vp9_min, FFmpegCLIManager.vp9_max)} -b:v 0 "); + args.Append("-c:v libvpx-vp9 "); + if (VideoQualityUseBitrate) + { + args.Append($"-b:v {VideoQualityBitrate}k "); + } + else + { + args.Append($"-crf {VideoQuality.Clamp(FFmpegCLIManager.vp9_min, FFmpegCLIManager.vp9_max)} "); + args.Append("-b:v 0 "); + } break; case ConverterVideoCodecs.xvid: // https://trac.ffmpeg.org/wiki/Encode/MPEG-4 - args.Append($"-c:v libxvid -q:v {VideoQuality.Clamp(FFmpegCLIManager.xvid_min, FFmpegCLIManager.xvid_max)} "); + args.Append("-c:v libxvid "); + if (VideoQualityUseBitrate) + { + args.Append($"-b:v {VideoQualityBitrate}k "); + } + else + { + args.Append($"-q:v {VideoQuality.Clamp(FFmpegCLIManager.xvid_min, FFmpegCLIManager.xvid_max)} "); + } break; case ConverterVideoCodecs.gif: // https://ffmpeg.org/ffmpeg-filters.html#palettegen-1 args.Append("-lavfi \"palettegen=stats_mode=full[palette],[0:v][palette]paletteuse=dither=sierra2_4a\" "); break; case ConverterVideoCodecs.webp: // https://www.ffmpeg.org/ffmpeg-codecs.html#libwebp - args.Append("-c:v libwebp -lossless 0 -preset default -loop 0 "); + args.Append("-c:v libwebp "); + args.Append("-lossless 0 "); + args.Append("-preset default "); + args.Append("-loop 0 "); break; case ConverterVideoCodecs.apng: - args.Append("-f apng -plays 0 "); + args.Append("-f apng "); + args.Append("-plays 0 "); break; } - // Audio codec + // Audio encoder switch (VideoCodec) { case ConverterVideoCodecs.x264: // https://trac.ffmpeg.org/wiki/Encode/AAC case ConverterVideoCodecs.x265: - args.Append("-c:a aac -b:a 128k "); + args.Append("-c:a aac "); + args.Append("-b:a 128k "); break; case ConverterVideoCodecs.vp8: // https://trac.ffmpeg.org/wiki/TheoraVorbisEncodingGuide case ConverterVideoCodecs.vp9: - args.Append("-c:a libvorbis -q:a 3 "); + args.Append("-c:a libvorbis "); + args.Append("-q:a 3 "); break; case ConverterVideoCodecs.xvid: // https://trac.ffmpeg.org/wiki/Encode/MP3 - args.Append("-c:a libmp3lame -q:a 4 "); + args.Append("-c:a libmp3lame "); + args.Append("-q:a 4 "); break; } + // Overwrite output files without asking + args.Append($"-y "); + // Output file path - args.Append($"-y \"{OutputFilePath}\""); + args.Append($"\"{OutputFilePath}\""); return args.ToString(); } diff --git a/ShareX.ScreenCaptureLib/Forms/StickerImageListViewRenderer.cs b/ShareX.ScreenCaptureLib/Helpers/StickerImageListViewRenderer.cs similarity index 100% rename from ShareX.ScreenCaptureLib/Forms/StickerImageListViewRenderer.cs rename to ShareX.ScreenCaptureLib/Helpers/StickerImageListViewRenderer.cs diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index 490dcc1a7..5220dabc0 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -145,7 +145,7 @@ StickerForm.cs - + Form