public static MediaContainer DetectContainerByExt(string fileName) { var ext = System.IO.Path.GetExtension(fileName).ToLower(); if (!String.IsNullOrEmpty(ext) && ext.Length > 1) { ext = ext.Substring(1); } // loop ExtensionList in each container foreach (var cont in MediaConvertGUIConfiguration.Containers) { foreach (var e in cont.ExtensionList) { if (e.ToLower() == ext.ToLower()) { return(cont); } } } // default ext var c = MediaConvertGUIConfiguration.GetContainerByExt(ext); if (c != null) { return(c); } return(MediaConvertGUIConfiguration.GetContainerByName("none")); }
public void Fill() { if (_eventLock.Lock()) { if (Info != null) { if (Editable) { SupportMethods.FillComboBox(comboContainer, MediaConvertGUIConfiguration.ContainersAsList(true), Editable, Info.TargetContainer.Name); } else { SupportMethods.FillComboBox(comboContainer, new List <string>() { Info.TargetContainer.Name }, Editable, Info.TargetContainer.Name); } } else { SupportMethods.ClearCombo(comboContainer); } imageContainer.Visible = comboContainer.Active > 0; _eventLock.Unlock(); } }
public void Clear() { TargetVideoCodec = MediaConvertGUIConfiguration.GetVideoCodecByName("copy"); TargetContainer = MediaConvertGUIConfiguration.DefaultContainer; AutoRotate = false; Tracks.Clear(); FileSize = 0; }
protected void OnContainerEventBoxButtonPressEvent(object o, ButtonPressEventArgs args) { if (Editable && Info != null && comboContainer.Active > 0) { var container = MediaConvertGUIConfiguration.GetContainerByName(comboContainer.ActiveText); if (!String.IsNullOrEmpty(container.Link)) { SupportMethods.ExecuteInShell(container.Link); } } }
protected void OnCodecEventBoxButtonPressEvent(object o, ButtonPressEventArgs args) { if (Editable && MovieInfo != null && comboCodec.Active > 0) { var codec = MediaConvertGUIConfiguration.GetVideoCodecByName(comboCodec.ActiveText); if (!string.IsNullOrEmpty(codec.Link)) { SupportMethods.ExecuteInShell(codec.Link); } } }
private void OnAnyValueChanged() { if (Editable && Info != null) { if (_eventLock.Lock()) { Info.TargetContainer = MediaConvertGUIConfiguration.GetContainerByName(comboContainer.ActiveText); _eventLock.Unlock(); Fill(); } } }
public void Clear() { Codec = String.Empty; Aspect = "0x0"; Bitrate = 0; Channels = 0; TrackType = String.Empty; FrameRate = 0; SamplingRateHz = 0; Width = RealWidth; PixelAspect = 1; Height = Height; DurationMS = DurationMS; TargetAudioCodec = MediaConvertGUIConfiguration.GetAudioCodecByName("none"); RotatationAngle = 0; }
public void Fill() { if (_eventLock.Lock()) { var activeTrack = SelectedTrack; var activeTrackAsString = String.Empty; // filling tracks combo var trackStrings = new List <string>(); if (Info != null && Info.AudioTracks.Count > 0) { foreach (var kvp in Info.AudioTracks) { trackStrings.Add(kvp.Key.ToString()); if ((activeTrack == kvp.Value)) { activeTrackAsString = kvp.Key.ToString(); } } } SupportMethods.FillComboBox(comboTracks, trackStrings, true, activeTrackAsString); // filling selected track if (activeTrack != null) { // channels var channelsStrings = new List <string>() { "1", "2" }; var activeChannelAsString = ""; if ((activeTrack.Channels == 1) || (activeTrack.Channels == 2)) { activeChannelAsString = activeTrack.Channels.ToString(); } SupportMethods.FillComboBox(comboChannels, channelsStrings, Editable, activeChannelAsString); // codec if (Editable) { frameAudioOptions.Visible = (activeTrack.TargetAudioCodec.Name != "none") && (activeTrack.TargetAudioCodec.Name != "copy"); SupportMethods.FillComboBox(comboCodec, MediaConvertGUIConfiguration.AudioCodecsAsList(true), true, activeTrack.TargetAudioCodec.Name); } else { frameAudioOptions.Visible = true; SupportMethods.FillComboBox(comboCodec, new List <string>() { activeTrack.Codec }, false, activeTrack.Codec); } SupportMethods.FillComboBoxEntry(comboSampleRate, MediaConvertGUIConfiguration.DefaultSamplingRates, activeTrack.SamplingRateHz, Editable); SupportMethods.FillComboBoxEntry(comboBitrate, MediaConvertGUIConfiguration.DefaultAudioBitrates, activeTrack.BitrateKbps, Editable); labelTrackSze.Text = activeTrack.HumanReadableStreamSize; } else { SupportMethods.ClearCombo(comboChannels); SupportMethods.ClearCombo(comboCodec); SupportMethods.ClearCombo(comboBitrate); SupportMethods.ClearCombo(comboSampleRate); frameAudioOptions.Visible = false; labelTrackSze.Text = String.Empty; } image.Visible = comboCodec.Active > 0; _eventLock.Unlock(); } }
private void OnAnyValueChanged() { if (Editable && MovieInfo != null && MovieInfo.FirstVideoTrack != null) { if (_eventLock.Lock()) { var m = MovieInfo.FirstVideoTrack; // reactivating disabled? if (chBoxResolution.Active && !MovieInfo.EditResolution) { entryWidth.Text = m.Width.ToString(); entryHeight.Text = m.Height.ToString(); } if (chBoxBitRate.Active && !MovieInfo.EditBitRate) { comboBitRate.Entry.Text = (m.BitrateKbps).ToString(); } if (chBoxAspect.Active && !MovieInfo.EditAspect) { comboAspect.Entry.Text = m.Aspect; } if (chBoxFrameRate.Active && !MovieInfo.EditFrameRate) { comboFrameRate.Entry.Text = m.FrameRate.ToString(); } MovieInfo.EditResolution = chBoxResolution.Active; MovieInfo.EditAspect = chBoxAspect.Active; MovieInfo.EditBitRate = chBoxBitRate.Active; MovieInfo.EditFrameRate = chBoxFrameRate.Active; if (chBoxBitRate.Active) { var bitRateTypedValue = SupportMethods.ParseDecimalValueFromValue(comboBitRate.ActiveText, MediaConvertGUIConfiguration.DefaultVideoBitRates); m.Bitrate = bitRateTypedValue * 1000; } if (chBoxResolution.Active) { if (SupportMethods.IsNumeric(entryWidth.Text)) { m.Width = Convert.ToInt32(entryWidth.Text); } if (SupportMethods.IsNumeric(entryHeight.Text)) { m.Height = Convert.ToInt32(entryHeight.Text); } } if (chBoxFrameRate.Active) { if (SupportMethods.IsNumeric(comboFrameRate.ActiveText)) { m.FrameRate = SupportMethods.ToDecimal(comboFrameRate.ActiveText); } } if (chBoxAspect.Active) { m.Aspect = comboAspect.ActiveText; } if (chBoxRotation.Active) { if (SupportMethods.IsNumeric(comboRotation.ActiveText)) { m.RotatationAngle = SupportMethods.ToDecimal(comboRotation.ActiveText); } } MovieInfo.EditRotation = chBoxRotation.Active; MovieInfo.AutoRotate = checkAutorotate.Active; if (checkAutorotate.Active) { // reseting Rotation angle to 0 m.RotatationAngle = 0; } MovieInfo.TargetVideoCodec = MediaConvertGUIConfiguration.GetVideoCodecByName(comboCodec.ActiveText); comboCodec.TooltipText = MovieInfo.TargetVideoCodec.Title; _eventLock.Unlock(); Fill(); } } }
public void Fill() { if (_eventLock.Lock()) { var defaultAspects = new List <string> { "16:9", "4:3" }; var frameRates = new List <string> { "23.976", "25" }; var chBoxesVisible = false; //textviewRawOutput.Buffer.Text = MovieInfo.RawMediaInfoOutput; if (MovieInfo != null && MovieInfo.FirstVideoTrack != null) { var m = MovieInfo.FirstVideoTrack; chBoxResolution.Active = MovieInfo.EditResolution; chBoxAspect.Active = MovieInfo.EditAspect; chBoxBitRate.Active = MovieInfo.EditBitRate; chBoxFrameRate.Active = MovieInfo.EditFrameRate; chBoxRotation.Active = MovieInfo.EditRotation; if (MovieInfo.EditResolution) { entryWidth.Text = m.Width.ToString(); entryHeight.Text = m.Height.ToString(); entryPixelAspect.Text = m.PixelAspect.ToString(); entryRealWidth.Text = m.RealWidth.ToString(); } else { entryHeight.Text = String.Empty; entryPixelAspect.Text = String.Empty; entryWidth.Text = String.Empty; entryRealWidth.Text = String.Empty; } entryWidth.Sensitive = entryHeight.Sensitive = MovieInfo.EditResolution; if (MovieInfo.EditAspect) { // fill aspect ratio combo SupportMethods.FillComboBoxEntry(comboAspect, defaultAspects, m.Aspect, false, Editable); } else { SupportMethods.ClearCombo(comboAspect); } comboAspect.Sensitive = MovieInfo.EditAspect; if (MovieInfo.EditFrameRate) { // fill frame rate combo SupportMethods.FillComboBoxEntry(comboFrameRate, frameRates, m.FrameRate.ToString(), true, Editable); } else { SupportMethods.ClearCombo(comboFrameRate); } comboFrameRate.Sensitive = MovieInfo.EditFrameRate; if (MovieInfo.EditBitRate) { SupportMethods.FillComboBoxEntry(comboBitRate, MediaConvertGUIConfiguration.DefaultVideoBitRates, m.BitrateKbps, Editable); } else { SupportMethods.ClearCombo(comboBitRate); } comboBitRate.Sensitive = MovieInfo.EditBitRate; if (MovieInfo.EditRotation) { SupportMethods.FillComboBoxEntry(comboRotation, MediaInfo.DefaultRotationAngles, MovieInfo.FirstVideoTrack.RotatationAngle, Editable); } else { SupportMethods.ClearCombo(comboRotation); } comboRotation.Sensitive = MovieInfo.EditRotation && !MovieInfo.AutoRotate; checkAutorotate.Active = MovieInfo.AutoRotate; chBoxRotation.Active = MovieInfo.EditRotation; if (Editable) { chBoxesVisible = true; SupportMethods.FillComboBox(comboCodec, MediaConvertGUIConfiguration.VideoCodecsAsList(true), Editable, MovieInfo.TargetVideoCodec.Name); } else { SupportMethods.FillComboBox(comboCodec, new List <string>() { m.Codec }, Editable, m.Codec); } m.ReComputeStreamSizeByBitrate(); labelTrackSize.Text = m.HumanReadableStreamSize; } else { entryWidth.Text = String.Empty; entryRealWidth.Text = String.Empty; entryHeight.Text = String.Empty; entryPixelAspect.Text = String.Empty; SupportMethods.ClearCombo(comboCodec); labelTrackSize.Text = String.Empty; SupportMethods.ClearCombo(comboBitRate); SupportMethods.ClearCombo(comboAspect); SupportMethods.ClearCombo(comboFrameRate); SupportMethods.ClearCombo(comboRotation); } imageCodec.Visible = comboCodec.Active > 0; frameVideooptions.Visible = (MovieInfo != null) && (MovieInfo.FirstVideoTrack != null) && (((Editable) && (comboCodec.Active > 0)) || !Editable); chBoxAspect.Visible = chBoxResolution.Visible = chBoxBitRate.Visible = chBoxFrameRate.Visible = chBoxRotation.Visible = checkAutorotate.Visible = chBoxesVisible; _eventLock.Unlock(); } }
public void SaveAsSchemeToXML(string fileName) { // Create a new XmlTextWriter instance XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.Indentation = 4; // start writing! writer.WriteStartDocument(); writer.WriteStartElement("MultimediaScheme"); writer.WriteElementString("Container", TargetContainer.Name); // Video writer.WriteStartElement("Video"); writer.WriteElementString("Codec", TargetVideoCodec.ToString()); if (TargetVideoCodec != MediaConvertGUIConfiguration.GetVideoCodecByName("none")) { var firstVideoTrack = FirstVideoTrack; if (firstVideoTrack != null) { if (EditResolution) { writer.WriteElementString("Width", firstVideoTrack.Width.ToString()); writer.WriteElementString("Height", firstVideoTrack.Height.ToString()); } if (EditAspect) { writer.WriteElementString("Aspect", firstVideoTrack.Aspect); } if (EditBitRate) { writer.WriteElementString("Bitrate", firstVideoTrack.Bitrate.ToString()); } if (EditFrameRate) { writer.WriteElementString("Framerate", firstVideoTrack.FrameRate.ToString(System.Globalization.CultureInfo.InvariantCulture)); } } } writer.WriteEndElement(); // Audio writer.WriteStartElement("Audio"); foreach (var track in Tracks) { if (track.TrackType == "Audio") { writer.WriteStartElement("Track"); writer.WriteElementString("Codec", track.TargetAudioCodec.ToString()); if ((track.TargetAudioCodec.Name != "none") && (track.TargetAudioCodec.Name != "copy")) { writer.WriteElementString("Channels", track.Channels.ToString()); writer.WriteElementString("Bitrate", track.Bitrate.ToString()); writer.WriteElementString("SamplingRate", track.SamplingRateHz.ToString()); } writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
public void OpenSchemeFromXML(string fileName) { // http://stackoverflow.com/questions/243022/parsing-through-xml-elements-in-xmlreader var xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); var xmlRoot = xmlDoc.DocumentElement; foreach (XmlNode item in xmlRoot.SelectNodes(@"/MultimediaScheme")) { MediaContainer container; var node = item.SelectSingleNode("Container"); if ((node != null) && (node.FirstChild != null)) { container = MediaConvertGUIConfiguration.GetContainerByName(node.FirstChild.Value); if (container != null) { TargetContainer = container; } } } var firstVideoTrack = FirstVideoTrack; if (firstVideoTrack != null) { foreach (XmlNode item in xmlRoot.SelectNodes(@"/MultimediaScheme/Video")) { int width; var widthNode = item.SelectSingleNode("Width"); if ((widthNode != null) && (widthNode.FirstChild != null)) { if (int.TryParse(widthNode.FirstChild.Value, out width)) { firstVideoTrack.Width = width; } } int height; var heightNode = item.SelectSingleNode("Height"); if ((heightNode != null) && (heightNode.FirstChild != null)) { if (int.TryParse(heightNode.FirstChild.Value, out height)) { firstVideoTrack.Height = height; } } int bitrate; var bitrateNode = item.SelectSingleNode("Bitrate"); if ((bitrateNode != null) && (bitrateNode.FirstChild != null)) { if (int.TryParse(bitrateNode.FirstChild.Value, out bitrate)) { firstVideoTrack.Bitrate = bitrate; } } decimal framerate; var framerateNode = item.SelectSingleNode("Framerate"); if ((framerateNode != null) && (framerateNode.FirstChild != null)) { if (decimal.TryParse(framerateNode.FirstChild.Value, out framerate)) { firstVideoTrack.FrameRate = framerate; } } var aspectNode = item.SelectSingleNode("Aspect"); if ((aspectNode != null) && (aspectNode.FirstChild != null)) { if (Regex.IsMatch(aspectNode.FirstChild.Value, "^[0-9]+:[0-9]+$")) { firstVideoTrack.Aspect = aspectNode.FirstChild.Value; } } var codecNode = item.SelectSingleNode("Codec"); if ((codecNode != null) && (codecNode.FirstChild != null)) { var codec = MediaConvertGUIConfiguration.GetVideoCodecByName(codecNode.FirstChild.Value); if (codec != null) { this.TargetVideoCodec = codec; } } } } var firstAudioTrack = FirstAudioTrack; if (this.AudioTracks.Count > 0) { var actualTrackIndex = 1; foreach (XmlNode trackNode in xmlRoot.SelectNodes(@"/MultimediaScheme/Audio/Track")) { var codecNode = trackNode.SelectSingleNode("Codec"); if ((codecNode != null) && (codecNode.FirstChild != null)) { var aCodec = MediaConvertGUIConfiguration.GetAudioCodecByName(codecNode.FirstChild.Value); if (aCodec != null) { AudioTracks[actualTrackIndex].TargetAudioCodec = aCodec; } } int channels; var channelsNode = trackNode.SelectSingleNode("Channels"); if ((channelsNode != null) && (channelsNode.FirstChild != null)) { if (int.TryParse(channelsNode.FirstChild.Value, out channels)) { AudioTracks[actualTrackIndex].Channels = channels; } } int bitrate; var bitrateNode = trackNode.SelectSingleNode("Bitrate"); if ((bitrateNode != null) && (bitrateNode.FirstChild != null)) { if (int.TryParse(bitrateNode.FirstChild.Value, out bitrate)) { AudioTracks[actualTrackIndex].Bitrate = bitrate; } } decimal sRate; var sRateNode = trackNode.SelectSingleNode("SamplingRate"); if ((sRateNode != null) && (sRateNode.FirstChild != null)) { if (decimal.TryParse(sRateNode.FirstChild.Value, out sRate)) { AudioTracks[actualTrackIndex].SamplingRateHz = sRate; } } actualTrackIndex++; if (actualTrackIndex > AudioTracks.Count) { break; } } } }
/// <summary> /// Makes the FF MPEG command. /// </summary> /// <returns>The FF MPEG command.</returns> /// <param name="sourceMovie">Source movie.</param> /// <param name="targetMovie">Target movie.</param> /// <param name="currentPass">Current pass.</param> public static string MakeFFMpegCommand(MediaInfo sourceMovie, MediaInfo targetMovie, int currentPass) { var res = String.Empty; // single audio convert? if ((targetMovie.AudioTracks.Count > 0) && (targetMovie.FirstAudioTrack.TargetAudioCodec.Name != "none") && ((targetMovie.FirstVideoTrack == null) || (targetMovie.TargetVideoCodec == MediaConvertGUIConfiguration.GetVideoCodecByName("none")) || (targetMovie.TargetContainer == null) || (targetMovie.TargetContainer.Name == "none") ) && (currentPass > 1)) { return(res); } // codec copy - single pass if ((targetMovie.FirstVideoTrack != null) && (targetMovie.TargetVideoCodec == MediaConvertGUIConfiguration.GetVideoCodecByName("copy")) && (currentPass > 1)) { return(res); } var sourceFile = " -i \"" + sourceMovie.FileName + "\""; var ext = System.IO.Path.GetExtension(sourceMovie.FileName); var targetFile = sourceMovie.FileName + ".converted" + ext; var video = " -vn"; // disable video var hwaccel = String.Empty; var audio = " -an "; // disable audio var map = String.Empty; if (targetMovie.FirstVideoTrack != null && targetMovie.TargetVideoCodec != MediaConvertGUIConfiguration.GetVideoCodecByName("none") && targetMovie.TargetContainer != null && targetMovie.TargetContainer.Name != "none") { var videoSettings = String.Empty; var container = String.Empty; container = " -f " + targetMovie.TargetContainer.Name; ext = targetMovie.TargetContainer.Extension; targetFile = sourceMovie.FileName + ".converted" + ext; videoSettings += container; var aspect = " -aspect " + targetMovie.FirstVideoTrack.Aspect; var scale = " -s " + targetMovie.FirstVideoTrack.Width.ToString() + "x" + targetMovie.FirstVideoTrack.Height.ToString(); var bitrate = " -b:v " + targetMovie.FirstVideoTrack.Bitrate; var frameRate = " -r " + targetMovie.FirstVideoTrack.FrameRate.ToString().Replace(",", "."); // TODO: invariant culture // auto rotation var rotation90AnglesCount = Convert.ToInt32(sourceMovie.FirstVideoTrack.RotatationAngle); var autoRotate = " -vf "; if (rotation90AnglesCount == 90) { autoRotate += " transpose=2"; // 90CounterClockwise } else if (rotation90AnglesCount == 180) { autoRotate += " transpose=1,transpose=1"; // 2*90Clockwise } else if (rotation90AnglesCount == 270) { autoRotate += " transpose=1"; // 90Clockwise } else { autoRotate = ""; // unsupported transposition } var rotationAngle = " -metadata:s:v:0 rotate=" + Convert.ToInt32(targetMovie.FirstVideoTrack.RotatationAngle).ToString(); if (targetMovie.EditAspect) { videoSettings += aspect; } if (targetMovie.EditResolution) { videoSettings += scale; } if (targetMovie.EditBitRate) { videoSettings += bitrate; } if (targetMovie.EditFrameRate) { videoSettings += frameRate; } if (targetMovie.EditRotation) { videoSettings += rotationAngle; } if (targetMovie.AutoRotate) { videoSettings += autoRotate; } if (targetMovie.TargetVideoCodec != MediaConvertGUIConfiguration.GetVideoCodecByName("copy")) { var pass = String.Format(" -pass {0} -passlogfile \"{1}\"", currentPass, targetFile + ".passlog"); videoSettings += pass; } video = targetMovie.TargetVideoCodec.Command + videoSettings; hwaccel = String.IsNullOrEmpty(targetMovie.TargetVideoCodec.HWAcceleration) ? "" : " -hwaccel " + targetMovie.TargetVideoCodec.HWAcceleration; } // only first Audio Track! if (targetMovie.AudioTracks.Count > 0) { var targetAudioTrack = targetMovie.FirstAudioTrack; var audioQuality = String.Format(" -ac {0} -ar {1} -ab {2}", targetAudioTrack.Channels, targetAudioTrack.SamplingRateHz, targetAudioTrack.Bitrate); audio = " " + targetAudioTrack.TargetAudioCodec.Command + " "; if (targetAudioTrack.TargetAudioCodec.Name != "copy") { audio += " " + audioQuality; } if ((targetMovie.FirstVideoTrack == null) || (targetMovie.TargetVideoCodec == MediaConvertGUIConfiguration.GetVideoCodecByName("none")) || (targetMovie.TargetContainer.Name == "none") ) { // converting single audio targetFile = sourceMovie.FileName + ".converted" + ext; } } // more audio tracks? supporting only the first one if (sourceMovie.AudioTracks.Count > 1 && sourceMovie.FirstVideoTrack != null) { map = " -map 0:0 -map 0:1"; } targetMovie.FFMPEGOutputFileName = targetFile + ".log"; targetMovie.FFMPEGPassLogFileName = targetFile + ".passlog"; targetMovie.FileName = targetFile; /* * if (File.Exists(targetMovie.FFMPEGOutputFileName)) * File.Delete(targetMovie.FFMPEGOutputFileName); * if (File.Exists(targetMovie.FFMPEGPassLogFileName)) * File.Delete(targetMovie.FFMPEGPassLogFileName); */ targetFile = String.Format(" \"{0}\"", targetFile); res = MediaConvertGUIConfiguration.FFMpegPath + " " + hwaccel + " -y -dump " + sourceFile + map + " " + video + audio + targetFile; return(res); }