Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace bitrate_res_changer
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- public bool stop = false;
- public Process running = new Process();
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void btnSearchIn_Click(object sender, EventArgs e)
- {
- DialogResult result = fbdInput.ShowDialog();
- if (result == DialogResult.OK)
- {
- string[] files = Directory.GetFiles(fbdInput.SelectedPath);
- tbInput.Text = fbdInput.SelectedPath;
- int num = files.Length;
- lbFiles.Items.Clear();
- foreach (string file in files)
- {
- lbFiles.Items.Add(file.Replace(fbdInput.SelectedPath + @"\", ""));
- }
- }
- }
- private void btnRemove_Click(object sender, EventArgs e)
- {
- lbFiles.Items.RemoveAt(lbFiles.SelectedIndex);
- }
- private void btnFilter_Click(object sender, EventArgs e)
- {
- List<string> list = new List<string>();
- foreach (string file in lbFiles.Items)
- {
- list.Add(file);
- }
- int i = 0;
- foreach (string file in list)
- {
- if (!file.EndsWith(tbFilter.Text))
- {
- lbFiles.Items.RemoveAt(i);
- continue;
- }
- i++;
- }
- }
- private void tbFilter_TextChanged(object sender, EventArgs e)
- {
- }
- private void btnReload_Click(object sender, EventArgs e)
- {
- if (!tbInput.Text.Equals(""))
- {
- string[] files = Directory.GetFiles(fbdInput.SelectedPath);
- tbInput.Text = fbdInput.SelectedPath;
- int num = files.Length;
- lbFiles.Items.Clear();
- foreach (string file in files)
- {
- lbFiles.Items.Add(file.Replace(fbdInput.SelectedPath + @"\", ""));
- }
- }
- }
- private void generate(string file_loc, string file, string output_name, string output_loc)
- {
- int v = 0;
- int a = 0;
- int vert = 0;
- int h = 0;
- int t = 0;
- this.Invoke(new Action(() => {
- v = (int)numVbitrate.Value;
- a = (int)numAbitrate.Value;
- vert = (int)numVertbitrate.Value;
- h = (int)numHbitrate.Value;
- t = (int)numThreads.Value;
- }));
- Process p = new Process();
- ProcessStartInfo startInfo = new ProcessStartInfo();
- startInfo.FileName = "cmd.exe";
- string arg = @"ffmpeg ";
- arg += @"-i """ + file_loc +@"\" + file + @""" ";
- if (vert != 0 || h != 0)
- {
- arg += @"-vf scale=" + h + ":" + vert + @" ";
- }
- if (v != 0 || a != 0)
- {
- arg += @"-b:v " + v + "k ";
- }
- arg += @"""" + output_loc + @"\" + output_name + @"""";
- if (t != 0)
- {
- arg += " -threads " + t + " ";
- }
- //MessageBox.Show(arg);
- startInfo.Arguments = @"/c " + arg;
- p.StartInfo = startInfo;
- p.Start();
- running = p;
- p.WaitForExit();
- }
- private void btn_Click(object sender, EventArgs e)
- {
- stop = false;
- foreach (object l in lbFiles.Items)
- {
- Thread d = new Thread(() => generate(tbInput.Text, l.ToString(), l.ToString(), tbOutput.Text));
- d.Start();
- tbStatus.Text += l.ToString() + " is now being processed." + Environment.NewLine + tbStatus.Text;
- do {
- if (stop)
- {
- running.Close();
- d.Abort();
- tbStatus.Text = "The process has been interrupted!" + Environment.NewLine + tbStatus.Text;
- MessageBox.Show("You will need to close any command prompts related to this program");
- return;
- }
- wait(1000);
- } while (d.IsAlive);
- tbStatus.Text = l.ToString() + " has finished being processed." + Environment.NewLine + tbStatus.Text;
- }
- }
- public static void wait(int milliseconds)
- {
- System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
- if (milliseconds == 0 || milliseconds < 0) return;
- timer1.Interval = milliseconds;
- timer1.Enabled = true;
- timer1.Start();
- timer1.Tick += (s, e) =>
- {
- timer1.Enabled = false;
- timer1.Stop();
- };
- while (timer1.Enabled)
- {
- Application.DoEvents();
- }
- }
- private void btnSearchOut_Click(object sender, EventArgs e)
- {
- DialogResult result = fbdOutput.ShowDialog();
- if (result == DialogResult.OK)
- {
- string[] files = Directory.GetFiles(fbdOutput.SelectedPath);
- tbOutput.Text = fbdOutput.SelectedPath;
- }
- }
- private void btnStop_Click(object sender, EventArgs e)
- {
- stop = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement