private void Main_Load(object sender, EventArgs e) { try { fileName = Environment.GetCommandLineArgs()[1]; } catch (Exception error) { } if( fileName != "") { //Look for matching .srt for our file. string[] paths = Directory.GetFiles(Path.GetDirectoryName(Path.GetFullPath(fileName))); fileObj = getFileData(fileName); string sub = Path.GetDirectoryName(Path.GetFullPath(fileName)) +"\\"+Path.GetFileNameWithoutExtension(fileName) + ".srt"; if (paths.Contains(sub)) { //Update our sub name. THE ESCAPE IS REAL. subName = "\"" + sub.Replace("\\","\\\\\\\\").Replace(":", "\\\\:") + "\"" + ":force_style='FontName=Arial,FontSize=20'"; subCheck.Enabled = true; } foreach (streamType stream in fileObj.streams) { if (stream.codec_type == "subtitle") { //The file contains it's own sub stream. subName = "\"" + fileObj.format.filename.Replace("\\", "\\\\\\\\").Replace(":", "\\\\:") + "\""; subCheck.Enabled = true; } } } destination.Text = targetURL; file.Text = fileName; bitrateAudio.Value = aBit; bitrateVideo.Value = vBit; videoRes.Text = vSize; buttonPause.Enabled = false; }
public ffprobeType getFileData(string path) { Process ffprobe = new Process(); //Run the thing. ffprobe.StartInfo.FileName = "ffprobe.exe"; ffprobe.StartInfo.UseShellExecute = false; ffprobe.StartInfo.RedirectStandardOutput = true; ffprobe.StartInfo.RedirectStandardError = true; ffprobe.StartInfo.CreateNoWindow = true; ffprobe.StartInfo.Arguments = "-v quiet -print_format xml=q=1 -show_format -show_streams " + "\"" + Path.GetFullPath(path) + "\""; ffprobeType output = new ffprobeType(); ffprobe.Start(); //Deserialize output back into the xsd generated class. XmlSerializer ser = new XmlSerializer(typeof(ffprobeType)); ffprobeType file; Stream stream = ffprobe.StandardOutput.BaseStream; string content; var reader = new StreamReader(stream); content = reader.ReadToEnd(); if (stream.CanSeek) { stream.Seek(0, SeekOrigin.Begin); } else { stream.Dispose(); stream = new MemoryStream(Encoding.UTF8.GetBytes(content)); } using (XmlReader myReader = XmlReader.Create(stream)) { file = (ffprobeType)ser.Deserialize(myReader); } stream.Seek(0, SeekOrigin.Begin); infoBox.Text = new StreamReader(stream).ReadToEnd(); return file; }