private void btnCreateMeGUI_Click(object sender, EventArgs e) { try { SwapButtonsDuringExecution(); //Check prerequisites if (!_Kienzan.HasTimecodes) { throw new Exception("Please load timecodes first!"); } if (!_Kienzan.HasSections) { throw new Exception("Please load sections first!"); } //Select filename String filename = ShowSaveFileDialog("Select MeGUI script file...", AcHelper.GetFilename(txtSectionsFile.Text, GetFileNameMode.NoFileName, GetDirectoryNameMode.FullPath), "*.clt|*.clt"); Stopwatch actime = new Stopwatch(); if (filename != null) { if (filename.Length > 0) { //Create the thread Thread createMeGUIThread = new Thread(new ParameterizedThreadStart(_Kienzan.CreateMeGUIScriptThreaded)); _Kienzan.TargetFramerate = AcHelper.DecimalParse(Convert.ToString(comTargetFramerate.Text)); //Start timing actime.Start(); //Start the thread createMeGUIThread.Start(filename); //Wait for the thread to finish while keeping UI responsive while (createMeGUIThread.ThreadState != System.Threading.ThreadState.Stopped) { Application.DoEvents(); } //End timing actime.Stop(); if (_Kienzan.Failed) { miniLog("Failed creating MeGUI cut file!"); throw _Kienzan.ThreadedException; } else { miniLog(String.Format("Finished creating MeGUI Cut File in {0}!", actime.Elapsed)); ShowSuccessMessage("Successfully created MeGUI Cut File!"); } } } } catch (Exception ex) { ShowExceptionMessage(ex); } SwapButtonsDuringExecution(); }
private void RunKienzanNew(Boolean ignoreSections = false) { //Check prerequisites CheckVideo(); if (!_Kienzan.HasTimecodes) { throw new Exception("Please load timecodes first!"); } // check if duplicates are needed if (!_Kienzan.VideoFrames.IsCFR) { if (!_Kienzan.HasDuplicates) { if (ShowQuestion("No duplicates were loaded! Do you want to continue?") != DialogResult.Yes) { return; } } } if (!_Kienzan.HasSections && !ignoreSections) { if (ShowQuestion("No sections were loaded! Do you want to continue with the whole video as one section?", "No sections were loaded!") == DialogResult.No) { return; } } Stopwatch actime = new Stopwatch(); Decimal targetFramerate = AcHelper.DecimalParse(Convert.ToString(comTargetFramerate.SelectedItem)); //Create the thread Thread runKienzThread = new Thread(new ParameterizedThreadStart(_Kienzan.RunNewKienzanThreaded)); //Set the video file _Kienzan.VideoFile = txtVideoFile.Text; //Start timing actime.Start(); //Start the thread runKienzThread.Start(targetFramerate); //Wait for the thread to finish while keeping UI responsive while (runKienzThread.ThreadState != System.Threading.ThreadState.Stopped) { Application.DoEvents(); } //Stop timing actime.Stop(); if (_Kienzan.Failed) { miniLog("Failed running New Kienzan!"); throw _Kienzan.ThreadedException; } else { miniLog(String.Format("Successfully run New Kienzan in {0}!", actime.Elapsed)); } }
/// <summary> /// Function to analyse data using 2 lines from a v2 timecodes file /// </summary> /// <param name="frame"> /// string with the line for the current frame /// </param> /// <param name="nextFrame"> /// string with the line the next frame /// </param> /// <param name="frameNum"> /// the current frame's number /// </param> /// <returns> /// the VideoFrame structure for the current frame /// </returns> private VideoFrame AnalyseV2(String frame, String nextFrame, int frameNum) { //Calculate VideoFrame data return(new VideoFrame() { FrameNumber = frameNum, FrameStartTime = AcHelper.DecimalParse(frame), FrameDuration = AcHelper.DecimalParse(nextFrame) - AcHelper.DecimalParse(frame) }); }
private VideoFrame getFrameFromForm() { VideoFrame vf = new VideoFrame(); vf.FrameNumber = Convert.ToInt32(txtFrameNumber.Text); if (radioFrameDuration.Checked) { vf.FrameDuration = AcHelper.DecimalParse(txtFrameDuration.Text); } else { vf.FrameRate = AcHelper.DecimalParse(txtFrameFrameRate.Text); } vf.FrameStartTime = AcHelper.DecimalParse(txtFrameStart.Text); return(vf); }
private void btnOK_Click(object sender, EventArgs e) { try { //Check prerequisites //Check if sections file was provided if (txtSectionsFile.Text.Length < 1) { throw new Exception("Error making chapters from sections! Please provide with sections file!"); } //Check if provided sections file exists if (!File.Exists(txtSectionsFile.Text)) { throw new Exception("Error making chapters from sections! Please provide with an existing sections file!"); } //If use chapters is checked if (checkUseChaptersFile.Checked) { //Check if chapters file was provided if (txtChaptersFile.Text.Length < 1) { throw new Exception("Error making chapters from sections! Please provide with chapters file!"); } //Check if provided chapters file exists if (!File.Exists(txtChaptersFile.Text)) { throw new Exception("Error making chapters from sections! Please provide with an existing chapters file!"); } } cEdit.CreateFromSections(txtSectionsFile.Text, txtChaptersFile.Text, AcHelper.DecimalParse(comboFramerate.SelectedItem.ToString()), checkUseChaptersFile.Checked, checkIsTrimFile.Checked); Close(); } catch (Exception ex) { ShowExceptionMessage(ex); } }
private void CreateMeGUIScript() { using (Kienzan kienz = new Kienzan()) { //Check prerequisites //Select filename String filename = txtMeguiCutsFile.Text; Stopwatch actime = new Stopwatch(); kienz.LoadTimecodes(txtTimecodesFile.Text); kienz.LoadSections(txtSectionsFile.Text); if (filename != null) { if (filename.Length > 0) { //Create the thread Thread createMeGUIThread = new Thread(new ParameterizedThreadStart(kienz.CreateMeGUIScriptThreaded)); kienz.TargetFramerate = AcHelper.DecimalParse(Convert.ToString(cmbFrameRate.SelectedItem)); //Start timing actime.Start(); //Start the thread createMeGUIThread.Start(filename); //Wait for the thread to finish while keeping UI responsive while (createMeGUIThread.ThreadState != System.Threading.ThreadState.Stopped) { Application.DoEvents(); } //End timing actime.Stop(); if (!kienz.Failed) { ShowSuccessMessage("Successfully created MeGUI Cut File!"); } } } } }
/// <summary> /// Function to analyse a string line of a v1 timecodes file /// </summary> /// <param name="frame">string which contains a valid line</param> /// <param name="vfl">the video frame list to write to</param> private void AnalyseV1(String frame, VideoFrameList vfl) { //Get elements //elements[0] first frame //elememts[1] last frame //elements[2] framerate String[] elements = frame.Split(new String[] { "," }, StringSplitOptions.None); //check for valid elements if (elements.Length == 3) { //Calculate FrameInfo data int start = Convert.ToInt32(elements[0]); int end = Convert.ToInt32(elements[1]); for (int i = start; i <= end; i++) { VideoFrame tmp = new VideoFrame(); tmp.FrameNumber = i; tmp.FrameRate = AcHelper.DecimalParse(elements[2]); if (i == 0) { tmp.FrameStartTime = 0.0m; } else { tmp.FrameStartTime = vfl.FrameList[i - 1].FrameDuration + vfl.FrameList[i - 1].FrameStartTime; } //Add FrameInfo to FrameList vfl.Add(tmp); } } else { throw (new AcException("Invalid format v1 timecodes!")); } }
private void addFrameRangeToList() { //Get start frame Object startFrameObj = AcControls.AcInputBox.AcInputBox.Show("Enter the start frame of the frame range:", "Enter frame...", ""); if (startFrameObj == null) { return; } //Get end frame Object endFrameObj = AcControls.AcInputBox.AcInputBox.Show("Enter the end frame of the frame range:", "Enter frame...", ""); if (endFrameObj == null) { return; } //Get start time Object startTimeObj = AcControls.AcInputBox.AcInputBox.Show("Enter the start time of the first frame:", "Enter start time...", ""); if (startFrameObj == null) { return; } //Check for duration or frame rate Boolean useDuration = false; if (ShowQuestion("Do you want to enter duration in ms?\r\n(Answering No will prompt you to enter frame rate in fps))", "Select duration type...") == DialogResult.Yes) { useDuration = true; } Object durationObj = null; Object frameRateObj = null; if (useDuration) { //Get duration durationObj = AcControls.AcInputBox.AcInputBox.Show("Enter the duration for each frame in ms:", "Enter frame duration...", ""); if (durationObj == null) { return; } } else { //Get frame rate frameRateObj = AcControls.AcInputBox.AcInputBox.Show("Enter the frame rate for each frame in fps:", "Enter frame rate...", ""); if (frameRateObj == null) { return; } } Decimal currentStartTime = AcHelper.DecimalParse((String)startTimeObj); Decimal durationAmount = Decimal.MinValue; durationAmount = useDuration ? AcHelper.DecimalParse((String)durationObj) : AcHelper.DecimalParse((String)frameRateObj); //Add frame range for (Int32 i = Convert.ToInt32(startFrameObj); i <= Convert.ToInt32(endFrameObj); i++) { // check if frame number already exists and if it does, skip it if (vfl.FrameList.Any(x => x.FrameNumber == i)) { continue; } VideoFrame vf = new VideoFrame(); vf.FrameNumber = i; vf.FrameStartTime = currentStartTime; if (useDuration) { vf.FrameDuration = durationAmount; } else { vf.FrameRate = durationAmount; } //Update start time for next frame currentStartTime += vf.FrameDuration; //Add the frame to the list vfl.Add(vf); } }
private void txtFrameFrameRate_TextChanged(object sender, EventArgs e) { try { if (!ignoreUpdateText) { txtFrameDuration.Text = Convert.ToString(VideoFrame.GetDurationFromFrameRate(AcHelper.DecimalParse(txtFrameFrameRate.Text)), System.Globalization.CultureInfo.InvariantCulture); } } catch (Exception ex) { Debug.WriteLine(ex); ignoreUpdateText = true; txtFrameDuration.Text = String.Empty; ignoreUpdateText = false; } }
/// <summary> /// Function to parse timecodes file /// </summary> /// <param name="timecodeFile">the path for the timecode file to parse</param> /// <param name="vfl">the video frame list to write to</param> /// <param name="writeDump">flag whether to write dump file</param> public void ParseTimecodes(String timecodeFile, VideoFrameList vfl, Boolean writeDump) { String curLine = ""; String prevLine = ""; bool isV1 = false; bool isV2 = false; Decimal assumedFps = 0.0m; //Open timecodes file using (StreamReader reader = new StreamReader(timecodeFile, Encoding.UTF8)) { try { //Start timing //Stopwatch timer = new Stopwatch(); //timer.Start(); //AcLogger.Log("Starting Parsing Timecodes file : " + timecodeFile, AcLogger.AcLogType.Form); //Read timecodes file while ((curLine = reader.ReadLine()) != null) { //Check for comment lines if (curLine.StartsWith("#")) { if (curLine.ToLower().Contains("v1")) { //AcLogger.Log("Version 1 Timecodes File Detected", AcLogger.AcLogType.Form); isV1 = true; timecodesFileVersion = 1; } if (curLine.ToLower().Contains("v2")) { //AcLogger.Log("Version 2 Timecodes File Detected", AcLogger.AcLogType.Form); isV2 = true; timecodesFileVersion = 2; } } //Check for assume line else if (curLine.ToLower().Contains("assume")) { curLine = curLine.ToLower().Replace("assume", "").Replace(" ", ""); assumedFps = AcHelper.DecimalParse(curLine); assumedFrameRate = assumedFps; //AcLogger.Log("Assumed FPS : " + assumedFps, AcLogger.AcLogType.Form); } else { //Check for empty line if (String.IsNullOrWhiteSpace(curLine)) { //Do nothing continue; } if (isV1) { AnalyseV1(curLine, vfl); } if (isV2) { //First Frame if (String.IsNullOrWhiteSpace(prevLine)) { prevLine = reader.ReadLine(); vfl.Add(AnalyseV2(curLine, prevLine, 0)); } //Other Frames else { vfl.Add(AnalyseV2(prevLine, curLine, vfl.Count)); prevLine = curLine; } } } } //Calculate last frame's FrameInfo data if v2 timecodes if (isV2) { vfl.Add(new VideoFrame() { FrameNumber = vfl.Count, FrameStartTime = AcHelper.DecimalParse(prevLine), FrameDuration = vfl.FrameList[vfl.Count - 1].FrameDuration }); } //timer.Stop(); } catch (Exception ex) { throw (new AcException("Error in reading timecodes file!", ex)); } } //AcLogger.Log("Parsing Timecodes finished!", AcLogger.AcLogType.Form); //AcLogger.Log("Parsing took : " + timer.Elapsed, AcLogger.AcLogType.Form); //AcLogger.Log("Total Frames : " + vfl.Count, AcLogger.AcLogType.Form); //Check timecode dump if (writeDump) { try { //Write Timecode Dump StringBuilder dumpBuilder = new StringBuilder(); using (StreamWriter writer = new StreamWriter(timecodeFile + ".dmp", false, Encoding.UTF8)) { for (int i = 0; i < vfl.Count; i++) { dumpBuilder.AppendFormat("Frame_Number:{0} Frame_Fps:{1} Frame_Duration:{2}\r\n", vfl.FrameList[i].FrameNumber, vfl.FrameList[i].FrameRate, vfl.FrameList[i].FrameDuration); } writer.Write(dumpBuilder.ToString()); } } catch (Exception ex) { throw (new AcException("Error writing timecode dump!", ex)); } } }
/// <summary> /// Function to parse duplicates file /// </summary> /// <param name="dupFile"> /// String with the path of the duplicates file /// </param> public static void ParseDup(String dupFile, VideoFrameList vfl) { using (StreamReader sr = new StreamReader(dupFile, Encoding.UTF8)) { //Start timing //Stopwatch timer = new Stopwatch(); //timer.Start(); //AcLogger.Log("Starting Parsing Duplicates file : " + dupFile, AcLogger.AcLogType.Form); //Check if FrameList exists bool createList = (vfl.Count == 0); //Read file String line = ""; Int32 frameNum = 0; while ((line = sr.ReadLine()) != null) { //Check for first line if (line.ToLowerInvariant().StartsWith("dedup")) { //Do nothing and advance to the next line continue; } //Check for frame difference line else if (line.ToLowerInvariant().StartsWith("frm")) { //Get frame difference String frameDiff = ""; int start = line.IndexOf("="); int len = line.IndexOf("%") - start; frameDiff = line.Substring(start + 1, len).Trim(); frameDiff = frameDiff.Substring(0, frameDiff.Length - 1); //Check if new frame list if (createList) { //Create new Video frame object VideoFrame tmpFrm = new VideoFrame(); tmpFrm.FrameNumber = frameNum; tmpFrm.FrameDifferenceFromPrevious = AcHelper.DecimalParse(frameDiff); //Add it to list vfl.Add(tmpFrm); } else { //Check if frame numbers don't match with the existing list if (frameNum > vfl.Count - 1) { //Invalid dup file throw (new AcException("Invalid Dup File! Frames are inconsistent with existing data!")); } else { //Set the difference vfl.FrameList[frameNum].FrameDifferenceFromPrevious = AcHelper.DecimalParse(frameDiff); } } //Advance frame number counter frameNum++; } } //timer.Stop(); //AcLogger.Log("Parsing Timecodes finished!", AcLogger.AcLogType.Form); //AcLogger.Log("Total frames : " + frameNum, AcLogger.AcLogType.Form); //AcLogger.Log("Parsing took : " + timer.Elapsed, AcLogger.AcLogType.Form); } }
private void btnSplit_Click(object sender, EventArgs e) { try { AssParser assP = new AssParser(); assP.ParseASS(txtAssFile.Text); VideoFrameList vfl = new VideoFrameList(); SectionParser.ParseSections(txtSectionsFile.Text, vfl); Decimal framerate = AcHelper.DecimalParse(txtFramerate.Text); foreach (AssDialogue assD in assP.AssContents) { Decimal timeToDelete = 0; for (Int32 currentSection = 0; currentSection < vfl.FrameSections.Count; currentSection++) { VideoFrameSection vfs = vfl.FrameSections[currentSection]; Decimal startSection = VideoFrame.GetStartTimeFromFrameNumber(vfs.FrameStart, framerate); Decimal endSection = VideoFrame.GetStartTimeFromFrameNumber(vfs.FrameEnd, framerate); //Check if the sub ends before the section if (assD.time_end_double <= startSection) { assD.deleted = true; break; } //Check if the sub starts after the section if (assD.time_start_double >= endSection) { //If its the last sections, then delete the sub if (currentSection == vfl.FrameSections.Count - 1) { assD.deleted = true; break; } else { continue; } } //Time to resync the sub if (currentSection == 0) { TimeSpan ts; timeToDelete = startSection; assD.time_start_double = assD.time_start_double - timeToDelete; ts = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_start_double)); assD.time_start = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00") + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00"); assD.time_end_double = assD.time_end_double - timeToDelete; ts = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_end_double)); assD.time_end = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00") + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00"); break; } else { TimeSpan ts; Decimal start = startSection; Decimal end = endSection; Decimal prevEnd = VideoFrame.GetStartTimeFromFrameNumber(vfl.FrameSections[currentSection - 1].FrameEnd, framerate); timeToDelete += start - prevEnd - VideoFrame.GetDurationFromFrameRate(framerate); assD.time_start_double = assD.time_start_double - timeToDelete; ts = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_start_double)); assD.time_start = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00") + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00"); assD.time_end_double = assD.time_end_double - timeToDelete; ts = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_end_double)); assD.time_end = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00") + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00"); break; } } } assP.WriteFinalAss(txtAssFile.Text.Substring(0, txtAssFile.Text.LastIndexOf(".") - 1) + ".resync.ass"); MessageBox.Show("Resync complete!", "Success!"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!"); } }