private void AddExternalTrack(string infilepath) { //получаем медиа информацию MediaInfoWrapper mi = null; FFInfo ff = null; try { AudioStream stream = null; int old_stream = 0; string ext = Path.GetExtension(infilepath).ToLower(); if (ext != ".avs" && ext != ".grf") { mi = new MediaInfoWrapper(); stream = mi.GetAudioInfoFromAFile(infilepath, false); stream.mi_order = mi.ATrackOrder(0); stream.mi_id = mi.ATrackID(0); ff = new FFInfo(); ff.Open(infilepath); //Аналогично тому, как сделано в Informer'е if (ff.AudioStreams().Count > 0) { stream.ff_order = ff.FirstAudioStreamID(); stream.ff_order_filtered = ff.FilteredStreamOrder(stream.ff_order); if (stream.mi_order < 0) stream.mi_order = stream.ff_order; if (stream.bitrate == 0) stream.bitrate = ff.AudioBitrate(stream.ff_order); if (stream.channels == 0) stream.channels = ff.StreamChannels(stream.ff_order); if (stream.samplerate == null) stream.samplerate = ff.StreamSamplerate(stream.ff_order); if (stream.language == "Unknown") stream.language = ff.StreamLanguage(stream.ff_order); stream.ff_bits = ff.StreamBits(stream.ff_order); //if (stream.bits == 0) stream.bits = stream.ff_bits; stream.ff_codec = ff.StreamCodec(stream.ff_order); if (stream.codec == "A_MS/ACM" || stream.codec == "") { stream.codec = stream.ff_codec; stream.codecshort = ff.StreamCodecShort(stream.ff_order); } } } else { stream = new AudioStream(); stream.audiopath = infilepath; stream.audiofiles = new string[] { stream.audiopath }; stream.codec = stream.codecshort = "PCM"; stream.language = "Unknown"; } //Добавляем этот трек old_stream = m.inaudiostream; stream = Format.GetValidADecoder(stream); m.inaudiostream = m.inaudiostreams.Count; m.inaudiostreams.Add(stream.Clone()); //Оставшаяся инфа + ошибки Caching cach = new Caching(m, true); if (cach.m == null) { //Удаляем этот трек m.inaudiostream = old_stream; m.inaudiostreams.RemoveAt(m.inaudiostreams.Count - 1); return; } m = cach.m.Clone(); textbox_apath.Text = infilepath; //разрешаем формы group_channels.IsEnabled = true; group_delay.IsEnabled = true; group_samplerate.IsEnabled = true; group_volume.IsEnabled = true; //прописываем в список внешний трек ComboBoxItem item = new ComboBoxItem(); stream = (AudioStream)m.inaudiostreams[m.inaudiostream]; //Переопределяем с новыми параметрами item.Content = (combo_atracks.Items.Count + 1).ToString("00") + ". " + stream.language + " " + stream.codecshort + " " + stream.channels + "ch"; item.ToolTip = item.Content + " " + stream.samplerate + "Hz " + stream.bitrate + "kbps " + stream.delay + "ms"; combo_atracks.Items.Add(item); combo_atracks.SelectedIndex = combo_atracks.Items.Count - 1; } catch (Exception ex) { ErrorException("AddExternalTrack: " + ex.Message, ex.StackTrace); return; } finally { if (mi != null) { mi.Close(); mi = null; } if (ff != null) { ff.Close(); ff = null; } } AudioStream newstream = new AudioStream(); m.outaudiostreams.Clear(); m.outaudiostreams.Add(newstream); AudioStream outstream = (AudioStream)m.outaudiostreams[m.outaudiostream]; //забиваем аудио настройки outstream.encoding = Settings.GetAEncodingPreset(Settings.FormatOut); outstream.codec = PresetLoader.GetACodec(m.format, outstream.encoding); outstream.passes = PresetLoader.GetACodecPasses(m); m = Format.GetValidSamplerate(m); //определяем битность m = Format.GetValidBits(m); //определяем колличество каналов m = Format.GetValidChannelsConverter(m); m = Format.GetValidChannels(m); //проверяем можно ли копировать данный формат if (outstream.codec == "Copy") { AudioStream instream = (AudioStream)m.inaudiostreams[m.inaudiostream]; outstream.audiopath = instream.audiopath; outstream.bitrate = instream.bitrate; string CopyProblems = Format.ValidateCopyAudio(m); if (CopyProblems != null) { Message mess = new Message(this); mess.ShowMessage(Languages.Translate("The stream contains parameters incompatible with this format") + " " + Format.EnumToString(m.format) + ": " + CopyProblems + "." + Environment.NewLine + Languages.Translate("(You see this message because audio encoder = Copy)"), Languages.Translate("Warning")); } } else { string aext = Format.GetValidRAWAudioEXT(outstream.codec); outstream.audiopath = Settings.TempPath + "\\" + m.key + aext; } SetAudioOptions(); SetInfo(); }
private void AddExternalTrack(string infilepath) { //получаем медиа информацию MediaInfoWrapper mi = null; FFInfo ff = null; try { AudioStream stream = null; int old_stream = 0; string ext = Path.GetExtension(infilepath).ToLower(); if (ext != ".avs" && ext != ".grf") { mi = new MediaInfoWrapper(); stream = mi.GetAudioInfoFromAFile(infilepath, false); stream.mi_order = mi.ATrackOrder(0); stream.mi_id = mi.ATrackID(0); ff = new FFInfo(); ff.Open(infilepath); //Аналогично тому, как сделано в Informer'е if (ff.AudioStreams().Count > 0) { stream.ff_order = ff.FirstAudioStreamID(); stream.ff_order_filtered = ff.FilteredStreamOrder(stream.ff_order); if (stream.mi_order < 0) { stream.mi_order = stream.ff_order; } if (stream.bitrate == 0) { stream.bitrate = ff.AudioBitrate(stream.ff_order); } if (stream.channels == 0) { stream.channels = ff.StreamChannels(stream.ff_order); } if (stream.samplerate == null) { stream.samplerate = ff.StreamSamplerate(stream.ff_order); } if (stream.language == "Unknown") { stream.language = ff.StreamLanguage(stream.ff_order); } stream.ff_bits = ff.StreamBits(stream.ff_order); //if (stream.bits == 0) stream.bits = stream.ff_bits; stream.ff_codec = ff.StreamCodec(stream.ff_order); if (stream.codec == "A_MS/ACM" || stream.codec == "") { stream.codec = stream.ff_codec; stream.codecshort = ff.StreamCodecShort(stream.ff_order); } } } else { stream = new AudioStream(); stream.audiopath = infilepath; stream.audiofiles = new string[] { stream.audiopath }; stream.codec = stream.codecshort = "PCM"; stream.language = "Unknown"; } //Добавляем этот трек old_stream = m.inaudiostream; stream = Format.GetValidADecoder(stream); m.inaudiostream = m.inaudiostreams.Count; m.inaudiostreams.Add(stream.Clone()); //Оставшаяся инфа + ошибки Caching cach = new Caching(m, true); if (cach.m == null) { //Удаляем этот трек m.inaudiostream = old_stream; m.inaudiostreams.RemoveAt(m.inaudiostreams.Count - 1); return; } m = cach.m.Clone(); textbox_apath.Text = infilepath; //разрешаем формы group_channels.IsEnabled = true; group_delay.IsEnabled = true; group_samplerate.IsEnabled = true; group_volume.IsEnabled = true; //прописываем в список внешний трек ComboBoxItem item = new ComboBoxItem(); stream = (AudioStream)m.inaudiostreams[m.inaudiostream]; //Переопределяем с новыми параметрами item.Content = (combo_atracks.Items.Count + 1).ToString("00") + ". " + stream.language + " " + stream.codecshort + " " + stream.channels + "ch"; item.ToolTip = item.Content + " " + stream.samplerate + "Hz " + stream.bitrate + "kbps " + stream.delay + "ms"; combo_atracks.Items.Add(item); combo_atracks.SelectedIndex = combo_atracks.Items.Count - 1; } catch (Exception ex) { ErrorException("AddExternalTrack: " + ex.Message, ex.StackTrace); return; } finally { if (mi != null) { mi.Close(); mi = null; } if (ff != null) { ff.Close(); ff = null; } } AudioStream newstream = new AudioStream(); m.outaudiostreams.Clear(); m.outaudiostreams.Add(newstream); AudioStream outstream = (AudioStream)m.outaudiostreams[m.outaudiostream]; //забиваем аудио настройки outstream.encoding = Settings.GetAEncodingPreset(Settings.FormatOut); outstream.codec = PresetLoader.GetACodec(m.format, outstream.encoding); outstream.passes = PresetLoader.GetACodecPasses(m); m = Format.GetValidSamplerate(m); //определяем битность m = Format.GetValidBits(m); //определяем колличество каналов m = Format.GetValidChannelsConverter(m); m = Format.GetValidChannels(m); //проверяем можно ли копировать данный формат if (outstream.codec == "Copy") { AudioStream instream = (AudioStream)m.inaudiostreams[m.inaudiostream]; outstream.audiopath = instream.audiopath; outstream.bitrate = instream.bitrate; string CopyProblems = Format.ValidateCopyAudio(m); if (CopyProblems != null) { Message mess = new Message(this); mess.ShowMessage(Languages.Translate("The stream contains parameters incompatible with this format") + " " + Format.EnumToString(m.format) + ": " + CopyProblems + "." + Environment.NewLine + Languages.Translate("(You see this message because audio encoder = Copy)"), Languages.Translate("Warning")); } } else { string aext = Format.GetValidRAWAudioEXT(outstream.codec); outstream.audiopath = Settings.TempPath + "\\" + m.key + aext; } SetAudioOptions(); SetInfo(); }