public void CreateTwoPassX264File()
{
try
{
int episodeNumber = 1;
using (StreamWriter sw = new StreamWriter(_x264FileSettings.X264BatchFilePath, false))
{
foreach (X264File x264File in _x264Files.OrderBy(f => f.AviSynthFileNameOnly))
{
//1st pass
StringBuilder sb1stPass = new StringBuilder();
sb1stPass.Append(string.Format("\"{0}\"", _x264FileSettings.vfw4x264Exe));
sb1stPass.Append(string.Format(" \"{0}\"", x264File.AviSynthFilePath));
sb1stPass.Append(" --pass 1");
sb1stPass.Append(string.Format(" {0}", _x264FileSettings.X264Template));
if (_x264FileSettings.X264EncodeAndLogFileOutputDirectoryPathType == EnumDirectoryType.DirectoryPerEpisode)
{
string episodeFolderName = HelperFunctions.PadNumberWithZeros(_x264Files.Count(),episodeNumber);
if (_x264FileSettings.SaveX264LogFileToDifferentDirectory)
sb1stPass.Append(string.Format(" --output NUL - 2> \"{0}\\{1}.x264.pass1.log\"", _x264FileSettings.X264LogFileOutputDirectoryPath, x264File.EncodeName));
else
sb1stPass.Append(string.Format(" --output NUL - 2> \"{0}\\episode{1}\\{2}.x264.pass1.log\"", _x264FileSettings.X264EncodeAndLogFileOutputDirectoryPath, episodeFolderName, x264File.EncodeName));
}
else
{
if (_x264FileSettings.SaveX264LogFileToDifferentDirectory)
sb1stPass.Append(string.Format(" --output NUL - 2> \"{0}\\{1}.x264.pass1.log\"", _x264FileSettings.X264LogFileOutputDirectoryPath, x264File.EncodeName));
else
sb1stPass.Append(string.Format(" --output NUL - 2> \"{0}\\{1}.x264.pass1.log\"", _x264FileSettings.X264EncodeAndLogFileOutputDirectoryPath, x264File.EncodeName));
}
sw.WriteLine(sb1stPass.ToString());
sw.WriteLine();
//2nd pass
StringBuilder sb2ndPass = new StringBuilder();
sb2ndPass.Append(string.Format("\"{0}\"", _x264FileSettings.vfw4x264Exe));
sb2ndPass.Append(string.Format(" \"{0}\"", x264File.AviSynthFilePath));
sb1stPass.Append(" --pass 2");
sb2ndPass.Append(string.Format(" {0}", _x264FileSettings.X264Template));
if (_x264FileSettings.X264EncodeAndLogFileOutputDirectoryPathType == EnumDirectoryType.DirectoryPerEpisode)
{
string episodeFolderName = HelperFunctions.PadNumberWithZeros(_x264Files.Count(), episodeNumber);
sb2ndPass.Append(string.Format(" --output \"{0}\\episode{1}\\{2}\"", _x264FileSettings.X264EncodeAndLogFileOutputDirectoryPath,episodeFolderName, x264File.EncodeName));
if (_x264FileSettings.SaveX264LogFileToDifferentDirectory)
sb2ndPass.Append(string.Format(" - 2> \"{0}\\{1}.x264.pass2.log\"", _x264FileSettings.X264LogFileOutputDirectoryPath, x264File.EncodeName));
else
sb2ndPass.Append(string.Format(" - 2> \"{0}\\episode{1}\\{2}.x264.pass2.log\"", _x264FileSettings.X264EncodeAndLogFileOutputDirectoryPath, episodeFolderName, x264File.EncodeName));
}
else
{
sb2ndPass.Append(string.Format(" --output \"{0}\\{1}\"", _x264FileSettings.X264EncodeAndLogFileOutputDirectoryPath, x264File.EncodeName));
if (_x264FileSettings.SaveX264LogFileToDifferentDirectory)
sb2ndPass.Append(string.Format(" - 2> \"{0}\\{1}.x264.pass2.log\"", _x264FileSettings.X264LogFileOutputDirectoryPath, x264File.EncodeName));
else
sb2ndPass.Append(string.Format(" - 2> \"{0}\\{1}.x264.pass2.log\"", _x264FileSettings.X264EncodeAndLogFileOutputDirectoryPath, x264File.EncodeName));
}
sw.WriteLine(sb2ndPass.ToString());
sw.WriteLine();
sw.WriteLine();
episodeNumber++;
}
}
}
catch (Exception ex)
{
_log.ErrorFormat(Program.GetLogErrorFormat(), ex.Message, ex.StackTrace, MethodBase.GetCurrentMethod().Name);
_errors.Add(new Error() { Description = "There was an error trying to create the x264 batch file. Please see the error log for more details." });
}
}