/// <summary> /// Handle eac3 conversions for mencoder /// TODO: This function is redundant and incorrectly written, handbrake, ffmpeg and mencoder are able to handle eac3 audio why do we need this? /// </summary> private bool ConvertMencoderEAC3() { string audioStream = ""; _jobStatus.PercentageComplete = 100; //all good by default _jobStatus.ETA = ""; if ((_videoFile.AudioCodec != "e-ac-3") && (_videoFile.AudioCodec != "eac3")) return true; // Only supports MP4, MKV and AVI if ((_extension != ".mp4") && (_extension != ".mkv") && (_extension != ".avi")) return true; _jobStatus.CurrentAction = Localise.GetPhrase("Converting E-AC3"); _jobLog.WriteEntry(this, ("Converting E-AC3"), Log.LogEntryType.Information); // Convert EAC3 file string eac3toParams; string audiop = _audioParams.Trim(); if (audiop.Contains("faac") || audiop.Contains("libfaac") || audiop.Contains("aac")) { audioStream = Path.Combine(_workingPath, Path.GetFileNameWithoutExtension(SourceVideo) + "_AUDIO.mp4"); eac3toParams = Util.FilePaths.FixSpaces(SourceVideo) + " " + Util.FilePaths.FixSpaces(audioStream) + " -384"; } else // TODO: what about other audio formats? { audioStream = Path.Combine(_workingPath, Path.GetFileNameWithoutExtension(SourceVideo) + "_AUDIO.ac3"); eac3toParams = Util.FilePaths.FixSpaces(SourceVideo) + " " + Util.FilePaths.FixSpaces(audioStream) + " -384"; } FileIO.TryFileDelete(audioStream); // Clean before starting Eac3To eac3to = new AppWrapper.Eac3To(eac3toParams, _jobStatus, _jobLog); eac3to.Run(); if (!eac3to.Success) { FileIO.TryFileDelete(audioStream); // Clean _jobLog.WriteEntry(this, ("E-AC3 conversion unsuccessful"), Log.LogEntryType.Error); _jobStatus.ErrorMsg = "E-AC3 conversion unsuccessful"; _jobStatus.PercentageComplete = 0; return false; // something went wrong } // Mux into destination if ((_extension == ".mp4") || (_extension == ".m4v")) { _jobLog.WriteEntry(this, ("Muxing E-AC3 using MP4Box"), Log.LogEntryType.Information); string mp4boxParams = " -keep-sys -keep-all -add " + FilePaths.FixSpaces(audioStream) + " " + FilePaths.FixSpaces(_convertedFile); _jobStatus.PercentageComplete = 0; //reset _jobStatus.ETA = ""; MP4Box mp4box = new MP4Box(mp4boxParams, _jobStatus, _jobLog); mp4box.Run(); if (!mp4box.Success || _jobStatus.PercentageComplete < GlobalDefs.ACCEPTABLE_COMPLETION) // check for incomplete output or process issues { FileIO.TryFileDelete(audioStream); _jobLog.WriteEntry(this, ("E-AC3 muxing using MP4Box failed at") + " " + _jobStatus.PercentageComplete.ToString(System.Globalization.CultureInfo.InvariantCulture), Log.LogEntryType.Error); _jobStatus.ErrorMsg = "E-AC3 muxing using MP4Box failed"; _jobStatus.PercentageComplete = 0; // something went wrong with the process return false; } } else if (_extension == ".mkv") { _jobLog.WriteEntry(this, ("Muxing E-AC3 using MKVMerge"), Log.LogEntryType.Information); string remuxedFile = Path.Combine(_workingPath, Path.GetFileNameWithoutExtension(_convertedFile) + "_REMUX.mkv"); FileIO.TryFileDelete(remuxedFile); string mkvmergeParams = "--clusters-in-meta-seek --compression -1:none " + FilePaths.FixSpaces(_convertedFile) + " --compression -1:none " + FilePaths.FixSpaces(audioStream) + " -o " + FilePaths.FixSpaces(remuxedFile); _jobStatus.PercentageComplete = 0; //reset _jobStatus.ETA = ""; MKVMerge mkvmerge = new MKVMerge(mkvmergeParams, _jobStatus, _jobLog); mkvmerge.Run(); if (!mkvmerge.Success) { FileIO.TryFileDelete(audioStream); FileIO.TryFileDelete(remuxedFile); _jobLog.WriteEntry(this, ("Muxing E-AC3 using MKVMerge failed"), Log.LogEntryType.Error); _jobStatus.ErrorMsg = "Muxing E-AC3 using MKVMerge failed"; _jobStatus.PercentageComplete = 0; // something went wrong with the process return false; } try { _jobLog.WriteEntry(this, ("Moving MKVMerge muxed E-AC3"), Log.LogEntryType.Information); FileIO.TryFileDelete(_convertedFile); File.Move(remuxedFile, _convertedFile); _jobStatus.PercentageComplete = 100; //proxy for job done since mkvmerge doesn't report _jobStatus.ETA = ""; } catch (Exception e) { FileIO.TryFileDelete(audioStream); FileIO.TryFileDelete(remuxedFile); _jobLog.WriteEntry(this, ("Unable to move MKVMerge remuxed E-AC3 file") + " " + remuxedFile + "\r\nError : " + e.ToString(), Log.LogEntryType.Error); _jobStatus.PercentageComplete = 0; _jobStatus.ErrorMsg = "Unable to move MKVMerge remuxed E-AC3 file"; return false; } } else { _jobStatus.PercentageComplete = 0; //reset _jobStatus.ETA = ""; _jobLog.WriteEntry(this, ("Muxing E-AC3 using FFMPEGRemux"), Log.LogEntryType.Information); double fps = 0; double.TryParse(_fps, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out fps); RemuxExt remuxFile = new RemuxExt(_convertedFile, _workingPath, (fps <= 0 ? _videoFile.Fps : fps), _jobStatus, _jobLog, _remuxTo); // Use output FPS if it exists otherwise the source file FPS (since it has not changed) if (remuxFile.FfmpegRemux(audioStream)) { _convertedFile = remuxFile.RemuxedFile; } else { FileIO.TryFileDelete(audioStream); _jobLog.WriteEntry(this, ("Error Muxing E-AC3 using FFMPEGRemux"), Log.LogEntryType.Error); _jobStatus.PercentageComplete = 0; _jobStatus.ErrorMsg = "Error Muxing E-AC3 using FFMPEGRemux"; return false; } } FileIO.TryFileDelete(audioStream); // Clean up _jobLog.WriteEntry(this, ("Finished EAC3 conversion, file size [KB]") + " " + (FileIO.FileSize(_convertedFile) / 1024).ToString("N", System.Globalization.CultureInfo.InvariantCulture), Log.LogEntryType.Debug); return true; }