private Output PrepareAndGoConvert(string inputPath) { Output output = new Output(); if (this.IsConverterReady()) { VideoFile input = new VideoFile(inputPath); return(this.ConvertToVideoType(input)); } output.Message = this._ErrorInfo; EncoderLog log = new EncoderLog("error.log", output.Message); return(output); }
private Output ConvertToVideoType(VideoFile input) { StringBuilder builder = new StringBuilder(); Output output = new Output(); if (!input.Found) { output.Message = input.Message; } else if (this._allowedext.IndexOf(Path.GetExtension(input.Path).ToLower()) < 0) { if (".xml.log.db".IndexOf(Path.GetExtension(input.Path)) < 0) { output.Message = "\"" + input.Path + "\" " + Path.GetExtension(input.Path) + " files are not allowed to convert."; } } else { if (!input.infoGathered) { } string fileName = string.Empty; string path = string.Empty; string parameters = string.Empty; string str4 = string.Empty; string outputSettings = this.GetOutputSettings(); fileName = Path.GetFileName(input.Path); path = Path.Combine(this._OutputPath, fileName); if (this._Settings.OutputAudioOnly) { path = Path.ChangeExtension(path, this._Settings.OutputAudioType); } else { path = Path.ChangeExtension(path, this._Settings.OutputVideoType); } parameters = string.Format("-i \"{0}\" {1} -pass 1 -passlogfile \"{2}\" NULL.3gp", input.Path, outputSettings, input.Path + "_pass2"); output.ConversionStart = DateTime.Now; str4 = this.RunProcess(parameters); parameters = string.Format("-i \"{0}\" {1} -pass 2 -passlogfile \"{2}\" \"{3}\"", new object[] { input.Path, outputSettings, input.Path + "_pass2", path }); str4 = this.RunProcess(parameters); try { if (File.Exists("NULL.3gp")) { File.Delete("NULL.3gp"); } if (File.Exists(input.Path + "_pass2-0.log")) { File.Delete(input.Path + "_pass2-0.log"); } } catch (Exception ex) { sb.AppendLine("Message - " + ex.Message + " Exception - " + ex.InnerException + " Source - " + ex.Source); } output.ConversionEnd = DateTime.Now; output.RawOutput = str4; output.Success = false; output.Message = "Failed"; if (str4.Contains("Output #")) { Regex regex = new Regex(""); Match match = regex.Match(""); int num = 0; int num2 = 0; if (this._Settings.OutputAudioOnly) { regex = new Regex(" audio:(?<AudioSize>[0-9]+)[k|K|m|M|g|G]B ", RegexOptions.IgnoreCase); match = regex.Match(str4); try { num = Convert.ToInt32(match.Groups["AudioSize"].Value); } catch (Exception ex) { sb.AppendLine("Message - " + ex.Message + " Exception - " + ex.InnerException + " Source - " + ex.Source); } if (num > 0) { output.Success = true; output.Message = "File has successfully been converted"; } } else { match = new Regex("video:(?<VideoSize>[0-9]+)[k|K|m|M|g|G]B audio:(?<AudioSize>[0-9]+)[k|K|m|M|g|G]B ", RegexOptions.IgnoreCase).Match(str4); try { num = Convert.ToInt32(match.Groups["AudioSize"].Value); num2 = Convert.ToInt32(match.Groups["VideoSize"].Value); } catch (Exception ex) { sb.AppendLine("Message - " + ex.Message + " Exception - " + ex.InnerException + " Source - " + ex.Source); } if ((num2 > 0) && (num > 0)) { output.Success = true; output.Message = "File has successfully been converted"; } else if ((num2 > 0) && (num <= 0)) { output.Message = output.Message + " (audio not converted)"; } else if (num2 <= 0) { output.Message = output.Message + " (video not converted)"; } } } else { string[] strArray = str4.Split(new char[] { '\r' }); if (strArray.Length > 0) { string str6 = ""; if (strArray[strArray.Length - 1] == "\n") { str6 = strArray[strArray.Length - 2].Replace('\n', ' ').Trim(); } else { str6 = strArray[strArray.Length - 1].Replace('\n', ' ').Trim(); } if (string.IsNullOrEmpty(str6)) { str6 = "Ffmpeg didn't return any output"; } output.Message = str6; } } if (output.Success && File.Exists(path)) { string str7 = Path.ChangeExtension(fileName, this._Settings.OutputVideoType); output.FileName = str7; output.VideoStream = LoadMemoryStreamFromFile(path); int num3 = this.ConvertedFileLimitInKB * 0x400; if (output.VideoStream.Length > num3) { output.VideoStream = null; output.Success = false; output.Message = "Output file stream is larger than " + Utility.BytesToWords((long)num3); } } try { File.Delete(path); } catch (Exception ex) { sb.AppendLine("Message - " + ex.Message + " Exception - " + ex.InnerException + " Source - " + ex.Source); } builder.AppendLine("[Input]= " + input.Path); builder.AppendLine("[Output]= " + path); builder.AppendLine(); builder.AppendLine("[Ffmpeg History] "); builder.Append(str4); if (string.IsNullOrEmpty(str4)) { builder.Append("Ffmpeg didn't return any output"); builder.AppendLine(); } builder.AppendLine(); builder.AppendLine(); builder.AppendLine("[Conversion Status]= " + output.Message); builder.AppendLine(); builder.AppendFormat("[Conversion Start Time]= {0}", output.ConversionStart.ToLongTimeString()); builder.AppendLine(); builder.AppendFormat("[Conversion End Time]= {0}", output.ConversionEnd.ToLongTimeString()); builder.AppendLine(); builder.AppendFormat("[Total Time]= {0}", output.GetConversionTime()); } if (this._LogOutput) { if (string.IsNullOrEmpty(builder.ToString())) { return(output); } EncoderLog log = new EncoderLog(); if (string.IsNullOrEmpty(this._LogPath)) { log.FilePath = Path.GetDirectoryName(input.Path); } else { log.FilePath = this._LogPath; } log.WriteLog(builder.ToString()); } return(output); }