Example #1
0
        public bool TrimSubtitle(string srtFile, string workingPath, int startTrim, int endTrim, float Duration, double offset)
        {
            string TempEDLFile = Path.Combine(workingPath, "TempSRTEDLTrimFile.edl"); // Temp EDL file to trim SRT

            if (String.IsNullOrWhiteSpace(srtFile))
            {
                return(true); // Nothing to do
            }
            if ((startTrim <= 0) && (endTrim <= 0))
            {
                return(true); // Nothing to do
            }
            if (Duration <= 0)
            {
                _jobLog.WriteEntry(this, ("Invalid video duration"), Log.LogEntryType.Error);
                return(false);
            }

            // Create a EDL file which trims beginning and ending
            List <KeyValuePair <float, float> > keepList = new List <KeyValuePair <float, float> >();

            keepList.Add(new KeyValuePair <float, float>((startTrim > 0 ? startTrim : 0), (endTrim > 0 ? Duration - endTrim : Duration))); // Add Start and end trim to create EDL file
            EDL edl = new EDL(_profile, "", GlobalDefs.MAX_VIDEO_DURATION, TempEDLFile, 0, _jobStatus, _jobLog, true);                     // Ignore minimum segment since we are trimming subtitles

            if (!edl.CreateEDLFile(keepList))                                                                                              // Create the EDL file
            {
                _jobLog.WriteEntry(this, ("Cannot trim SRT file"), Log.LogEntryType.Error);
                return(false);
            }

            // Now use the EDL file to trim the SRT file
            CutWithEDL(TempEDLFile, srtFile, offset, 0, true); // Ignore minimum cut since we are trimming here and not cutting commercials
            FileIO.TryFileDelete(TempEDLFile);                 // clean up temp edl file

            return(true);
        }