Пример #1
0
 public abstract void WriteChapter( FrameInfo currentFrame );
Пример #2
0
 public override void WriteChapter( FrameInfo currentFrame )
 {
     ChapterStreamWriter.WriteLine( String.Format( "{0}", currentFrame.FrameNumber ) );
 }
Пример #3
0
 public override void WriteChapter( FrameInfo currentFrame )
 {
     ChapterStreamWriter.WriteLine( String.Format( "{0:00}:{1:00}:{2:00}:{3:00}",
         currentFrame.Hour, currentFrame.Minute, currentFrame.Second, (currentFrame.MilliSecond / 10) ) );
 }
Пример #4
0
 public abstract void WriteSubtitle( string formattedFilename, int subNumber, FrameInfo start, FrameInfo end );
Пример #5
0
 public override void WriteSubtitle( string formattedFilename, int subNumber, FrameInfo start, FrameInfo end )
 {
     SubtitleStreamWriter.WriteLine( String.Format( "{0:00}:{1:00}:{2:00}:{3:00} {4:00}:{5:00}:{6:00}:{7:00} {8}",
         start.Hour, start.Minute, start.Second, (start.MilliSecond / 10),
         end.Hour, end.Minute, end.Second, (end.MilliSecond / 10), formattedFilename ) );
 }
Пример #6
0
 public override void WriteSubtitle( string formattedFilename, int subNumber, FrameInfo start, FrameInfo end )
 {
     throw new NotImplementedException();
 }
Пример #7
0
 public override void WriteSubtitle( string formattedFilename, int subNumber, FrameInfo start, FrameInfo end )
 {
     SubtitleStreamWriter.WriteLine( "FileName: " + formattedFilename + "\t" );
     SubtitleStreamWriter.WriteLine( String.Format( "Duration: {0:00}:{1:00}:{2:00}.{3:000} to \r\n",
         start.Hour, start.Minute, start.Second, start.MilliSecond ) );
 }
Пример #8
0
        //Search Function
        public bool Process()
        {
            bool success = true;

            String currentDirectory = Environment.CurrentDirectory;

            //Create recursively a list with all the files complying with the criteria
            List<FileInfo> videoFileInfos = new List<FileInfo>();

            foreach (string fileName in _args.Filenames )
            {
                //Eliminate white spaces
                var trimmedFileName = fileName.Trim();

                var filename = Path.GetFileName( trimmedFileName );
                var fileDirectory = Path.GetDirectoryName( trimmedFileName );

                if ( String.IsNullOrWhiteSpace( fileDirectory ) )
                {
                    fileDirectory = currentDirectory;
                }

                videoFileInfos.AddRange( GetFiles( fileDirectory, filename, _args.Recursive ) );
            }

            if ( videoFileInfos.Count == 0 )
            {
                success = false;
                UpdateStatus( "no files to process" );
            }

            if ( success )
            {
                using ( BaseChapterWriter chapterWriter = _args.ChapterWriterFactory.Create( _args.ChapterFileName ) )
                using ( BaseSubtitleWriter subtitleWriter = _args.SubtitleWriterFactory.Create( _args.SubtitleFileName ) )
                {
                    bool addDefaultPrefix = !String.IsNullOrEmpty( _args.SubtitlePrefixFilename ) && !_args.SubtitlePrefixFilename.Equals( "auto", StringComparison.OrdinalIgnoreCase );
                    if ( addDefaultPrefix )
                    {
                        FileInfo SubtitlePrefix = new FileInfo( _args.SubtitlePrefixFilename );
                        StreamReader SubtitlePrefixFS = SubtitlePrefix.OpenText();
                        subtitleWriter.Prefix = SubtitlePrefixFS.ReadToEnd();
                        SubtitlePrefixFS.Close();
                    }

                    int fileCount = 0;
                    int subCount = 1;
                    bool empty = true;
                    FrameInfo totalFrameInfo = new FrameInfo();
                    totalFrameInfo.FrameRate = _args.FrameRate;
                    totalFrameInfo.Duration = 0;
                    string previousFormattedFilename = null;

                    // Sorts the values of the list
                    var orderedVideoFileInfos = videoFileInfos.OrderBy( videoFileInfo => videoFileInfo.FullName );
                    foreach ( FileInfo videoFileInfo in orderedVideoFileInfos )
                    {
                        try
                        {
                            UpdateStatus( $"Processing '{videoFileInfo.Name}'" );

                            FilgraphManager filterGraphManager = null;
                            IMediaPosition mediaPosition = null;
                            filterGraphManager = new FilgraphManager();
                            filterGraphManager.RenderFile( videoFileInfo.FullName );

                            // Find file's frame rate
                            double fileFrameRate = 1 / ((IBasicVideo)filterGraphManager).AvgTimePerFrame;
                            
                            mediaPosition = filterGraphManager as IMediaPosition;
                            string formattedFilename = Path.GetFileNameWithoutExtension( videoFileInfo.Name );
                            if ( _args.Scenalyzer )
                            {
                                formattedFilename = ScenalyzerFormat( formattedFilename );
                            } else
                            {
                                string formattedFileDateTime = formattedFilename;
                                if ( formattedFileDateTime.Contains( "(" ) )
                                {
                                    formattedFileDateTime = formattedFileDateTime.Substring( 0, formattedFileDateTime.IndexOf( "(" ) );
                                }
                                formattedFileDateTime = formattedFileDateTime.Replace( ".", ":" );
                                
                                DateTime fileDateTime;
                                if ( DateTime.TryParse( formattedFileDateTime, out fileDateTime ) )
                                {
                                    formattedFilename = FormatDateTime( fileDateTime );
                                }
                            }
                            fileCount++;
                            FrameInfo Start = new FrameInfo();
                            Start.FrameRate = fileFrameRate;
                            Start.Duration = totalFrameInfo.Duration;
                            Start.Duration += SECONDS_DELAY_BEFORE_SUBTITLE_DISPLAY;
                            FrameInfo End = new FrameInfo();
                            End.FrameRate = fileFrameRate;
                            End.Duration = Start.Duration + _args.SubDuration;
                            
                            bool writeMarkers = (_args.IncludeDuplicates || previousFormattedFilename != formattedFilename);

                            if ( writeMarkers )
                            {
                                chapterWriter.WriteChapter( totalFrameInfo );
                                UpdateStatus( $"Writing chapter at {totalFrameInfo.Duration} seconds" );
                            }
                            else
                            {
                                UpdateStatus( "Skipped" );
                            }

                            totalFrameInfo.Duration += mediaPosition.Duration;

                            if ( writeMarkers )
                            {
                                if ( End.Duration > totalFrameInfo.Duration )
                                {
                                    End.Duration = totalFrameInfo.Duration - (1 / fileFrameRate);
                                }

                                subtitleWriter.WriteSubtitle( formattedFilename, subCount, Start, End );
                                subCount++;
                                UpdateStatus( $"Writing subtitle {formattedFilename} at {Start.Duration:#.##} to {End.Duration:#.##}" );
                            }
                            
                            previousFormattedFilename = formattedFilename;
                            filterGraphManager.Stop();
                            empty = false;

                            if ( mediaPosition != null )
                            {
                                mediaPosition = null;
                            }
                            if ( filterGraphManager != null )
                            {
                                Marshal.FinalReleaseComObject( filterGraphManager );
                                filterGraphManager = null;
                            }
                        }
                        catch ( SecurityException ex )
                        {
                            UpdateStatus( $"File, '{videoFileInfo.FullName}' was unable to be opened due to a security exception: {ex.Message}" );
                        }
                        catch ( FileNotFoundException )
                        {
                            UpdateStatus( $"File, '{videoFileInfo.FullName}' was not found" );
                        }
                    }
                    totalFrameInfo.Duration -= .2;
                    chapterWriter.WriteChapter( totalFrameInfo );
                    
                    if ( empty == true )
                    {
                        success = false;
                        UpdateStatus( "No matches found!" );
                    }
                    else
                    {
                        UpdateStatus( $"Processed {fileCount} Files!" );
                    }
                }
            }

            return success;
        }