Example #1
0
        private static void GenerateForVid(string videoFile, VideoThumbnailerConfig config, bool doRemoveFirst)
        {
            // First check if thumbs are there
            var filePattern = ExtractFileNameForSave(Path.GetFileName(videoFile), "") + "*" + DEFAULT_THUMB_EXT;
            var fld = new DirectoryInfo(Path.GetDirectoryName(videoFile));

            // Do we need to clean first? (a.k.a. regenerate always?)
            if (fld.GetFiles(filePattern).Length == 0 || doRemoveFirst)
            {
                FFmpegMediaInfo info = new FFmpegMediaInfo(videoFile, config.ffmpeg.ffprobe_path);

                if (config.settings.info_json_generation)
                    WriteVideoInfoToFile(info, videoFile);

                //Take video snapshots (config: thumbcount)
                double length = info.Duration.TotalSeconds;
                double step = length/config.settings.thumbcount;
                double pos = config.settings.first_thumbnail_sec; // set first thumb
                Dictionary<TimeSpan, Bitmap> snapshots = new Dictionary<TimeSpan, Bitmap>();
                while (pos < length)
                {
                    TimeSpan position = TimeSpan.FromSeconds(pos);
                    try
                    {
                        if (pos + step > length)
                        {
                            //it is the last
                            position = TimeSpan.FromSeconds(pos - config.settings.last_thumbnail_sec);
                        }

                        Bitmap bmp = info.GetSnapshot(position, config.ffmpeg.ffmpeg_path);
                        snapshots[position] = bmp;

                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                    }

                    pos += step;
                }

                //Write snapshots to file
                WriteSnapshotsToFile(snapshots, videoFile, config.settings.subdir, config.settings.thumbquality,
                    doRemoveFirst);
            }
        }
Example #2
0
 public VidThumbnailer(VideoThumbnailerConfig config)
 {
     conf = config;
 }
Example #3
0
        private static void ProcessDirectory(string dirpath, bool resursiveSpecified, bool resursive, bool removeSpecified, bool remove, VideoThumbnailerConfig _conf)
        {
            if (Directory.Exists(dirpath))
            {
                Console.WriteLine("Processing Directory: " + dirpath);

                // default remove setting
                bool doRemoveFirst = _conf.settings.remove_old_first;
                // override for specific directory?
                if (removeSpecified)
                {
                    doRemoveFirst = remove;
                }

                var files = new DirectoryInfo(dirpath).GetFiles()
                           .Where(
                               f =>
                               f.Extension.ToLowerInvariant().In(wantedFileExts)).ToList();

                foreach (var videoFile in files)
                {
                    GenerateForVid(videoFile.FullName, _conf, doRemoveFirst);
                    //Debug.WriteLine(fileName);
                }

                // default: recurse setting
                bool doRecursive = _conf.settings.resursive;

                // override for specific directory?
                if (resursiveSpecified)
                {
                    doRecursive = resursive;
                }

                // So, do we need to process sub directories?
                if (doRecursive)
                {
                    var dirs = new DirectoryInfo(dirpath).GetDirectories();
                    foreach (var dir in dirs)
                    {
                        ProcessDirectory(dir.FullName, resursiveSpecified, resursive, removeSpecified, remove, _conf);
                    }
                }
            }
        }