Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 private static void WriteVideoInfoToFile(FFmpegMediaInfo info, string orignalVideoFileName)
 {
     string json = JsonConvert.SerializeObject(info, Formatting.Indented);
     var jsonInfoFile = ExtractFileNameForSave(orignalVideoFileName, ".json");
     System.IO.File.WriteAllText(jsonInfoFile, json);
 }