Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
zabpehely | 2dcfa5132b | |
LouisLam | ac63e215ff | |
LouisLam | d9b13cb1a7 | |
LouisLam | 01bbdde60c | |
LouisLam | a5cfc0e42d | |
LouisLam | 37c1e1b6bc | |
LouisLam | 31c292f7be |
|
@ -30,6 +30,11 @@
|
|||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
|
||||
this.buttonContextMenu = new System.Windows.Forms.Button();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
||||
this.FilePath = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Status = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize) (this.dataGridView1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// button1
|
||||
|
@ -66,7 +71,7 @@
|
|||
//
|
||||
// linkLabel1
|
||||
//
|
||||
this.linkLabel1.Location = new System.Drawing.Point(314, 93);
|
||||
this.linkLabel1.Location = new System.Drawing.Point(315, 276);
|
||||
this.linkLabel1.Name = "linkLabel1";
|
||||
this.linkLabel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
|
||||
this.linkLabel1.Size = new System.Drawing.Size(284, 23);
|
||||
|
@ -85,12 +90,50 @@
|
|||
this.buttonContextMenu.UseVisualStyleBackColor = true;
|
||||
this.buttonContextMenu.Click += new System.EventHandler(this.button3_Click);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Location = new System.Drawing.Point(12, 99);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(100, 23);
|
||||
this.label1.TabIndex = 7;
|
||||
this.label1.Text = "Task List";
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
this.dataGridView1.AllowUserToAddRows = false;
|
||||
this.dataGridView1.AllowUserToDeleteRows = false;
|
||||
this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.FilePath, this.Status});
|
||||
this.dataGridView1.Location = new System.Drawing.Point(12, 120);
|
||||
this.dataGridView1.Name = "dataGridView1";
|
||||
this.dataGridView1.ReadOnly = true;
|
||||
this.dataGridView1.RowTemplate.Height = 24;
|
||||
this.dataGridView1.Size = new System.Drawing.Size(586, 141);
|
||||
this.dataGridView1.TabIndex = 8;
|
||||
//
|
||||
// FilePath
|
||||
//
|
||||
this.FilePath.HeaderText = "File Path";
|
||||
this.FilePath.Name = "FilePath";
|
||||
this.FilePath.ReadOnly = true;
|
||||
this.FilePath.Width = 272;
|
||||
//
|
||||
// Status
|
||||
//
|
||||
this.Status.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||
this.Status.HeaderText = "Status";
|
||||
this.Status.Name = "Status";
|
||||
this.Status.ReadOnly = true;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.ClientSize = new System.Drawing.Size(610, 125);
|
||||
this.ClientSize = new System.Drawing.Size(610, 307);
|
||||
this.Controls.Add(this.dataGridView1);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.buttonContextMenu);
|
||||
this.Controls.Add(this.linkLabel1);
|
||||
this.Controls.Add(this.button2);
|
||||
|
@ -100,10 +143,12 @@
|
|||
this.Name = "Form1";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Lazy Compress H.265 (HEVC)";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
|
||||
this.Load += new System.EventHandler(this.Form1_Load);
|
||||
this.Shown += new System.EventHandler(this.Form1_Shown);
|
||||
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
|
||||
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter);
|
||||
((System.ComponentModel.ISupportInitialize) (this.dataGridView1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
}
|
||||
|
@ -111,8 +156,12 @@
|
|||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button buttonContextMenu;
|
||||
private System.Windows.Forms.DataGridView dataGridView1;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn FilePath;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.LinkLabel linkLabel1;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog1;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn Status;
|
||||
private System.Windows.Forms.TextBox textBox1;
|
||||
|
||||
#endregion
|
||||
|
|
143
Form1.cs
143
Form1.cs
|
@ -18,6 +18,11 @@ namespace CompressH265 {
|
|||
|
||||
private bool isFromContextMenu = false;
|
||||
private bool installed = false;
|
||||
private int nextTaskID = 0;
|
||||
|
||||
private int runningProcessCount = 0;
|
||||
|
||||
private LinkedList<Process> processList = new LinkedList<Process>();
|
||||
|
||||
public Form1() {
|
||||
InitializeComponent();
|
||||
|
@ -84,43 +89,127 @@ namespace CompressH265 {
|
|||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e) {
|
||||
|
||||
if (textBox1.Text.Trim() == "") {
|
||||
var inputFilename = textBox1.Text;
|
||||
var shortName = Path.GetFileName(inputFilename);
|
||||
|
||||
if (inputFilename.Trim() == "") {
|
||||
MessageBox.Show("Please select or drag-and-drop a file.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(textBox1.Text)) {
|
||||
if (!File.Exists(inputFilename)) {
|
||||
MessageBox.Show("File Not Found");
|
||||
return;
|
||||
}
|
||||
|
||||
var creationTime = File.GetCreationTime(inputFilename);
|
||||
var lastAccessTime = File.GetLastAccessTime(inputFilename);
|
||||
var lastWriteTime = File.GetLastWriteTime(inputFilename);
|
||||
|
||||
Process process = new Process();
|
||||
process.EnableRaisingEvents = true;
|
||||
// process.StartInfo.RedirectStandardOutput = true;
|
||||
// process.StartInfo.RedirectStandardError = true;
|
||||
|
||||
var outputFilename = textBox1.Text + ".h265.mp4";
|
||||
var outputFilename = inputFilename + ".h265.mp4";
|
||||
|
||||
if (File.Exists(outputFilename)) {
|
||||
MessageBox.Show("The output file name is existing. Please move or delete it before converting. " + outputFilename);
|
||||
return;
|
||||
}
|
||||
|
||||
process.StartInfo.FileName = "cmd.exe";
|
||||
process.StartInfo.Arguments = $"/K ffmpeg.exe -i \"{textBox1.Text}\" -vcodec hevc -map_metadata 0 \"{outputFilename}\"";
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
// process.StartInfo.CreateNoWindow = true;
|
||||
// Get FPS
|
||||
var fps = GetFPS(inputFilename);
|
||||
var fpsParam = "";
|
||||
|
||||
process.Exited += (sender2, e2) => {
|
||||
System.Environment.Exit(1);
|
||||
if (fps > 0) {
|
||||
fpsParam = "-r " + fps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Converting
|
||||
process.StartInfo.FileName = "ffmpeg.exe";
|
||||
process.StartInfo.Arguments = $" -i \"{inputFilename}\" -vcodec hevc -map_metadata 0 -vf yadif -crf 20 -preset medium {fpsParam} \"{outputFilename}\"";
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
|
||||
MessageBox.Show(process.StartInfo.Arguments);
|
||||
|
||||
var rowID = nextTaskID++;
|
||||
var msgQueue = new Queue<string>();
|
||||
dataGridView1.Rows.Insert(rowID, shortName, "Preparing...");
|
||||
var row = dataGridView1.Rows[rowID];
|
||||
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.ErrorDataReceived += (errorEvent,errorArgs) => {
|
||||
if (errorArgs.Data == null || errorArgs.Data.Trim() == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
msgQueue.Enqueue(errorArgs.Data);
|
||||
|
||||
if (msgQueue.Count == 5) {
|
||||
msgQueue.Dequeue();
|
||||
}
|
||||
|
||||
row.Cells[1].Value = String.Join(" | ", msgQueue.Reverse());
|
||||
};
|
||||
|
||||
// process.OutputDataReceived += OnProcessOutput;
|
||||
// process.ErrorDataReceived += OnProcessOutput;
|
||||
process.Exited += (sender2, e2) => {
|
||||
|
||||
if (File.Exists(outputFilename)) {
|
||||
File.SetCreationTime(outputFilename, creationTime);
|
||||
File.SetLastAccessTime(outputFilename, lastAccessTime);
|
||||
File.SetLastWriteTime(outputFilename, lastWriteTime);
|
||||
}
|
||||
|
||||
msgQueue.Enqueue("Finish");
|
||||
row.Cells[1].Value = String.Join(" | ", msgQueue.Reverse());
|
||||
|
||||
if (isFromContextMenu) {
|
||||
//System.Environment.Exit(1);
|
||||
}
|
||||
|
||||
runningProcessCount--;
|
||||
};
|
||||
|
||||
runningProcessCount++;
|
||||
process.Start();
|
||||
|
||||
// process.BeginErrorReadLine();
|
||||
// process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
processList.AddLast(process);
|
||||
}
|
||||
|
||||
private void OnProcessOutput(object send, DataReceivedEventArgs args) {
|
||||
// textBox2.Text += args.Data;
|
||||
private float GetFPS(string inputFilename) {
|
||||
Process process = new Process();
|
||||
process.StartInfo.FileName = "ffmpeg.exe";
|
||||
process.StartInfo.Arguments = $"-i \"{inputFilename}\"";
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
string err = process.StandardError.ReadToEnd();
|
||||
|
||||
var end = err.IndexOf(" fps,");
|
||||
|
||||
if (end < 0) {
|
||||
return -1f;
|
||||
}
|
||||
|
||||
var start = end;
|
||||
|
||||
while (true) {
|
||||
if (err[start - 1] == ' ') {
|
||||
break;
|
||||
}
|
||||
start--;
|
||||
|
||||
if (start < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return float.Parse(err.Substring(start, end - start));
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e) {
|
||||
|
@ -166,12 +255,26 @@ namespace CompressH265 {
|
|||
|
||||
private void Form1_Shown(object sender, EventArgs e) {
|
||||
if (isFromContextMenu) {
|
||||
Hide();
|
||||
//Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
|
||||
System.Diagnostics.Process.Start("https://github.com/louislam/lazy-compress-h265");
|
||||
}
|
||||
|
||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
|
||||
if (runningProcessCount > 0) {
|
||||
var result = MessageBox.Show("Are you sure want to stop the processing?", "Stop process", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
if (result == DialogResult.Yes) {
|
||||
foreach (var p in processList) {
|
||||
p.Kill();
|
||||
}
|
||||
} else {
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -120,4 +120,10 @@
|
|||
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>23, 17</value>
|
||||
</metadata>
|
||||
<metadata name="FilePath.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Status.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
10
Program.cs
10
Program.cs
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
@ -15,7 +17,13 @@ namespace CompressH265 {
|
|||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main(string[] args) {
|
||||
|
||||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
|
||||
if (path != null) {
|
||||
Environment.CurrentDirectory = path;
|
||||
}
|
||||
|
||||
|
||||
foreach(var item in args)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||
// 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("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.3.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.3.0.0")]
|
|
@ -7,7 +7,7 @@ Compress or convert your video files to h.265 (hevc) format with one-click, make
|
|||
|
||||
# Download
|
||||
|
||||
https://github.com/louislam/lazy-compress-h265/releases
|
||||
https://gitea.ath.cx/zabpehely/lazy-compress-h265/releases
|
||||
|
||||
# Features
|
||||
|
||||
|
@ -16,6 +16,7 @@ https://github.com/louislam/lazy-compress-h265/releases
|
|||
* No config is required
|
||||
* Easy to use, drag-and-drop and compress
|
||||
* Alternative, you could install to your Context Menu, one-click to compress
|
||||
* Keep metadata, date created and date modified.
|
||||
* Output to the same folder with postfix ".h265.mp4"
|
||||
* Portable
|
||||
|
||||
|
|
Loading…
Reference in New Issue