private string GenerateCommandLine() { var sb = new StringBuilder(); var avs = new AviSynthGenerator(_appConfig); _inputFile = avs.GenerateCropDetect(_currentTask.VideoStream.TempFile, _currentTask.VideoStream.Fps, _currentTask.VideoStream.Length, new Size(_currentTask.VideoStream.Width, _currentTask.VideoStream.Height), _currentTask.VideoStream.AspectRatio, out _cropDetectFrames); sb.Append($"-threads {Environment.ProcessorCount + 1:0} -i \"{_inputFile}\" -vf cropdetect -vcodec rawvideo -an -sn -f matroska -y NUL"); _currentTask.VideoStream.CropRect = new Rectangle(); return(sb.ToString()); }
private string GenerateCommandLine() { var sb = new StringBuilder(); _audio = _currentTask.AudioStreams[_currentTask.StreamId]; var outChannels = ((AacProfile)_currentTask.AudioProfile).OutputChannels; switch (outChannels) { case 1: outChannels = 2; break; case 2: outChannels = 1; break; } var outSampleRate = ((AacProfile)_currentTask.AudioProfile).SampleRate; switch (outSampleRate) { case 1: outSampleRate = 8000; break; case 2: outSampleRate = 11025; break; case 3: outSampleRate = 22050; break; case 4: outSampleRate = 44100; break; case 5: outSampleRate = 48000; break; default: outSampleRate = 0; break; } var encMode = ((AacProfile)_currentTask.AudioProfile).EncodingMode; var bitrate = ((AacProfile)_currentTask.AudioProfile).Bitrate * 1000; var quality = ((AacProfile)_currentTask.AudioProfile).Quality; var avs = new AviSynthGenerator(_appConfig); _inputFile = avs.GenerateAudioScript(_audio.TempFile, _audio.Format, _audio.FormatProfile, _audio.ChannelCount, outChannels, _audio.SampleRate, outSampleRate); _outputFile = FileSystemHelper.CreateTempFile(_appConfig.DemuxLocation, _audio.TempFile, "encoded.m4a"); switch (encMode) { case 0: sb.Append($"-br {bitrate:0} "); break; case 1: sb.Append($"-cbr {bitrate:0} "); break; case 2: sb.Append($"-q {quality:0.00} ".ToString(_appConfig.CInfo)); break; } sb.Append($"-ignorelength -if \"{_appConfig.EncodeNamedPipeFullName}\" -of \"{_outputFile}\" "); return(sb.ToString()); }
private string GenerateCommandLine() { var sb = new StringBuilder(); _encProfile = _currentTask.AudioProfile as Mp3Profile; if (_encProfile == null) { return(string.Empty); } _audio = _currentTask.AudioStreams[_currentTask.StreamId]; var outChannels = _encProfile.OutputChannels; switch (outChannels) { case 0: outChannels = _audio.ChannelCount > 2 ? 2 : 0; break; case 1: outChannels = 1; break; } var outSampleRate = _encProfile.SampleRate; switch (outSampleRate) { case 1: outSampleRate = 8000; break; case 2: outSampleRate = 11025; break; case 3: outSampleRate = 22050; break; case 4: outSampleRate = 44100; break; case 5: outSampleRate = 48000; break; default: outSampleRate = 0; break; } var encMode = _encProfile.EncodingMode; var bitrate = _encProfile.Bitrate; var quality = _encProfile.Quality; var preset = _encProfile.Preset; var avs = new AviSynthGenerator(_appConfig); _inputFile = avs.GenerateAudioScript(_audio.TempFile, _audio.Format, _audio.FormatProfile, _audio.ChannelCount, outChannels, _audio.SampleRate, outSampleRate); _outputFile = FileSystemHelper.CreateTempFile(_appConfig.DemuxLocation, _audio.TempFile, "encoded.mp3"); switch (encMode) { case 2: sb.Append($"-V {quality:0} "); break; case 0: sb.Append($"--preset {bitrate:0} "); break; case 1: sb.Append($"--preset cbr {bitrate:0} "); break; case 3: sb.Append($"--preset {preset} "); break; } sb.Append($"\"{_appConfig.EncodeNamedPipeFullName}\" \"{_outputFile}\" "); return(sb.ToString()); }
private string GenerateCommandLine() { string[] mbdArray = { "simple", "bits", "rd" }; string[] cmpArray = { "sad", "sse", "satd", "dct", "psnr", "bit", "rd" }; var sb = new StringBuilder(); _encProfile = _currentTask.VideoProfile as Mpeg2VideoProfile; if (_encProfile == null) { return(string.Empty); } _inputFile = _currentTask.VideoStream.TempFile; _outputFile = FileSystemHelper.CreateTempFile(_appConfig.DemuxLocation, _inputFile, "encoded.m2v"); _frameCount = _currentTask.VideoStream.FrameCount; #region AviSynth script generation var targetSys = _currentTask.EncodingProfile.SystemType; int targetHeight; var sourceFps = (float)Math.Round(_currentTask.VideoStream.Fps, 3); var targetFps = 0f; var changeFps = false; var sourceAspect = (float)Math.Round(_currentTask.VideoStream.AspectRatio, 3); var targetWidth = sourceAspect >= 1.4f ? 1024 : 720; if (_currentTask.Input == InputType.InputDvd) { _currentTask.VideoStream.Width = (int)Math.Round(_currentTask.VideoStream.Height * sourceAspect, 0); } if (_currentTask.EncodingProfile.OutFormat == OutputType.OutputDvd) { if (targetSys == 0) { targetHeight = 576; if (Math.Abs(sourceFps - 25f) > 0) { changeFps = true; } targetFps = 25f; } else { targetHeight = 480; if (Math.Abs(sourceFps - 29.970f) > 0 && Math.Abs(sourceFps - 23.976f) > 0) { changeFps = true; } targetFps = (float)Math.Round(30000f / 1001f, 3); } } else { targetWidth = _currentTask.EncodingProfile.TargetWidth; targetHeight = (int)Math.Floor(targetWidth / sourceAspect); } var resizeTo = new Size(targetWidth, targetHeight); var sub = _currentTask.SubtitleStreams.FirstOrDefault(item => item.HardSubIntoVideo); var subFile = string.Empty; var keepOnlyForced = false; if (sub != null) { subFile = sub.TempFile; keepOnlyForced = sub.KeepOnlyForcedCaptions; } if (string.IsNullOrEmpty(_currentTask.AviSynthScript)) { var avs = new AviSynthGenerator(_appConfig); _currentTask.AviSynthScript = avs.Generate(_currentTask.VideoStream, changeFps, targetFps, resizeTo, StereoEncoding.None, new StereoVideoInfo(), true, subFile, keepOnlyForced, false); } #endregion #region bitrate calculation var bitrate = _currentTask.EncodingProfile.TargetFileSize > 1 ? VideoHelper.CalculateVideoBitrate(_currentTask) : _encProfile.Bitrate; var audBitrate = _currentTask.AudioStreams.Sum(stream => (int)stream.Bitrate / 1000); var maxRate = 9800 - audBitrate; #endregion _encodingPass = _encProfile.EncodingMode == 0 ? 0 : _currentTask.StreamId; var targetSysStr = targetSys == 0 ? "pal" : "ntsc"; sb.Append($" -i \"{_currentTask.AviSynthScript}\" -map 0:v"); sb.Append($" -target {targetSysStr}-dvd"); sb.Append($" -b:v {bitrate:0}k -maxrate {maxRate:0}k -qmin 1"); sb.Append($" -aspect {sourceAspect:0.000}".ToString(_appConfig.CInfo)); if (_encodingPass > 0) { sb.Append($" -pass {_encodingPass:0}"); } if (_encProfile.MbDecision > 0) { sb.Append($" -mbd {mbdArray[_encProfile.MbDecision]}"); } if (_encProfile.Trellis > 0) { sb.Append($" -trellis {_encProfile.Trellis:0}"); } if (_encProfile.Cmp > 0) { sb.Append($" -cmp {cmpArray[_encProfile.Cmp]}"); } if (_encProfile.SubCmp > 0) { sb.Append($" -subcmp {cmpArray[_encProfile.SubCmp]}"); } if (_encProfile.DcPrecision > 0) { sb.Append($" -dc {_encProfile.DcPrecision}"); } if (_encProfile.ClosedGops) { sb.Append(" -flags cgop -mpv_flags strict_gop -sc_threshold 1000000000"); } if (!_encProfile.AutoGop) { sb.Append($" -g {_encProfile.GopLength:0}"); } sb.Append($" -f rawvideo -y \"{_outputFile}\""); return(sb.ToString()); }
// TODO: Get App Versions /// <summary> /// Read encoder versions /// </summary> /// <param name="encPath">Location of encoder executables</param> /// <param name="javaPath">Path to java.exe</param> public void GetAppVersions(string encPath = "", string javaPath = "") { if (string.IsNullOrEmpty(encPath)) { encPath = _configService.ToolsPath; } if (string.IsNullOrEmpty(javaPath)) { javaPath = _configService.JavaInstallPath; } _configService.Lasteac3ToVer = DemuxerEac3To.GetVersionInfo(encPath); _configService.LastMplayerVer = DemuxerMplayer.GetVersionInfo(encPath); _configService.LastffmpegVer = DemuxerFfmpeg.GetVersionInfo(encPath, false); _configService.LastLameVer = EncoderLame.GetVersionInfo(encPath, false); _configService.Lastx264Ver = EncoderX264.GetVersionInfo(encPath, false); _configService.LastMKVMergeVer = MuxerMkvMerge.GetVersionInfo(encPath); _configService.LastDVDAuthorVer = MuxerDvdAuthor.GetVersionInfo(encPath); _configService.LastMp4BoxVer = MuxerMp4Box.GetVersionInfo(encPath); _configService.LastMJPEGToolsVer = MuxerMplex.GetVersionInfo(encPath); if (!string.IsNullOrEmpty(javaPath)) { _configService.LastBDSup2SubVer = EncoderBdSup2Sub.GetVersionInfo(encPath, javaPath); } if (Environment.Is64BitOperatingSystem && _configService.Use64BitEncoders) { _configService.Lastx26464Ver = EncoderX264.GetVersionInfo(encPath, true); _configService.Lastffmpeg64Ver = DemuxerFfmpeg.GetVersionInfo(encPath, true); _configService.LastLame64Ver = EncoderLame.GetVersionInfo(encPath, true); } _configService.LastOggEncVer = EncoderOggEnc.GetVersionInfo(encPath, false, _configService); if (_configService.UseOptimizedEncoders) { _configService.LastOggEncLancerVer = EncoderOggEnc.GetVersionInfo(encPath, true, _configService); } _configService.LastNeroAacEncVer = EncoderNeroAac.GetVersionInfo(encPath); _configService.LastTSMuxerVer = MuxerTsMuxeR.GetVersionInfo(encPath); //LsDvd lsdvd = new LsDvd(); //ConfigService.LastlsdvdVer = lsdvd.GetVersionInfo(encPath); //HcEnc hcenc = new HcEnc(); //ConfigService.LastHcEncVer = hcenc.GetVersionInfo(encPath); //VpxEnc vpxEnc = new VpxEnc(); //ConfigService.LastVpxEncVer = vpxEnc.GetVersionInfo(encPath); //XvidEnc xvidEnc = new XvidEnc(); //string myVer = xvidEnc.GetVersionInfo(encPath); #region Get AviSynth Version var graphBuilder = (IGraphBuilder) new FilterGraph(); var avsFile = new AviSynthGenerator(_configService).GenerateTestFile(); // workaround for crashes while in debug mode var result = 0; if (!Debugger.IsAttached) { try { result = graphBuilder.RenderFile(avsFile, null); graphBuilder.Abort(); graphBuilder = null; } catch (Exception ex) { Log.Error(ex); } } Log.Debug($"RenderFile Result: {result}"); if (result < 0 && !Debugger.IsAttached) { Log.Debug("AviSynth is not installed"); } else { var ver = FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "avisynth.dll")); var appVer = $"{ver.FileMajorPart:0}.{ver.FileMinorPart:0}.{ver.FileBuildPart:0}.{ver.FilePrivatePart:0}"; Log.Debug($"Avisynth version {appVer} installed"); _configService.LastAviSynthVer = appVer; } try { File.Delete(avsFile); } catch (Exception ex) { Log.Error(ex.InnerException); } #endregion GetAviSynthPluginsVer(); GetUpdaterVersion(); _configService.UpdateVersions = false; }
private string GenerateCommandLine() { int[] bitrateList = { 64, 128, 160, 192, 224, 256, 288, 320, 352, 384, 448, 512, 576, 640 }; int[] sampleRateArr = { 0, 8000, 11025, 22050, 44100, 48000 }; int[] channelArr = { 0, 2, 3, 4, 1 }; _audio = _currentTask.AudioStreams[_currentTask.StreamId]; _audioProfile = (Ac3Profile)_currentTask.AudioProfile; var sb = new StringBuilder(); var outChannels = -1; var outSampleRate = -1; var bitrate = 0; var channels = 0; var drc = false; switch (_currentTask.AudioProfile.Type) { case ProfileType.Ac3: outChannels = _audioProfile.OutputChannels; channels = _audioProfile.OutputChannels; outChannels = channelArr[outChannels]; if (_audio.ChannelCount > 6) { outChannels = 6; } outSampleRate = _audioProfile.SampleRate; outSampleRate = sampleRateArr[outSampleRate]; bitrate = _audioProfile.Bitrate; bitrate = bitrateList[bitrate]; drc = _audioProfile.ApplyDynamicRangeCompression; break; case ProfileType.Copy: outChannels = _audio.ChannelCount > 6 ? 6 : _audio.ChannelCount; channels = _audioProfile.OutputChannels; outSampleRate = _audio.SampleRate; bitrate = _audioProfile.Bitrate; if (_currentTask.EncodingProfile.OutFormat == OutputType.OutputDvd && (outSampleRate != 48000 || bitrate > 10)) { outSampleRate = 48000; if (bitrate > 10) { bitrate = 10; } } break; } var avs = new AviSynthGenerator(_appConfig); _inputFile = avs.GenerateAudioScript(_audio.TempFile, _audio.Format, _audio.FormatProfile, _audio.ChannelCount, outChannels, _audio.SampleRate, outSampleRate); _outputFile = FileSystemHelper.CreateTempFile(_appConfig.DemuxLocation, _audio.TempFile, "encoded.ac3"); sb.Append($"-f wav -i \"{_appConfig.EncodeNamedPipeFullName}\" -c:a ac3"); sb.Append($" -b:a {bitrate:0}k"); if (channels == 2 || channels == 3) { sb.Append(" -dsur_mode 1"); } if (drc) { sb.Append(" -dialnorm -27"); } sb.Append($" -vn -y \"{_outputFile}\""); return(sb.ToString()); }
public static void GetAppVersions(string encPath = "", string javaPath = "") { if (String.IsNullOrEmpty(encPath)) { encPath = AppSettings.ToolsPath; } if (String.IsNullOrEmpty(javaPath)) { javaPath = AppSettings.JavaInstallPath; } X264 x264Enc = new X264(); AppSettings.Lastx264Ver = x264Enc.GetVersionInfo(encPath, false); if (Environment.Is64BitOperatingSystem) { AppSettings.Lastx26464Ver = x264Enc.GetVersionInfo(encPath, true); } FfMpeg ffmpeg = new FfMpeg(); AppSettings.LastffmpegVer = ffmpeg.GetVersionInfo(encPath, false); if (Environment.Is64BitOperatingSystem) { AppSettings.Lastffmpeg64Ver = ffmpeg.GetVersionInfo(encPath, true); } Eac3To eac3To = new Eac3To(); AppSettings.Lasteac3ToVer = eac3To.GetVersionInfo(encPath); LsDvd lsdvd = new LsDvd(); AppSettings.LastlsdvdVer = lsdvd.GetVersionInfo(encPath); MkvMerge mkvMerge = new MkvMerge(); AppSettings.LastMKVMergeVer = mkvMerge.GetVersionInfo(encPath); MPlayer mplayer = new MPlayer(); AppSettings.LastMplayerVer = mplayer.GetVersionInfo(encPath); TsMuxeR tsmuxer = new TsMuxeR(); AppSettings.LastTSMuxerVer = tsmuxer.GetVersionInfo(encPath); MJpeg mjpeg = new MJpeg(); AppSettings.LastMJPEGToolsVer = mjpeg.GetVersionInfo(encPath); DvdAuthor dvdauthor = new DvdAuthor(); AppSettings.LastDVDAuthorVer = dvdauthor.GetVersionInfo(encPath); MP4Box mp4Box = new MP4Box(); AppSettings.LastMp4BoxVer = mp4Box.GetVersionInfo(encPath); HcEnc hcenc = new HcEnc(); AppSettings.LastHcEncVer = hcenc.GetVersionInfo(encPath); OggEnc ogg = new OggEnc(); AppSettings.LastOggEncVer = ogg.GetVersionInfo(encPath, false); if (AppSettings.UseOptimizedEncoders) { AppSettings.LastOggEncLancerVer = ogg.GetVersionInfo(encPath, true); } NeroAACEnc aac = new NeroAACEnc(); AppSettings.LastNeroAacEncVer = aac.GetVersionInfo(encPath); Lame lame = new Lame(); AppSettings.LastLameVer = lame.GetVersionInfo(encPath); VpxEnc vpxEnc = new VpxEnc(); AppSettings.LastVpxEncVer = vpxEnc.GetVersionInfo(encPath); XvidEnc xvidEnc = new XvidEnc(); string myVer = xvidEnc.GetVersionInfo(encPath); if (!String.IsNullOrEmpty(javaPath)) { BdSup2SubTool bdSup2Sub = new BdSup2SubTool(); AppSettings.LastBDSup2SubVer = bdSup2Sub.GetVersionInfo(encPath, javaPath); } #region Get AviSynth Version IGraphBuilder graphBuilder = (IGraphBuilder) new FilterGraph(); string avsFile = AviSynthGenerator.GenerateTestFile(); int result = graphBuilder.RenderFile(avsFile, null); Log.DebugFormat("RenderFile Result: {0}", result); if (result < 0) { Log.Debug("AviSynth is not installed"); } else { FileVersionInfo ver = FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "avisynth.dll")); string appVer = String.Format("{0:g}.{1:g}.{2:g}.{3:g}", ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart); Log.DebugFormat("Avisynth version {0:s} installed", appVer); AppSettings.LastAviSynthVer = appVer; } File.Delete(avsFile); #endregion GetAviSynthPluginsVer(); GetUpdaterVersion(); AppSettings.UpdateVersions = false; AppSettings.SaveSettings(); }