Skip to content

Commit

Permalink
chages for 3.39.0
Browse files Browse the repository at this point in the history
* Add in caption filter crop zone when it exist previously
* Improve preview performance
* Improve shadow under dynamic points
* Refactor rotate filter to ffmpeg commands
* Update ffmpeg to v6.1
  • Loading branch information
argorar committed May 4, 2024
1 parent c484a35 commit 7f63414
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 38 deletions.
Binary file modified Binaries/Win64/ffmpeg.exe
Binary file not shown.
12 changes: 6 additions & 6 deletions Components/PreviewFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public RotateFlipType RotateFlip
set { rotateFlipType = value; GeneratePreview(); }
}



public PreviewFrame()
{
if (Program.VideoSource != null)
Expand All @@ -46,11 +44,16 @@ public PreviewFrame()

frame = Program.VideoSource.GetFrame((int)framenumber);

if (frame.EncodedResolution.Width * frame.EncodedResolution.Height > 2073600) // 1080p (1920*1080)
if (frame.EncodedResolution.Width * frame.EncodedResolution.Height >= 2073600) // 1080p (1920*1080)
{
encodeW = frame.EncodedResolution.Width / 2;
encodeH = frame.EncodedResolution.Height / 2;
}
else if (frame.EncodedResolution.Width * frame.EncodedResolution.Height >= 8294400)
{
encodeW = frame.EncodedResolution.Width / 4;
encodeH = frame.EncodedResolution.Height / 4;
}
else
{
encodeW = frame.EncodedResolution.Width;
Expand Down Expand Up @@ -94,7 +97,6 @@ private int FixValue(int number)

public void GeneratePreview(bool force)
{

if (Program.VideoSource == null)
return;

Expand All @@ -105,7 +107,6 @@ public void GeneratePreview(bool force)
{
Picture.BackgroundImage = MainForm.cache[(int)framenumber];
Picture.ClientSize = new Size(width, height);
Picture.Refresh();
SetPadding();
return;
}
Expand Down Expand Up @@ -136,7 +137,6 @@ public void GeneratePreview(bool force)
MainForm.cache.TryAdd((int)framenumber, (Bitmap)destImage.Clone());

Picture.BackgroundImage = destImage;
Picture.Refresh();
SetPadding();
cachedframenumber = (int)framenumber;
}
Expand Down
39 changes: 38 additions & 1 deletion Filters/Caption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,35 @@ public partial class CaptionForm : Form
Size videoResolution;
Point held;
Point beforeheld;
private RectangleF cropPercent;

public CaptionForm()
{
InitializeComponent();
SetFrameRange();
SetEvents();
SetCrop();
}

public CaptionForm(CaptionFilter filterToEdit)
{
InitializeComponent();

SetFrameRange();

SetCrop();
numericStartFrame.Value = filterToEdit.Start;
numericEndFrame.Value = filterToEdit.End;
InputFilter = filterToEdit;

SetEvents();
}

private void SetCrop()
{
if (Filters.Crop != null)
cropPercent = Filters.Crop.cropPercent;
}

private void SetFrameRange()
{
numericStartFrame.Maximum = Program.VideoSource.NumberOfFrames;
Expand All @@ -48,6 +56,7 @@ private void SetFrameRange()
private void SetEvents()
{
previewFrame.Picture.Paint += new PaintEventHandler(this.previewPicture_Paint);
previewFrame.Picture.Paint += new PaintEventHandler(this.previewPicture_Crop);
previewFrame.Picture.MouseDown += new MouseEventHandler(this.previewPicture_MouseDown);
previewFrame.Picture.MouseMove += new MouseEventHandler(this.previewPicture_MouseMove);
}
Expand Down Expand Up @@ -119,6 +128,34 @@ void previewPicture_Paint(object sender, PaintEventArgs e)
g.DrawPath(new Pen(new SolidBrush(colorDialogBorderColor.Color), (float)numericBorderThickness.Value * scale), path);
}

private void previewPicture_Crop(object sender, PaintEventArgs e)
{
if (Filters.Crop == null)
return;

var g = e.Graphics;
var edgePen = new Pen(Color.White, 1f);
var dotBrush = new SolidBrush(Color.White);
var outsideBrush = new HatchBrush(HatchStyle.Percent50, Color.Transparent);

var maxW = previewFrame.Picture.Width;
var maxH = previewFrame.Picture.Height;
var x = cropPercent.X * previewFrame.Picture.Width;
var y = cropPercent.Y * previewFrame.Picture.Height;
var w = cropPercent.Width * maxW;
var h = cropPercent.Height * maxH;

//Darken background
g.FillRectangle(outsideBrush, 0, 0, maxW, y);
g.FillRectangle(outsideBrush, 0, y, x, h);
g.FillRectangle(outsideBrush, x + w, y, maxW - (x + w), h);
g.FillRectangle(outsideBrush, 0, y + h, maxW, maxH);

//Edge
g.DrawRectangle(edgePen, x, y, w, h);

}

void previewPicture_MouseDown(object sender, MouseEventArgs e)
{
held = e.Location;
Expand Down
28 changes: 25 additions & 3 deletions Filters/Crop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public partial class CropForm : Form
private RectangleF cropPercent;
private int currentFrame;
private IDictionary<int, CropPoint> cropsList = new Dictionary<int, CropPoint>();
private bool open = true;
private enum Corner
{
TopLeft,
Expand Down Expand Up @@ -53,6 +54,18 @@ public CropForm()
SetEvents();
}

private void LoadDynamicCrop()
{
if (Filters.DynamicCrop != null)
{
open = false;
dynamicCropActive.Checked = true;
cropsList = Filters.DynamicCrop.crops;
cropPercent = Filters.DynamicCrop.cropArea;
open = true;
}
}

private void SetEvents()
{
trackVideoTimeline.Maximum = Program.VideoSource.NumberOfFrames - 1;
Expand Down Expand Up @@ -99,6 +112,7 @@ void CropForm_Load(object sender, EventArgs e)
trackVideoTimeline.Maximum = Filters.MultipleTrim.Trims[Filters.MultipleTrim.Trims.Count - 1].TrimEnd;
trimTimingToolStripMenuItem.Enabled = true;
}
LoadDynamicCrop();
}

private void previewPicture_MouseDown(object sender, MouseEventArgs e)
Expand Down Expand Up @@ -378,7 +392,7 @@ private void AddCropPan(int width, int height)

private void GenerateFilter(IDictionary<int, CropPoint> cropsList)
{
GeneratedCropPanFilter = new DynamicCropFilter(cropsList, trackVideoTimeline.Maximum);
GeneratedCropPanFilter = new DynamicCropFilter(cropsList, trackVideoTimeline.Maximum, cropPercent);
}
private void GenerateFilter(int width, int height)
{
Expand Down Expand Up @@ -709,7 +723,9 @@ private void dynamicCropActive_CheckedChanged(object sender, EventArgs e)
{
dynamicCropActive.ForeColor = dynamicCropActive.Checked ? Color.Green : Color.Black;

if (newHeight == 0 && dynamicCropActive.Checked)
cropBars.Enabled = dynamicCropActive.Checked ? false : true;

if (newHeight == 0 && dynamicCropActive.Checked && open)
ShowNewDimension();
}

Expand All @@ -719,10 +735,12 @@ private void cropBars_CheckedChanged(object sender, EventArgs e)
if (cropBars.Checked)
{
Filters.CropBarsFilter = new CropBarsFilter();
dynamicCropActive.Enabled = false;
}
else
{
Filters.CropBarsFilter = null;
dynamicCropActive.Enabled = true;
}

}
Expand Down Expand Up @@ -767,9 +785,13 @@ public CropFilter(int left, int top, int right, int bottom, RectangleF cropPerce
public class DynamicCropFilter
{
private readonly string cropFilter;
public IDictionary<int, CropPoint> crops { get; }
public RectangleF cropArea { get; }

public DynamicCropFilter(IDictionary<int, CropPoint> cropsList, int maximum)
public DynamicCropFilter(IDictionary<int, CropPoint> cropsList, int maximum, RectangleF cropPercent)
{
cropArea = cropPercent;
crops = cropsList;
List<KeyValuePair<int, CropPoint>> listCrops = cropsList.ToList();
string crop = listCrops[0].Value.Crop;
string easeType = "easeInOutSine";
Expand Down
20 changes: 14 additions & 6 deletions Filters/Dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections;
using WebMConverter.Objects;
using System.Text;
using System.Collections.Generic;

namespace WebMConverter
{
Expand Down Expand Up @@ -117,23 +118,30 @@ private void previewPicture_Paint(object sender, PaintEventArgs e)
var g = e.Graphics;
var edgePen = new Pen(Color.White, 2f);
var dotBrush = new SolidBrush(Color.Red);
var outsideBrush = new HatchBrush(HatchStyle.Percent80, Color.Transparent);

g.FillRectangle(outsideBrush, 0, 0, previewFrame.Size.Width, previewFrame.Size.Height);
var outsideBrush = new HatchBrush(HatchStyle.Percent70, Color.Transparent);

PointF[] drawPoints = new PointF[points.Count];

var h = previewFrame.Picture.Size.Height;
var w = previewFrame.Picture.Size.Width;
List<PointF> polygon = new List<PointF>();
polygon.Add(new PointF(0, h));

for (int i = 0; i < points.Count; i++)
{
SpeedPoint point = (SpeedPoint)points.GetByIndex(i);
int keyFrame = (int)points.GetKey(i);

drawPoints[i] = new PointF(((((float)keyFrame - trimStart) * 100) / (trimEnd - trimStart)) / 100 * w , (h * (1 - (float)point.Speed)) / 2 + h / 2);
float x = ((((float)keyFrame - trimStart) * 100) / (trimEnd - trimStart)) / 100 * w;
float y = (h * (1 - (float)point.Speed)) / 2 + h / 2;
var pointF = new PointF(x, y);
drawPoints[i] = pointF;
polygon.Add(pointF);
}


polygon.Add(new PointF( w, h));
polygon.Add(new PointF(0, h));

g.FillPolygon(outsideBrush, polygon.ToArray());
g.DrawLines(edgePen, drawPoints);

float diameter = 6;
Expand Down
10 changes: 5 additions & 5 deletions Filters/RotateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,24 @@ public override string ToString()
command = "";
break;
case RotateMode.Right:
command = "TurnRight() ";
command = "transpose=1";
break;
case RotateMode.Twice:
command = "TurnRight() TurnRight() ";
command = "transpose=2";
break;
case RotateMode.Left:
command = "TurnLeft() ";
command = "transpose=3";
break;
}

if (FlipHorizontal)
{
command += "FlipHorizontal() ";
command += ", hflip";
}

if (FlipVertical)
{
command += "FlipVertical()";
command += ", vflip";
}

return command;
Expand Down
1 change: 1 addition & 0 deletions Filters/Trim.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using WebMConverter.Dialogs;
Expand Down
38 changes: 23 additions & 15 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,16 +1058,11 @@ void buttonRotate_Click(object sender, EventArgs e)
{
if (form.ShowDialog(this) == DialogResult.OK)
{
if (boxAdvancedScripting.Checked)
{
textBoxProcessingScript.AppendText(Environment.NewLine + form.GeneratedFilter);
}
else
{
Filters.Rotate = form.GeneratedFilter;
listViewProcessingScript.Items.Add("Rotate", "rotate");
(sender as ToolStripItem).Enabled = false;
}

Filters.Rotate = form.GeneratedFilter;
listViewProcessingScript.Items.Add("Rotate", "rotate");
(sender as ToolStripItem).Enabled = false;
UpdateArguments(sender, e);
}
}
}
Expand Down Expand Up @@ -1240,6 +1235,7 @@ void listViewProcessingScript_ItemActivate(object sender, EventArgs e)
if (form.ShowDialog(this) == DialogResult.OK)
{
Filters.Rotate = form.GeneratedFilter;
UpdateArguments(sender, e);
}
}
break;
Expand Down Expand Up @@ -2223,7 +2219,9 @@ void Preview()
string avsFileName = GetTemporaryFile();
WriteAvisynthScript(avsFileName, input);

List<string> listVF = new List<string>();
string levels = string.Empty;

switch (comboLevels.SelectedIndex)
{
case 1:
Expand All @@ -2237,11 +2235,20 @@ void Preview()
break;
}

if (!string.IsNullOrEmpty(levels))
levels = " -vf " + levels;
if (!String.IsNullOrEmpty(levels))
listVF.Add(levels);

if (Filters.Rotate != null)
listVF.Add(Filters.Rotate.ToString());

string filter = string.Empty;

if (listVF.Count > 0)
filter = $" -vf \"{UnionVF(listVF)}\"";

var disableAudio = boxAudio.Checked ? "" : "-an";
var ffplay = new FFplay($@"-window_title Preview -loop 0 -f avisynth -v error {disableAudio}{levels} ""{avsFileName}""");
var a = $@"-window_title Preview -loop 0 -f avisynth -v error {disableAudio} {filter} ""{avsFileName}""";
var ffplay = new FFplay($@"-window_title Preview -loop 0 -f avisynth -v error {disableAudio} {filter} ""{avsFileName}""");
ffplay.Exited += delegate
{
string error = ffplay.ErrorLog;
Expand Down Expand Up @@ -2505,6 +2512,9 @@ string GenerateArguments()
if (!String.IsNullOrEmpty(textBoxdB.Text) && boxAudio.Checked)
audioFilter = $" -filter:a \"volume={textBoxdB.Text}dB\" ";

if (Filters.Rotate != null)
listVF.Add(Filters.Rotate.ToString());

string filter = string.Empty;

if(listVF.Count > 0)
Expand Down Expand Up @@ -2646,8 +2656,6 @@ void GenerateAvisynthScript()
script.AppendLine(Filters.Reverse.ToString());
if (Filters.Fade != null)
script.AppendLine(Filters.Fade.ToString());
if (Filters.Rotate != null)
script.AppendLine(Filters.Rotate.ToString());
if (Filters.DelayAudio != null)
script.AppendLine(Filters.DelayAudio.ToString());
if (Filters.CropBarsFilter != null)
Expand Down
Binary file added NewUpdate/3.39.0.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion NewUpdate/latest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.38.0
3.39.0
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.38.0")]
[assembly: AssemblyVersion("3.39.0")]
Loading

0 comments on commit 7f63414

Please sign in to comment.