Compare commits
No commits in common. "master" and "1.0" have entirely different histories.
|
@ -30,11 +30,6 @@
|
|||
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
|
||||
|
@ -71,7 +66,7 @@
|
|||
//
|
||||
// linkLabel1
|
||||
//
|
||||
this.linkLabel1.Location = new System.Drawing.Point(315, 276);
|
||||
this.linkLabel1.Location = new System.Drawing.Point(314, 93);
|
||||
this.linkLabel1.Name = "linkLabel1";
|
||||
this.linkLabel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
|
||||
this.linkLabel1.Size = new System.Drawing.Size(284, 23);
|
||||
|
@ -90,50 +85,12 @@
|
|||
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, 307);
|
||||
this.Controls.Add(this.dataGridView1);
|
||||
this.Controls.Add(this.label1);
|
||||
this.ClientSize = new System.Drawing.Size(610, 125);
|
||||
this.Controls.Add(this.buttonContextMenu);
|
||||
this.Controls.Add(this.linkLabel1);
|
||||
this.Controls.Add(this.button2);
|
||||
|
@ -143,12 +100,10 @@
|
|||
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();
|
||||
}
|
||||
|
@ -156,12 +111,8 @@
|
|||
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
|
||||
|
|
135
Form1.cs
135
Form1.cs
|
@ -18,11 +18,6 @@ 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();
|
||||
|
@ -89,127 +84,43 @@ namespace CompressH265 {
|
|||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e) {
|
||||
var inputFilename = textBox1.Text;
|
||||
var shortName = Path.GetFileName(inputFilename);
|
||||
|
||||
if (inputFilename.Trim() == "") {
|
||||
if (textBox1.Text.Trim() == "") {
|
||||
MessageBox.Show("Please select or drag-and-drop a file.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(inputFilename)) {
|
||||
if (!File.Exists(textBox1.Text)) {
|
||||
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 = inputFilename + ".h265.mp4";
|
||||
var outputFilename = textBox1.Text + ".h265.mp4";
|
||||
|
||||
if (File.Exists(outputFilename)) {
|
||||
MessageBox.Show("The output file name is existing. Please move or delete it before converting. " + outputFilename);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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.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;
|
||||
|
||||
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.StartInfo.CreateNoWindow = true;
|
||||
|
||||
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--;
|
||||
System.Environment.Exit(1);
|
||||
};
|
||||
|
||||
runningProcessCount++;
|
||||
// process.OutputDataReceived += OnProcessOutput;
|
||||
// process.ErrorDataReceived += OnProcessOutput;
|
||||
process.Start();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
processList.AddLast(process);
|
||||
// process.BeginErrorReadLine();
|
||||
// process.BeginOutputReadLine();
|
||||
}
|
||||
|
||||
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 OnProcessOutput(object send, DataReceivedEventArgs args) {
|
||||
// textBox2.Text += args.Data;
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e) {
|
||||
|
@ -255,26 +166,12 @@ 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,10 +120,4 @@
|
|||
<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>
|
|
@ -1,9 +1,7 @@
|
|||
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;
|
||||
|
@ -17,12 +15,6 @@ 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)
|
||||
{
|
||||
|
|
|
@ -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.3.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.3.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -7,7 +7,7 @@ Compress or convert your video files to h.265 (hevc) format with one-click, make
|
|||
|
||||
# Download
|
||||
|
||||
https://gitea.ath.cx/zabpehely/lazy-compress-h265/releases
|
||||
https://github.com/louislam/lazy-compress-h265/releases
|
||||
|
||||
# Features
|
||||
|
||||
|
@ -16,7 +16,6 @@ https://gitea.ath.cx/zabpehely/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