Compare commits

..

7 Commits
1.0 ... master

Author SHA1 Message Date
zabpehely 2dcfa5132b Update README.md 2024-01-28 20:19:01 +01:00
LouisLam ac63e215ff fix drop frame rate 2020-05-16 20:37:12 +08:00
LouisLam d9b13cb1a7 fix drop frame rate 2020-05-16 20:36:47 +08:00
LouisLam 01bbdde60c update version 2020-05-11 00:45:17 +08:00
LouisLam a5cfc0e42d increase quality to almost lossless 2020-05-11 00:37:18 +08:00
LouisLam 37c1e1b6bc close ffmpeg and improve quality 2020-05-10 19:57:59 +08:00
LouisLam 31c292f7be add task list, carry created/modified date to new file 2020-05-10 19:27:39 +08:00
6 changed files with 193 additions and 26 deletions

53
Form1.Designer.cs generated
View File

@ -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

149
Form1.cs
View File

@ -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) {
var inputFilename = textBox1.Text;
var shortName = Path.GetFileName(inputFilename);
if (textBox1.Text.Trim() == "") {
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";
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;
process.Exited += (sender2, e2) => {
System.Environment.Exit(1);
};
// process.OutputDataReceived += OnProcessOutput;
// process.ErrorDataReceived += OnProcessOutput;
process.Start();
// process.BeginErrorReadLine();
// process.BeginOutputReadLine();
if (File.Exists(outputFilename)) {
MessageBox.Show("The output file name is existing. Please move or delete it before converting. " + outputFilename);
return;
}
private void OnProcessOutput(object send, DataReceivedEventArgs args) {
// textBox2.Text += args.Data;
// Get FPS
var fps = GetFPS(inputFilename);
var fpsParam = "";
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.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();
processList.AddLast(process);
}
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;
}
}
}
}
}

View File

@ -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>

View File

@ -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,6 +17,12 @@ 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)
{

View File

@ -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")]

View File

@ -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