using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Collections;
namespace Video_Convertor
{
public partial class ConvertVideo : Form
{
public ConvertVideo()
{
InitializeComponent();
}
private void ConvertVideo_Load(object sender, EventArgs e)
{
cmbFileFormat.Enabled = false;
}
private bool validation()
{
bool flag = true;
if (txtSournce.Text.Trim() == string.Empty)
{
MessageBox.Show("Please choose source path.");
flag = false;
}
else if (txtDestination.Text.Trim() == string.Empty)
{
MessageBox.Show("Please choose destination path.");
flag = false;
}
else if (cmbConversionType.SelectedIndex == -1)
{
MessageBox.Show("Please choose the conversion type.");
flag = false;
}
else if (cmbFileFormat.SelectedIndex == -1)
{
MessageBox.Show("Please choose the file format.");
flag = false;
}
return flag;
}
private bool validateFileExtions(string inputFileExt, int conversionType)
{
string fileExt = inputFileExt;
string[] validfileExt = { ".wmv", ".flv", ".3gp", ".avi", ".dat", ".mpg", ".vob", ".mkv" };
if (validfileExt.Contains(fileExt))
{
return true;
}
return false;
}
private void btnConvert_Click(object sender, EventArgs e)
{
if (validation())
{
string[] files = Directory.GetFiles(txtSournce.Text);
string outputFileName = string.Empty;
string inputPath = string.Empty;
string outputPath = string.Empty;
string cmd = string.Empty;
string aORv = string.Empty;
if (files.Length > 0)
{
cmd = "-i {0} -r 25 -s vga -b:{1} 1024000 -ab 192000 {2}";
aORv = (cmbConversionType.SelectedIndex == 0) ? "a" : "v";
foreach (string file in files)
{
inputPath = @"""" + file + @"""";
if (validateFileExtions(Path.GetExtension(file), cmbConversionType.SelectedIndex))
{
outputFileName = Path.GetFileNameWithoutExtension(file) + cmbFileFormat.SelectedItem.ToString();
outputPath=txtDestination.Text + "\\" + outputFileName;
cmd = string.Format(cmd, inputPath, aORv, @"""" + outputPath + @"""");
ProcessFile( cmd);
}
}
}
else
{
MessageBox.Show("There is no file(s) in input folder.");
}
}
}
private void ProcessFile(string cmd)
{
string apppath = Application.StartupPath + "\\ffmpeg\\ffmpeg.exe";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = apppath;
proc.StartInfo.Arguments = cmd;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
proc.Close();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void cmbConversionType_SelectedIndexChanged(object sender, EventArgs e)
{
cmbFileFormat.Items.Clear();
if (cmbConversionType.SelectedIndex != -1)
{
cmbFileFormat.Enabled = true;
string[] validfileExt = (cmbConversionType.SelectedIndex == 0) ? new string[] { ".mp3", ".wma" } : new string[] { ".wmv", ".flv", ".3gp", ".avi", ".dat", ".mpg", ".vob", ".mkv" };
Array.Sort<string>(validfileExt);
foreach (string ext in validfileExt)
{
cmbFileFormat.Items.Add(ext);
}
//cmbFileFormat.Refresh();
//cmbFileFormat.SelectedIndex = -1;
//cmbFileFormat.SelectedText = string.Empty;
}
}
private void btnSelectSource_Click(object sender, EventArgs e)
{
FolderBrowserDialog browseDialog = new FolderBrowserDialog();
browseDialog.Description = "Select folder that contains input video(s).";
browseDialog.ShowNewFolderButton = false;
DialogResult result = browseDialog.ShowDialog();
if (result == DialogResult.OK)
{
txtSournce.Text = browseDialog.SelectedPath;
}
}
private void btnSelectDestination_Click(object sender, EventArgs e)
{
FolderBrowserDialog browseDialog = new FolderBrowserDialog();
browseDialog.Description = "Select or create new folder that will contains output video(s).";
browseDialog.ShowNewFolderButton = true;
DialogResult result = browseDialog.ShowDialog();
if (result == DialogResult.OK)
{
txtDestination.Text = browseDialog.SelectedPath;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Collections;
namespace Video_Convertor
{
public partial class ConvertVideo : Form
{
public ConvertVideo()
{
InitializeComponent();
}
private void ConvertVideo_Load(object sender, EventArgs e)
{
cmbFileFormat.Enabled = false;
}
private bool validation()
{
bool flag = true;
if (txtSournce.Text.Trim() == string.Empty)
{
MessageBox.Show("Please choose source path.");
flag = false;
}
else if (txtDestination.Text.Trim() == string.Empty)
{
MessageBox.Show("Please choose destination path.");
flag = false;
}
else if (cmbConversionType.SelectedIndex == -1)
{
MessageBox.Show("Please choose the conversion type.");
flag = false;
}
else if (cmbFileFormat.SelectedIndex == -1)
{
MessageBox.Show("Please choose the file format.");
flag = false;
}
return flag;
}
private bool validateFileExtions(string inputFileExt, int conversionType)
{
string fileExt = inputFileExt;
string[] validfileExt = { ".wmv", ".flv", ".3gp", ".avi", ".dat", ".mpg", ".vob", ".mkv" };
if (validfileExt.Contains(fileExt))
{
return true;
}
return false;
}
private void btnConvert_Click(object sender, EventArgs e)
{
if (validation())
{
string[] files = Directory.GetFiles(txtSournce.Text);
string outputFileName = string.Empty;
string inputPath = string.Empty;
string outputPath = string.Empty;
string cmd = string.Empty;
string aORv = string.Empty;
if (files.Length > 0)
{
cmd = "-i {0} -r 25 -s vga -b:{1} 1024000 -ab 192000 {2}";
aORv = (cmbConversionType.SelectedIndex == 0) ? "a" : "v";
foreach (string file in files)
{
inputPath = @"""" + file + @"""";
if (validateFileExtions(Path.GetExtension(file), cmbConversionType.SelectedIndex))
{
outputFileName = Path.GetFileNameWithoutExtension(file) + cmbFileFormat.SelectedItem.ToString();
outputPath=txtDestination.Text + "\\" + outputFileName;
cmd = string.Format(cmd, inputPath, aORv, @"""" + outputPath + @"""");
ProcessFile( cmd);
}
}
}
else
{
MessageBox.Show("There is no file(s) in input folder.");
}
}
}
private void ProcessFile(string cmd)
{
string apppath = Application.StartupPath + "\\ffmpeg\\ffmpeg.exe";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = apppath;
proc.StartInfo.Arguments = cmd;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
proc.Close();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void cmbConversionType_SelectedIndexChanged(object sender, EventArgs e)
{
cmbFileFormat.Items.Clear();
if (cmbConversionType.SelectedIndex != -1)
{
cmbFileFormat.Enabled = true;
string[] validfileExt = (cmbConversionType.SelectedIndex == 0) ? new string[] { ".mp3", ".wma" } : new string[] { ".wmv", ".flv", ".3gp", ".avi", ".dat", ".mpg", ".vob", ".mkv" };
Array.Sort<string>(validfileExt);
foreach (string ext in validfileExt)
{
cmbFileFormat.Items.Add(ext);
}
//cmbFileFormat.Refresh();
//cmbFileFormat.SelectedIndex = -1;
//cmbFileFormat.SelectedText = string.Empty;
}
}
private void btnSelectSource_Click(object sender, EventArgs e)
{
FolderBrowserDialog browseDialog = new FolderBrowserDialog();
browseDialog.Description = "Select folder that contains input video(s).";
browseDialog.ShowNewFolderButton = false;
DialogResult result = browseDialog.ShowDialog();
if (result == DialogResult.OK)
{
txtSournce.Text = browseDialog.SelectedPath;
}
}
private void btnSelectDestination_Click(object sender, EventArgs e)
{
FolderBrowserDialog browseDialog = new FolderBrowserDialog();
browseDialog.Description = "Select or create new folder that will contains output video(s).";
browseDialog.ShowNewFolderButton = true;
DialogResult result = browseDialog.ShowDialog();
if (result == DialogResult.OK)
{
txtDestination.Text = browseDialog.SelectedPath;
}
}
}
}
0 comments:
Post a Comment