Advertisement
agentsix1

Untitled

Jul 3rd, 2022
1,958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13.  
  14. namespace bitrate_res_changer
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         public bool stop = false;
  24.         public Process running = new Process();
  25.  
  26.         private void Form1_Load(object sender, EventArgs e)
  27.         {
  28.            
  29.         }
  30.  
  31.         private void btnSearchIn_Click(object sender, EventArgs e)
  32.         {
  33.             DialogResult result = fbdInput.ShowDialog();
  34.             if (result == DialogResult.OK)
  35.             {
  36.                 string[] files = Directory.GetFiles(fbdInput.SelectedPath);
  37.                 tbInput.Text = fbdInput.SelectedPath;
  38.                 int num = files.Length;
  39.  
  40.                 lbFiles.Items.Clear();
  41.                 foreach (string file in files)
  42.                 {
  43.                     lbFiles.Items.Add(file.Replace(fbdInput.SelectedPath + @"\", ""));
  44.  
  45.                 }
  46.             }
  47.         }
  48.  
  49.         private void btnRemove_Click(object sender, EventArgs e)
  50.         {
  51.             lbFiles.Items.RemoveAt(lbFiles.SelectedIndex);
  52.         }
  53.  
  54.         private void btnFilter_Click(object sender, EventArgs e)
  55.         {
  56.             List<string> list = new List<string>();
  57.             foreach (string file in lbFiles.Items)
  58.             {
  59.                 list.Add(file);  
  60.             }
  61.             int i = 0;
  62.             foreach (string file in list)
  63.             {
  64.                 if (!file.EndsWith(tbFilter.Text))
  65.                 {
  66.                     lbFiles.Items.RemoveAt(i);
  67.                     continue;
  68.                 }
  69.                 i++;
  70.             }
  71.         }
  72.  
  73.         private void tbFilter_TextChanged(object sender, EventArgs e)
  74.         {
  75.  
  76.         }
  77.  
  78.         private void btnReload_Click(object sender, EventArgs e)
  79.         {
  80.             if (!tbInput.Text.Equals(""))
  81.             {
  82.                 string[] files = Directory.GetFiles(fbdInput.SelectedPath);
  83.                 tbInput.Text = fbdInput.SelectedPath;
  84.                 int num = files.Length;
  85.  
  86.                 lbFiles.Items.Clear();
  87.                 foreach (string file in files)
  88.                 {
  89.                     lbFiles.Items.Add(file.Replace(fbdInput.SelectedPath + @"\", ""));
  90.  
  91.                 }
  92.             }
  93.         }
  94.  
  95.         private void generate(string file_loc, string file, string output_name, string output_loc)
  96.         {
  97.  
  98.             int v = 0;
  99.             int a = 0;
  100.             int vert = 0;
  101.             int h = 0;
  102.             int t = 0;
  103.             this.Invoke(new Action(() => {
  104.                 v = (int)numVbitrate.Value;
  105.                 a = (int)numAbitrate.Value;
  106.                 vert = (int)numVertbitrate.Value;
  107.                 h = (int)numHbitrate.Value;
  108.                 t = (int)numThreads.Value;
  109.             }));
  110.             Process p = new Process();
  111.             ProcessStartInfo startInfo = new ProcessStartInfo();
  112.             startInfo.FileName = "cmd.exe";
  113.             string arg = @"ffmpeg ";
  114.             arg += @"-i """ + file_loc +@"\" + file + @""" ";
  115.             if (vert != 0 || h != 0)
  116.             {
  117.                 arg += @"-vf scale=" + h + ":" + vert + @" ";
  118.             }
  119.             if (v != 0 || a != 0)
  120.             {
  121.                 arg += @"-b:v " + v + "k ";
  122.             }
  123.             arg += @"""" + output_loc + @"\" + output_name + @"""";
  124.             if (t != 0)
  125.             {
  126.                 arg += " -threads " + t + " ";
  127.             }
  128.             //MessageBox.Show(arg);
  129.             startInfo.Arguments = @"/c " + arg;
  130.             p.StartInfo = startInfo;
  131.             p.Start();
  132.             running = p;
  133.             p.WaitForExit();
  134.         }
  135.  
  136.         private void btn_Click(object sender, EventArgs e)
  137.         {
  138.             stop = false;
  139.             foreach (object l in lbFiles.Items)
  140.             {
  141.                 Thread d = new Thread(() => generate(tbInput.Text, l.ToString(), l.ToString(), tbOutput.Text));
  142.                 d.Start();
  143.                 tbStatus.Text += l.ToString() + " is now being processed." + Environment.NewLine + tbStatus.Text;
  144.                 do {
  145.                     if (stop)
  146.                     {
  147.                         running.Close();
  148.                         d.Abort();
  149.                         tbStatus.Text = "The process has been interrupted!" + Environment.NewLine + tbStatus.Text;
  150.                         MessageBox.Show("You will need to close any command prompts related to this program");
  151.                         return;
  152.                     }
  153.                     wait(1000);
  154.                 } while (d.IsAlive);
  155.  
  156.                 tbStatus.Text = l.ToString() + " has finished being processed." + Environment.NewLine + tbStatus.Text;
  157.             }
  158.            
  159.         }
  160.  
  161.         public static void wait(int milliseconds)
  162.         {
  163.             System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
  164.             if (milliseconds == 0 || milliseconds < 0) return;
  165.             timer1.Interval = milliseconds;
  166.             timer1.Enabled = true;
  167.             timer1.Start();
  168.             timer1.Tick += (s, e) =>
  169.             {
  170.                 timer1.Enabled = false;
  171.                 timer1.Stop();
  172.             };
  173.             while (timer1.Enabled)
  174.             {
  175.                 Application.DoEvents();
  176.             }
  177.         }
  178.  
  179.         private void btnSearchOut_Click(object sender, EventArgs e)
  180.         {
  181.             DialogResult result = fbdOutput.ShowDialog();
  182.             if (result == DialogResult.OK)
  183.             {
  184.                 string[] files = Directory.GetFiles(fbdOutput.SelectedPath);
  185.                 tbOutput.Text = fbdOutput.SelectedPath;
  186.             }
  187.         }
  188.  
  189.         private void btnStop_Click(object sender, EventArgs e)
  190.         {
  191.             stop = true;
  192.         }
  193.     }
  194.    
  195. }
  196.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement