private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (encoderProcess != null) { try { IsAborted = true; if (!encoderProcess.HasExited) { encoderProcess.Kill(); encoderProcess.WaitForExit(); } } catch { } } if (avs != null && avs.IsBusy()) { IsAborted = false; e.Cancel = true; } if (IsAborted || IsErrors) { SafeDelete(outfile); } }
private void ExtractSound() { //удаляем старый файл SafeDelete(outfile); //создаём кодер avs = new AviSynthEncoder(m, m.script, outfile); //запускаем кодер avs.start(); //Выводим прогресс double total_frames = (m.outframes != 0) ? m.outframes : m.inframes; //Определяем количество кадров while (avs.IsBusy()) { double p = ((double)(avs.frame) / total_frames) * 100.0; worker.ReportProgress((int)p); Thread.Sleep(100); } //Ловим ошибки, если они были if (avs.IsErrors) { AppendEncoderText(avs.error_text); avs = null; throw new Exception(encodertext.ToString()); } //чистим ресурсы avs = null; }
private void CloseEncoder(bool _null) { lock (locker) { if (avs != null) { if (avs.IsBusy()) { avs.stop(); } if (_null) { avs = null; } } } }
private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { //определяем аудио потоки AudioStream instream = (AudioStream)m.inaudiostreams[m.inaudiostream]; script = AviSynthScripting.GetInfoScript(m, AviSynthScripting.ScriptMode.Normalize); script += Environment.NewLine + "Trim(0, " + vtrim + ")"; avs = new AviSynthEncoder(m, script); //Запускаем анализ avs.start(); //Выводим прогресс while (avs.IsBusy()) { if (worker.CancellationPending) { avs.stop(); } else if (avs.frame > 0) { worker.ReportProgress(avs.frame); } Thread.Sleep(100); } //Результаты if (!worker.CancellationPending) { if (!avs.IsErrors) { instream.gain = avs.gain.ToString("##0.000").Replace(",", "."); if (instream.gain == "0.000") { instream.gain = "0.0"; } instream.gaindetected = true; } else { instream.gain = "0.0"; instream.gaindetected = false; throw new Exception(avs.error_text, avs.exception_raw); } } } catch (Exception ex) { if (worker != null && !worker.CancellationPending && m != null && num_closes == 0) { //Ошибка ex.HelpLink = script; e.Result = ex; } } finally { CloseEncoder(true); } }
private void make_sound() { step++; if (m.format == Format.ExportFormats.Audio) SafeDelete(m.outfilepath); //определяем аудио потоки AudioStream instream = (AudioStream)m.inaudiostreams[m.inaudiostream]; AudioStream outstream = (AudioStream)m.outaudiostreams[m.outaudiostream]; //не делаем ничего со звуком если можно смонтировать напрямую //Если dontmuxstream, то все-же извлекаем звук сдесь, т.к. стадии муксинга не будет if (IsDirectRemuxingPossible && outstream.codec == "Copy" && !DontMuxStreams) { if (File.Exists(outstream.audiopath) && new FileInfo(outstream.audiopath).Length != 0) { SetLog(Languages.Translate("Using already created file") + ": " + outstream.audiopath + Environment.NewLine); } return; } //кодируем только звук if (m.vencoding == "Disabled") outstream.audiopath = m.outfilepath; string ext = Path.GetExtension(m.infilepath).ToLower(); if (outstream.codec == "Copy" && ext == ".pmp") return; string aext; if (outstream.codec == "Copy") aext = Format.GetValidRAWAudioEXT(instream.codecshort); else aext = Format.GetValidRAWAudioEXT(outstream.codec); //if (outstream.audiopath == null) // outstream.audiopath = Settings.TempPath + "\\" + m.key + aext; if (DontMuxStreams) { outstream.audiopath = Calculate.RemoveExtention(m.outfilepath, true) + (m.format == Format.ExportFormats.BluRay ? "\\" + m.key : "") + //Кодирование в папку Path.GetExtension(outstream.audiopath); } //подхватываем готовый файл if (outstream.codec == "Copy" && File.Exists(instream.audiopath)) { if (DontMuxStreams) { IsNoProgressStage = true; //Копируем существующий файл в нужное место SetLog(Languages.Translate("Using already created file") + ": " + instream.audiopath); SetLog(Languages.Translate("Copying it to") + ": " + outstream.audiopath); SetLog(Languages.Translate("Please wait") + "...\r\n"); File.Copy(instream.audiopath, outstream.audiopath); return; } else outstream.audiopath = instream.audiopath; } if (m.vencoding != "Disabled") { if (File.Exists(outstream.audiopath) && new FileInfo(outstream.audiopath).Length != 0) { SetLog(Languages.Translate("Using already created file") + ": " + outstream.audiopath + Environment.NewLine); return; } } //Извлекаем звук для Copy if (outstream.codec == "Copy" && !File.Exists(instream.audiopath)) { if (aext == ".wav") { ExtractSound(); } else { Format.Demuxers dem = Format.GetDemuxer(m); if (dem == Format.Demuxers.mkvextract) demux_mkv(Demuxer.DemuxerMode.ExtractAudio); else if (dem == Format.Demuxers.pmpdemuxer) demux_pmp(Demuxer.DemuxerMode.ExtractAudio); else if (dem == Format.Demuxers.mp4box) demux_mp4box(Demuxer.DemuxerMode.ExtractAudio); else demux_ffmpeg(Demuxer.DemuxerMode.ExtractAudio); } return; } //Подменяем расширение для кодирования ААС (NeroEncAac кодирует в .m4a) if (Path.GetExtension(outstream.audiopath) == ".aac") outstream.audiopath = Calculate.RemoveExtention(outstream.audiopath, true) + ".m4a"; busyfile = Path.GetFileName(outstream.audiopath); bool TwoPassAAC = false; SetLog("Encoding audio to: " + outstream.audiopath); if (outstream.codec == "MP3" && m.mp3_options.encodingmode == Settings.AudioEncodingModes.VBR) SetLog(outstream.codec + " Q" + m.mp3_options.quality + " " + outstream.channels + "ch " + outstream.bits + "bit " + outstream.samplerate + "khz"); else if (outstream.codec == "FLAC") SetLog(outstream.codec + " Q" + m.flac_options.level + " " + outstream.channels + "ch " + outstream.bits + "bit " + outstream.samplerate + "khz"); else if (outstream.codec == "AAC" && m.aac_options.encodingmode == Settings.AudioEncodingModes.TwoPass) { SetLog(outstream.codec + " " + outstream.bitrate + "kbps 2pass " + outstream.channels + "ch " + outstream.bits + "bit " + outstream.samplerate + "khz"); TwoPassAAC = true; } else if (outstream.codec == "AAC" && m.aac_options.encodingmode == Settings.AudioEncodingModes.VBR) SetLog(outstream.codec + " Q" + m.aac_options.quality + " " + outstream.channels + "ch " + outstream.bits + "bit " + outstream.samplerate + "khz"); else if (outstream.codec == "QAAC" && m.qaac_options.encodingmode == Settings.AudioEncodingModes.VBR) SetLog(outstream.codec + " Q" + m.qaac_options.quality + " " + outstream.channels + "ch " + outstream.bits + "bit " + outstream.samplerate + "khz"); else if (outstream.codec == "QAAC" && m.qaac_options.encodingmode == Settings.AudioEncodingModes.ALAC) SetLog(outstream.codec + " Lossless " + outstream.channels + "ch " + outstream.bits + "bit " + outstream.samplerate + "khz"); else SetLog(outstream.codec + " " + outstream.bitrate + "kbps " + outstream.channels + "ch " + outstream.bits + "bit " + outstream.samplerate + "khz"); //удаляем старый файл SafeDelete(outstream.audiopath); //создаём кодер if (outstream.codec == "LPCM" && outstream.channels > 2 || outstream.codec == "PCM" && outstream.channels > 2) { make_ffmpeg_audio(); //прямое кодирование через ffmpeg (не совсем понятно, зачем оно нужно) } else if (TwoPassAAC) { two_pass_aac(); //Двухпроходный AAC } else { avs = new AviSynthEncoder(m); if (outstream.codec == "AAC") { if (m.format == Format.ExportFormats.PmpAvc) avs.encoderPath = Calculate.StartupPath + "\\apps\\neroAacEnc_pmp\\neroAacEnc.exe"; else avs.encoderPath = Calculate.StartupPath + "\\apps\\neroAacEnc\\neroAacEnc.exe"; } else if (outstream.codec == "QAAC") avs.encoderPath = Calculate.StartupPath + "\\apps\\qaac\\qaac.exe"; else if (outstream.codec == "MP3") avs.encoderPath = Calculate.StartupPath + "\\apps\\lame\\lame.exe"; else if (outstream.codec == "MP2" || outstream.codec == "PCM" || outstream.codec == "LPCM" || outstream.codec == "FLAC") avs.encoderPath = Calculate.StartupPath + "\\apps\\ffmpeg\\ffmpeg.exe"; else if (outstream.codec == "AC3") avs.encoderPath = Calculate.StartupPath + "\\apps\\aften\\aften.exe"; //запускаем кодер avs.start(); //прописываем аргументы командной строки while (avs.args == null && !avs.IsErrors) Thread.Sleep(50); SetLog(""); if (Settings.ArgumentsToLog) { SetLog(Path.GetFileName(avs.encoderPath) + ": " + avs.args); SetLog(""); } //Вывод прогресса кодирования while (avs.IsBusy()) { worker.ReportProgress(avs.frame); Thread.Sleep(100); } if (avs.IsErrors) { string error_txt = avs.error_text; avs = null; throw new Exception(error_txt); } //обнуляем прогресс ResetProgress(); //чистим ресурсы avs = null; } SetLog(""); if (IsAborted || IsErrors) return; //проверка на удачное завершение if (!File.Exists(outstream.audiopath) || new FileInfo(outstream.audiopath).Length == 0) { throw new Exception(Languages.Translate("Can`t find output audio file!")); } //Похоже, что tsMuxeR уже умеет принимать m4a на вход.. //if (muxer == Format.Muxers.tsmuxer && (outstream.codec == "AAC" || outstream.codec == "QAAC")) // make_aac(); }
private void ExtractSound() { //определяем аудио потоки AudioStream outstream = (AudioStream)m.outaudiostreams[m.outaudiostream]; SetLog("Decoding audio stream to: " + outstream.audiopath + "\r\n"); //удаляем старый файл SafeDelete(outstream.audiopath); //создаём кодер avs = new AviSynthEncoder(m); //запускаем кодер avs.start(); //извлекаем кусок на ext_frames фреймов while (avs.IsBusy()) { worker.ReportProgress(avs.frame); Thread.Sleep(100); } //Ловим ошибки, если они были if (avs.IsErrors) { ErrorException(avs.error_text); } else { //Задержка уже была в скрипте, и звук декодировался вместе с ней CopyDelay = false; } //чистим ресурсы avs = null; }
private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { //определяем аудио потоки AudioStream instream = (AudioStream)m.inaudiostreams[m.inaudiostream]; script = AviSynthScripting.GetInfoScript(m, AviSynthScripting.ScriptMode.Normalize); script += Environment.NewLine + "Trim(0, " + vtrim + ")"; avs = new AviSynthEncoder(m, script); //Запускаем анализ avs.start(); //Выводим прогресс while (avs.IsBusy()) { if (worker.CancellationPending) avs.stop(); else if (avs.frame > 0) worker.ReportProgress(avs.frame); Thread.Sleep(100); } //Результаты if (!worker.CancellationPending) { if (!avs.IsErrors) { instream.gain = avs.gain.ToString("##0.000").Replace(",", "."); if (instream.gain == "0.000") instream.gain = "0.0"; instream.gaindetected = true; } else { instream.gain = "0.0"; instream.gaindetected = false; throw new Exception(avs.error_text, avs.exception_raw); } } } catch (Exception ex) { if (worker != null && !worker.CancellationPending && m != null && num_closes == 0) { //Ошибка ex.HelpLink = script; e.Result = ex; } } finally { CloseEncoder(true); } }