<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebMConverter
{
    public partial class MainForm : Form
    {
        private string _template;
        public MainForm()
        {
            InitializeComponent();

            _template = "{1} -i \"{0}\" {2} -c:v libvpx {3} -crf 32 -b:v {4}K {5} -threads 0 {6} \"{7}\"";
            //{0} is input file
            //{1} is -ss TIME if seek enabled otherwise blank
            //{2} is -to TIME if to enabled otherwise blank
            //{3} is -an if no audio otherwise blank
            //{4} is bitrate in kb/s
            //{5} is -vf scale=WIDTH:HEIGHT if set otherwise blank
            //{6} is -fs 3M if 3MB limit enabled otherwise blank
            //{7} is output file

        }

        private void buttonBrowseIn_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.CheckFileExists = true;
            dialog.CheckPathExists = true;
            dialog.ValidateNames = true;

            if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.FileName))
                textBoxIn.Text = dialog.FileName;
        }

        private void buttonBrowseOut_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.OverwritePrompt = true;
            dialog.ValidateNames = true;
            dialog.Filter = "WebM files|*.webm";

            if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.FileName))
                textBoxOut.Text = dialog.FileName;
        }

        private void buttonGo_Click(object sender, EventArgs e)
        {
            string result = Go();
            if (!string.IsNullOrWhiteSpace(result))
                MessageBox.Show(result, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }

        private string Go()
        {
            string input = textBoxIn.Text;
            string output = textBoxOut.Text;

            if (string.IsNullOrWhiteSpace(input))
                return "No input file!";
            if (string.IsNullOrWhiteSpace(output))
                return "No output file!";


            int width = 0;
            int height = 0;

            if (!string.IsNullOrWhiteSpace(boxResW.Text) || !string.IsNullOrWhiteSpace(boxResH.Text))
            {
                if (!int.TryParse(boxResW.Text, out width))
                    return "Invalid width!";
                if (!int.TryParse(boxResH.Text, out height))
                    return "Invalid height!";
            }

            if ((!string.IsNullOrWhiteSpace(boxResW.Text) && string.IsNullOrWhiteSpace(boxResH.Text)) ||
                (string.IsNullOrWhiteSpace(boxResW.Text) && !string.IsNullOrWhiteSpace(boxResH.Text)))
                return "One of the width/height fields isn't filled in! Either fill none of them, or both of them!";


            //Try fo figure out if begin/end are correct
            //1. if it contains a :, it's probably a time, try to convert using DateTime.Parse
            //2. if not, try int.tryparse

            string start = "";
            string end = "";

            if (!string.IsNullOrWhiteSpace(boxCropFrom.Text))
            {
                start = "-ss " + boxCropFrom.Text.Trim();
                if (boxCropFrom.Text.Contains(":"))
                {
                    TimeSpan time;
                    if (!TimeSpan.TryParse(boxCropFrom.Text, out time))
                        return "Invalid start crop time!";
                }
                else
                {
                    uint integer;
                    if (!uint.TryParse(boxCropFrom.Text, out integer))
                        return "Invalid start crop time!";
                }
            }

            float duration = 0;

            if (!string.IsNullOrWhiteSpace(boxCropTo.Text))
            {
                end = "-to " + boxCropTo.Text.Trim();
                if (boxCropTo.Text.Contains(":"))
                {
                    TimeSpan time;
                    if (!TimeSpan.TryParse(boxCropTo.Text, out time))
                        return "Invalid end crop time!";
                    duration = (float)time.TotalSeconds;
                }
                else
                {
                    uint integer;
                    if (!uint.TryParse(boxCropTo.Text, out integer))
                        return "Invalid end crop time!";
                    duration = integer;
                }
            }

            /*if (string.IsNullOrWhiteSpace(start) && !string.IsNullOrWhiteSpace(end) ||
                !string.IsNullOrWhiteSpace(start) && string.IsNullOrWhiteSpace(end))
                return "One of the crop time fields is empty! Either empty them both, or fill them both.";*/

            float limit = 0;
            string limitTo = "";
            if (!string.IsNullOrWhiteSpace(boxLimit.Text))
            {
                if (!float.TryParse(boxLimit.Text, out limit))
                    return "Invalid size limit!";
                limitTo = string.Format("-fs {0}M", limit.ToString(System.Globalization.CultureInfo.InvariantCulture)); //Should turn comma into dot
            }

            string size = "";
            if (width != 0 && height != 0)
                size = string.Format("-vf scale={0}:{1}", width, height);

            //Calculate bitrate yourself!
            //1 megabyte = 8192 kilobits
            //3 megabytes = 24576 kilobits -> this is the limit
            //So if you have 60 seconds, the bitrate should be...
            //24576/60 = 409.6 kilobits/sec

            int bitrate = 300;
            if (duration != 0 && limit != 0) bitrate = (int)(8192 * limit / duration);

            if (!string.IsNullOrWhiteSpace(boxBitrate.Text))
                if (!int.TryParse(boxBitrate.Text, out bitrate))
                    return "Invalid bitrate!";

            string audio = "";
            if (!checkBoxAudio.Checked) //Remember, if the box ISN'T checked, the tag gets added
                audio = "-an";

            string arguments = string.Format(_template, input, start, end, audio, bitrate, size, limitTo, output);
            var form = new ConverterForm(arguments);
            form.ShowDialog();

            return null;
        }
    }
}
<commit_msg>Tripled default bitrate<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebMConverter
{
    public partial class MainForm : Form
    {
        private string _template;
        public MainForm()
        {
            InitializeComponent();

            _template = "{1} -i \"{0}\" {2} -c:v libvpx {3} -crf 32 -b:v {4}K {5} -threads 0 {6} \"{7}\"";
            //{0} is input file
            //{1} is -ss TIME if seek enabled otherwise blank
            //{2} is -to TIME if to enabled otherwise blank
            //{3} is -an if no audio otherwise blank
            //{4} is bitrate in kb/s
            //{5} is -vf scale=WIDTH:HEIGHT if set otherwise blank
            //{6} is -fs 3M if 3MB limit enabled otherwise blank
            //{7} is output file

        }

        private void buttonBrowseIn_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.CheckFileExists = true;
            dialog.CheckPathExists = true;
            dialog.ValidateNames = true;

            if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.FileName))
                textBoxIn.Text = dialog.FileName;
        }

        private void buttonBrowseOut_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.OverwritePrompt = true;
            dialog.ValidateNames = true;
            dialog.Filter = "WebM files|*.webm";

            if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.FileName))
                textBoxOut.Text = dialog.FileName;
        }

        private void buttonGo_Click(object sender, EventArgs e)
        {
            string result = Go();
            if (!string.IsNullOrWhiteSpace(result))
                MessageBox.Show(result, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }

        private string Go()
        {
            string input = textBoxIn.Text;
            string output = textBoxOut.Text;

            if (string.IsNullOrWhiteSpace(input))
                return "No input file!";
            if (string.IsNullOrWhiteSpace(output))
                return "No output file!";


            int width = 0;
            int height = 0;

            if (!string.IsNullOrWhiteSpace(boxResW.Text) || !string.IsNullOrWhiteSpace(boxResH.Text))
            {
                if (!int.TryParse(boxResW.Text, out width))
                    return "Invalid width!";
                if (!int.TryParse(boxResH.Text, out height))
                    return "Invalid height!";
            }

            if ((!string.IsNullOrWhiteSpace(boxResW.Text) && string.IsNullOrWhiteSpace(boxResH.Text)) ||
                (string.IsNullOrWhiteSpace(boxResW.Text) && !string.IsNullOrWhiteSpace(boxResH.Text)))
                return "One of the width/height fields isn't filled in! Either fill none of them, or both of them!";


            //Try fo figure out if begin/end are correct
            //1. if it contains a :, it's probably a time, try to convert using DateTime.Parse
            //2. if not, try int.tryparse

            string start = "";
            string end = "";

            if (!string.IsNullOrWhiteSpace(boxCropFrom.Text))
            {
                start = "-ss " + boxCropFrom.Text.Trim();
                if (boxCropFrom.Text.Contains(":"))
                {
                    TimeSpan time;
                    if (!TimeSpan.TryParse(boxCropFrom.Text, out time))
                        return "Invalid start crop time!";
                }
                else
                {
                    uint integer;
                    if (!uint.TryParse(boxCropFrom.Text, out integer))
                        return "Invalid start crop time!";
                }
            }

            float duration = 0;

            if (!string.IsNullOrWhiteSpace(boxCropTo.Text))
            {
                end = "-to " + boxCropTo.Text.Trim();
                if (boxCropTo.Text.Contains(":"))
                {
                    TimeSpan time;
                    if (!TimeSpan.TryParse(boxCropTo.Text, out time))
                        return "Invalid end crop time!";
                    duration = (float)time.TotalSeconds;
                }
                else
                {
                    uint integer;
                    if (!uint.TryParse(boxCropTo.Text, out integer))
                        return "Invalid end crop time!";
                    duration = integer;
                }
            }

            /*if (string.IsNullOrWhiteSpace(start) && !string.IsNullOrWhiteSpace(end) ||
                !string.IsNullOrWhiteSpace(start) && string.IsNullOrWhiteSpace(end))
                return "One of the crop time fields is empty! Either empty them both, or fill them both.";*/

            float limit = 0;
            string limitTo = "";
            if (!string.IsNullOrWhiteSpace(boxLimit.Text))
            {
                if (!float.TryParse(boxLimit.Text, out limit))
                    return "Invalid size limit!";
                limitTo = string.Format("-fs {0}M", limit.ToString(System.Globalization.CultureInfo.InvariantCulture)); //Should turn comma into dot
            }

            string size = "";
            if (width != 0 && height != 0)
                size = string.Format("-vf scale={0}:{1}", width, height);

            //Calculate bitrate yourself!
            //1 megabyte = 8192 kilobits
            //3 megabytes = 24576 kilobits -> this is the limit
            //So if you have 60 seconds, the bitrate should be...
            //24576/60 = 409.6 kilobits/sec

            int bitrate = 900;
            if (duration != 0 && limit != 0) bitrate = (int)(8192 * limit / duration);

            if (!string.IsNullOrWhiteSpace(boxBitrate.Text))
                if (!int.TryParse(boxBitrate.Text, out bitrate))
                    return "Invalid bitrate!";

            string audio = "";
            if (!checkBoxAudio.Checked) //Remember, if the box ISN'T checked, the tag gets added
                audio = "-an";

            string arguments = string.Format(_template, input, start, end, audio, bitrate, size, limitTo, output);
            var form = new ConverterForm(arguments);
            form.ShowDialog();

            return null;
        }
    }
}

{'fraction_non_alphanumeric': 0.10410958904109589, 'fraction_numerical': 0.00989345509893455, 'mean_word_length': 1.5661003710212849, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5949349', 'n_tokens_mistral': 3571, 'n_tokens_neox': 3390, 'n_words': 948}