/// <summary> /// Gets the last time from convert log file in seconds /// Parsing text "time=00:22:25.05" to 1345 (22*60++25+0.05) s /// </summary> /// <returns> /// The last frame time convert log file (int). /// If value not found, returns -1 /// </returns> /// <param name='outputFileName'> /// log file name. /// </param> public static int GetLastTimeFromConvertLogFile(string outputFileName) { var lastTime = -1; if (File.Exists(outputFileName)) { using (var fs = new FileStream(outputFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var sr = new StreamReader(fs)) { string line; while ((line = sr.ReadLine()) != null) { if (line != null && line.Contains("time=")) { var pos = line.IndexOf("time="); if (line.Length > pos + 5 + 8) { var lastTimeAsString = line.Substring(pos + 5, 8).Trim(); var hms = lastTimeAsString.Split(':'); if (hms.Length == 3 && SupportMethods.IsNumeric(hms [0]) && SupportMethods.IsNumeric(hms [1]) && SupportMethods.IsNumeric(hms [2])) { lastTime = Convert.ToInt32(hms[0]) * 3600 + Convert.ToInt32(hms[1]) * 60 + Convert.ToInt32(hms[2]); // ignoring ms } } } } } } } return(lastTime); }
private void OnAnyValuechanged() { if (_eventLock.Lock() && Editable) { var activeTrack = SelectedTrack; if (activeTrack != null) { activeTrack.TargetAudioCodec = SelectedAudioCodec; activeTrack.Bitrate = BitRateTypedValue * 1000; activeTrack.ReComputeStreamSizeByBitrate(); activeTrack.Channels = Convert.ToInt32(comboChannels.ActiveText); var samplingRateTypedValue = SupportMethods.ParseDecimalValueFromValue(comboSampleRate.ActiveText, MediaConvertGUIConfiguration.DefaultSamplingRates); activeTrack.SamplingRateHz = samplingRateTypedValue; } _eventLock.Unlock(); } ; Fill(); }
public void PlayInShell() { if (File.Exists(FileName)) { SupportMethods.ExecuteInShell("\"" + FileName + "\""); } }
/// <summary> /// Gets the last frame from convert log file. /// Parsing text "frame=15" to 15 /// </summary> /// <returns> /// The last frame from convert log file (int). /// If value not found, returns -1 /// </returns> /// <param name='_outputFileName'> /// _output file name. /// </param> public static int GetLastFrameFromConvertLogFile(string outputFileName) { var lastFrame = -1; if (File.Exists(outputFileName)) { using (var fs = new FileStream(outputFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var sr = new StreamReader(fs)) { string line; while ((line = sr.ReadLine()) != null) { if (line != null && line.Length > 11 && line.StartsWith("frame=")) { var lastFrameAsString = line.Substring(6, 5).Trim(); if (SupportMethods.IsNumeric(lastFrameAsString)) { lastFrame = Convert.ToInt32(lastFrameAsString); } } } } } } return(lastFrame); }
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(); } }
/// <summary> /// Fills the combo box entry. /// </summary> /// <param name='combo'> /// Combo. /// </param> /// <param name='items'> /// Items. /// </param> /// <param name='currentValue'> /// Current value. /// </param> /// <param name='editable'> /// Editable. /// </param> public static void FillComboBoxEntry(Gtk.ComboBoxEntry combo, List <string> items, string currentValue, bool isDecimal, bool editable) { combo.Model = new ListStore(typeof(string)); var resultItems = new List <string>(); if (editable) { // searching for value var present = false; foreach (var value in items) { if ( (isDecimal && (SupportMethods.ToDecimal(value) == SupportMethods.ToDecimal(currentValue))) || (!isDecimal && (value == currentValue)) ) { present = true; break; } } // adding missing to first pos if (!present) { resultItems.Add(currentValue); } foreach (var value in items) { resultItems.Add(value); } } else { resultItems.Add(currentValue); } var index = 0; foreach (var value in resultItems) { combo.AppendText(value); if ( (isDecimal && (SupportMethods.ToDecimal(value) == SupportMethods.ToDecimal(currentValue))) || (!isDecimal && (value == currentValue)) ) { combo.Active = index; } index++; } }
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); } } }
public void ScreenShot() { if (File.Exists(FileName)) { var fName = MediaInfoBase.MakeFFMpegScreenShot(this); if (fName != null) { SupportMethods.ExecuteInShell("\"" + fName + "\""); } } }
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); } } }
protected void OnEventBoxButtonPressEvent(object o, ButtonPressEventArgs args) { var activeTrack = SelectedTrack; if (activeTrack != null) { var codec = SelectedAudioCodec; if (!String.IsNullOrEmpty(codec.Link)) { SupportMethods.ExecuteInShell(codec.Link); } } }
protected void OnEntryWidthChanged(object sender, EventArgs e) { if (checkKeep.Active && MovieInfo.FirstVideoTrack != null && SupportMethods.IsNumeric(entryWidth.Text)) { if (_eventLock.Lock()) { var width = SupportMethods.ToDecimal(entryWidth.Text); var aspectRatio = MovieInfo.FirstVideoTrack.AspectAsNumber; if (aspectRatio != -1) { entryHeight.Text = Convert.ToInt32(width / aspectRatio).ToString(); } _eventLock.Unlock(); } } OnAnyValueChanged(); }
public static decimal ParseDecimalValueFromValue(string value, Dictionary <decimal, string> dict) { var res = 0m; if (SupportMethods.IsNumeric(value)) { res = SupportMethods.ToDecimal(value); } else { foreach (var kvp in dict) { if (kvp.Value == value) { res = kvp.Key; } } } return(res); }
/// <summary> /// Opens from file. /// </summary> /// <param name='fileName'> /// File name. /// </param> public bool OpenFromFile(string fileName) { try { if (!File.Exists(fileName)) { return(false); } FileName = fileName; var fi = new System.IO.FileInfo(fileName); FileSize = fi.Length; Tracks.Clear(); TargetContainer = MediaInfoBase.DetectContainerByExt(fileName); var mediaInfoXML = SupportMethods.ExecuteAndReturnOutput(MediaConvertGUIConfiguration.MediaInfoPath, "-f --Output=XML \"" + fileName + "\""); RawMediaInfoOutput = mediaInfoXML; var xmlDoc = new System.Xml.XmlDocument(); xmlDoc.LoadXml(mediaInfoXML); var nodes = xmlDoc.SelectNodes("Mediainfo/File/track"); foreach (XmlNode node in nodes) { var track = new TrackInfo(); track.ParseFromXmlNode(node); Tracks.Add(track); } return(true); } catch (Exception ex) { Console.WriteLine("Error:" + ex.ToString()); return(false); } }
public static string MakeFFMpegScreenShot(MediaInfo sourceMovie, int secondsDelay = 0) { if (sourceMovie.FirstVideoTrack != null && File.Exists(sourceMovie.FileName)) { var ffmpegCommandArgs = String.Empty; var timeSpan = TimeSpan.FromSeconds(secondsDelay); //var timeAsStrig = timeSpan.ToString("hh:mm:ss"); var timeAsString = string.Format("{0}:{1}", timeSpan.Minutes.ToString().PadLeft(2, '0'), timeSpan.Seconds.ToString().PadLeft(2, '0')); var picFileName = sourceMovie.FileName + ".jpg"; var counter = 0; while (File.Exists(picFileName)) { counter++; picFileName = sourceMovie.FileName + "." + counter.ToString().PadLeft(2, '0') + ".jpg"; } // https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video // ffmpeg -i input.flv -ss 00:00:14.435 -f image2 -vframes 1 out.png ffmpegCommandArgs = " -i {filename} -ss {time} -f image2 -vframes 1 {pic}"; ffmpegCommandArgs = ffmpegCommandArgs.Replace("{filename}", "\"" + sourceMovie.FileName + "\""); ffmpegCommandArgs = ffmpegCommandArgs.Replace("{time}", timeAsString); ffmpegCommandArgs = ffmpegCommandArgs.Replace("{pic}", "\"" + picFileName + "\""); SupportMethods.ExecuteAndReturnOutput(MediaConvertGUIConfiguration.FFMpegPath, ffmpegCommandArgs); return(picFileName); } return(null); }
public void ParseFromXmlNode(XmlNode node) { foreach (XmlNode subNode in node.ChildNodes) { if (subNode.Name == "Overall_bit_rate" && (SupportMethods.IsNumeric(subNode.InnerText))) { Bitrate = SupportMethods.ToDecimal(subNode.InnerText); } if (subNode.Name == "Frame_rate" && (SupportMethods.IsNumeric(subNode.InnerText))) { FrameRate = SupportMethods.ToDecimal(subNode.InnerText); } if (subNode.Name == "Sampling_rate" && (SupportMethods.IsNumeric(subNode.InnerText))) { SamplingRateHz = SupportMethods.ToDecimal(subNode.InnerText); } if (subNode.Name == "Bit_rate" && (SupportMethods.IsNumeric(subNode.InnerText))) { Bitrate = decimal.Parse(subNode.InnerText); } if (subNode.Name == "Stream_size" && (SupportMethods.IsNumeric(subNode.InnerText))) { StreamSize = long.Parse(subNode.InnerText); } if (subNode.Name == "Channel_s_" && (SupportMethods.IsNumeric(subNode.InnerText))) { Channels = Int32.Parse(subNode.InnerText); } if (subNode.Name == "Channel_count" && (SupportMethods.IsNumeric(subNode.InnerText))) { Channels = Int32.Parse(subNode.InnerText); } if (subNode.Name == "Pixel_aspect_ratio" && (SupportMethods.IsNumeric(subNode.InnerText))) { PixelAspect = SupportMethods.ToDecimal(subNode.InnerText); } if (subNode.Name == "Width" && (SupportMethods.IsInt(subNode.InnerText))) { Width = Int32.Parse(subNode.InnerText); } if (subNode.Name == "Height" && (SupportMethods.IsInt(subNode.InnerText))) { Height = Int32.Parse(subNode.InnerText); } if (subNode.Name == "Display_aspect_ratio" && (subNode.InnerText.Contains(":"))) { Aspect = subNode.InnerText; } if (subNode.Name == "Codec") { Codec = subNode.InnerText; } if (subNode.Name == "Rotation" && (SupportMethods.IsNumeric(subNode.InnerText))) { decimal angle = 0; var separator = System.Globalization.CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator; var rotationAsString = subNode.InnerText.Replace(".", separator).Replace(",", separator); if (Decimal.TryParse(rotationAsString, out angle)) { RotatationAngle = angle; } } if (subNode.Name == "Duration" && (subNode.InnerText.Contains(":"))) { Duration = subNode.InnerText; } if (subNode.Name == "Duration" && (SupportMethods.IsNumeric(subNode.InnerText))) { DurationMS = SupportMethods.ToDecimal(subNode.InnerText); } } TrackType = node.Attributes.GetNamedItem("type").Value; }
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 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(); } } }