示例#1
0
        private void menuCrop_Click(object sender, EventArgs e)
        {
            try
            {
                // index == 8
                index = ((ToolStripMenuItem)sender).Owner.Items.IndexOf((ToolStripMenuItem)sender);

                cbxSpecies.Items.Clear();
                cbxSpecies.Items.Add("[Default] Width:Height");
                cbxSpecies.Items.Add("[Advanced] Width:Height:X:Y");
                cbxSpecies.Items.Add("[Autosize X] Width:Height:-1:Y");
                cbxSpecies.Items.Add("[AutoSize Y] Width:Height:X:-1");

                if (string.IsNullOrEmpty(open.FileName))
                {
                    MessageBox.Show("Your path is incorrect", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    // Trong cbxSpecies cbxSpecies.Text khong phai la 1 Items nen co the kiem tra Text vs cac Items cua no
                    for (int i = 0; i < cbxSpecies.Items.Count; i++)
                    {
                        if (cbxSpecies.Text == cbxSpecies.Items[i].ToString())
                        {
                            break;
                        }
                        else if (cbxSpecies.Text != cbxSpecies.Items[i].ToString() && i == cbxSpecies.Items.Count - 1)
                        {
                            cbxSpecies.Text = "";
                        }
                    }

                    if (!string.IsNullOrEmpty(cbxSpecies.Text))
                    {
                        txtFileName.Text = open.FileName;

                        using (frmGetCoordinates getCoordinates = new frmGetCoordinates())
                        {
                            if (getCoordinates.ShowDialog() == DialogResult.OK)
                            {
                                if (save.ShowDialog() == DialogResult.OK)
                                {
                                    // -i input.mp4 -vf  "crop=w:h:x:y" output.mp4
                                    // -i input.mp4 -vf crop=w:h:x:y output.mp4
                                    //      + w: chieu dai cua anh
                                    //      + h: chieu cao cua anh
                                    //      + x: toa do truc Ox khi cat anh ---> tu trai sang phai
                                    //      + y: toa do truc Oy khi cat anh \> tu tren xuong duoi
                                    //      + Neu nhu khong goi x, y chi co so lieu w, h thoi thi anh se tu dong duoc cat o phan trung tam

                                    /// ===> Tao ra 1 video moi la output.mp4 tu video cu la input.mp4 nhung co kich thuoc thi bi crop

                                    processStartInfo.FileName = "ffmpeg";

                                    if (!string.IsNullOrEmpty(getCoordinates.txtWidth.Text) && !string.IsNullOrEmpty(getCoordinates.txtHeight.Text))
                                    {
                                        // -i input.mp4 -vf crop=w:h out.putmp4
                                        if (string.IsNullOrEmpty(getCoordinates.txtX.Text) && string.IsNullOrEmpty(getCoordinates.txtY.Text))
                                        {
                                            processStartInfo.Arguments = "-i " + open.FileName +
                                                                         " -vf crop=" + getCoordinates.txtWidth.Text + ":" + getCoordinates.txtHeight.Text + " " + save.FileName;
                                        }

                                        // -i input.mp4 -vf crop=w:h:x:y out.putmp4
                                        else if (!string.IsNullOrEmpty(getCoordinates.txtX.Text) && !string.IsNullOrEmpty(getCoordinates.txtY.Text))
                                        {
                                            processStartInfo.Arguments = "-i " + open.FileName +
                                                                         " -vf crop=" + getCoordinates.txtWidth.Text + ":" + getCoordinates.txtHeight.Text +
                                                                         ":" + getCoordinates.txtX.Text + ":" + getCoordinates.txtY.Text + " " + save.FileName;
                                        }

                                        // -i input.mp4 -vf crop=w:h:-1:y out.putmp4
                                        else if (string.IsNullOrEmpty(getCoordinates.txtX.Text) && !string.IsNullOrEmpty(getCoordinates.txtY.Text))
                                        {
                                            processStartInfo.Arguments = "-i " + open.FileName +
                                                                         " -vf crop=" + getCoordinates.txtWidth.Text + ":" + getCoordinates.txtHeight.Text +
                                                                         ":-1:" + getCoordinates.txtY.Text + " " + save.FileName;
                                        }

                                        // -i input.mp4 -vf crop=w:h:x:-1 out.putmp4
                                        else if (!string.IsNullOrEmpty(getCoordinates.txtX.Text) && string.IsNullOrEmpty(getCoordinates.txtY.Text))
                                        {
                                            processStartInfo.Arguments = "-i " + open.FileName +
                                                                         " -vf crop=" + getCoordinates.txtWidth.Text + ":" + getCoordinates.txtHeight.Text +
                                                                         ":" + getCoordinates.txtX.Text + ":-1 " + save.FileName;
                                        }

                                        using (Process process = new Process()
                                        {
                                            StartInfo = processStartInfo
                                        })
                                        {
                                            if (process.Start())
                                            {
                                                MessageBox.Show("Excuting", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                process.WaitForExit();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Your width or height value is empty", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        txtFileName.Text = "Select videos cropping mode";
                    }
                }
            }
            catch (MyException myEx)
            {
                MessageBox.Show(myEx.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// menuEdit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuChangeResolution_Click(object sender, EventArgs e)
        {
            // index == 0
            index = ((ToolStripMenuItem)sender).Owner.Items.IndexOf((ToolStripMenuItem)sender);

            cbxSpecies.Items.Clear();
            cbxSpecies.Items.Add("[Default] Width:Height");
            cbxSpecies.Items.Add("[Auto Size] Width:-1");
            cbxSpecies.Items.Add("[Auto Size] -1:Height");

            if (!string.IsNullOrEmpty(cbxSpecies.Text))
            {
                // Trong cbxSpecies cbxSpecies.Text khong phai la 1 Items nen co the kiem tra Text vs cac Items cua no
                for (int i = 0; i < cbxSpecies.Items.Count; i++)
                {
                    if (cbxSpecies.Text == cbxSpecies.Items[i].ToString())
                    {
                        cbxSpecies.SelectedIndex = i;
                        break;
                    }
                    else if (cbxSpecies.Text != cbxSpecies.Items[i].ToString() && i == cbxSpecies.Items.Count - 1)
                    {
                        cbxSpecies.Text = "";
                    }
                }

                if (!string.IsNullOrEmpty(cbxSpecies.Text))
                {
                    using (OpenFileDialog open = new OpenFileDialog()
                    {
                        Filter = "(PNG file)|*.png|(JPG file)|*.jpg"
                    })
                    {
                        if (open.ShowDialog() == DialogResult.OK)
                        {
                            if (string.IsNullOrEmpty(open.FileName))
                            {
                                MessageBox.Show("Your path is incorrect", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else
                            {
                                txtFileName.Text = open.FileName;

                                using (frmGetCoordinates getCoordinates = new frmGetCoordinates())
                                {
                                    if (getCoordinates.ShowDialog() == DialogResult.OK)
                                    {
                                        using (SaveFileDialog save = new SaveFileDialog()
                                        {
                                            Filter = "(PNG file)|*.png|(JPG file)|*.jpg"
                                        })
                                        {
                                            if (save.ShowDialog() == DialogResult.OK)
                                            {
                                                processStartInfo.FileName = "ffmpeg";

                                                // -i input.mp4 -vf scale=320:240 -sws_flags bilinear output.mp4
                                                if (!string.IsNullOrEmpty(getCoordinates.txtWidth.Text) && !string.IsNullOrEmpty(getCoordinates.txtHeight.Text))
                                                {
                                                    processStartInfo.Arguments = "-i " + open.FileName + " -vf scale=" + getCoordinates.txtWidth.Text + ":" + getCoordinates.txtHeight.Text +
                                                                                 " -sws_flags bilinear " + save.FileName;
                                                }

                                                // -i input.mp4 -vf scale=320:-1 -sws_flags bilinear output.mp4
                                                else if (!string.IsNullOrEmpty(getCoordinates.txtWidth.Text) && string.IsNullOrEmpty(getCoordinates.txtHeight.Text))
                                                {
                                                    if (cbxSpecies.Text == cbxSpecies.Items[1].ToString())
                                                    {
                                                        processStartInfo.Arguments = "-i " + open.FileName + " -vf scale=" + getCoordinates.txtWidth.Text +
                                                                                     ":-1 -sws_flags bilinear " + save.FileName;
                                                    }
                                                }

                                                // -i input.mp4 -vf scale=-1:240 -sws_flags bilinear output.mp4
                                                else
                                                {
                                                    if (cbxSpecies.Text == cbxSpecies.Items[2].ToString())
                                                    {
                                                        processStartInfo.Arguments = "-i " + open.FileName + " -vf scale=-1:" + getCoordinates.txtHeight.Text +
                                                                                     " -sws_flags bicubic " + save.FileName;
                                                    }
                                                }
                                                txtFileName.Text = processStartInfo.Arguments;

                                                using (Process process = new Process()
                                                {
                                                    StartInfo = processStartInfo
                                                })
                                                {
                                                    if (process.Start())
                                                    {
                                                        MessageBox.Show("Excuting", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                txtFileName.Text = "Select scaling videos";
            }
        }