private void Button_Click(object sender, RoutedEventArgs e) { string _testMovie = @"d:\Test\Inglorious Basterds [2009]\CD1 Inglorious Basterds.avi"; string _ffmpeg = @"d:\Work\mtn-200808a-win32\mtn.exe"; //VideoScreenShot.MakeThumbnail(_testMovie); double _duration = 0d; // MediaInfoManager.GetDurationMilliseconds(movieFilename); System.Windows.Size _size = new System.Windows.Size(); // MediaInfoManager.GetVideoResolution(movieFilename); MediaInfoManager.GetDurationAndVideoResolution(_testMovie, out _duration, out _size); int _cnt = 5; System.Windows.Size _thumbSize = FileManager.Configuration.Options.ThumbnailSize; double _rap = 1; if (_size.Width >= _size.Height) { _rap = _size.Width / _thumbSize.Width; _cnt = (int)Math.Round(_thumbSize.Height / (_size.Height / _rap)); } else { _rap = _size.Height / _thumbSize.Height; _cnt = (int)Math.Round(_thumbSize.Width / (_size.Width / _rap)); } //string _command = string.Format("{0} -i \"{1}\" -ss 0:0:5.0 -vframes 1 -vcodec png -y -f image2 frame.png", string _command = string.Format(" -o .tg.jpg -w {0} -t -c 1 -h 10 -r {1} -i -b 0.50 -D 12 -P \"{2}\"", FileManager.Configuration.Options.ThumbnailSize.Width, _cnt, _testMovie); string _imageUrl = Path.ChangeExtension(Helpers.GetCorrectThumbnailPath(_testMovie, true), ".tg.jpg"); try { ProcessStartInfo _pi = new ProcessStartInfo(_ffmpeg, _command); _pi.CreateNoWindow = true; _pi.UseShellExecute = false; Process.Start(_pi).WaitForExit(20000); if (File.Exists(_imageUrl)) { Helpers.CreateThumbnailImage(_imageUrl, Helpers.GetCorrectThumbnailPath(_testMovie, true), true, true, Helpers.ThumbnailSize, false, Helpers.MaxThumbnailFilesize); } } finally { if (File.Exists(_imageUrl)) { try { File.Delete(_imageUrl); } catch { } } } //MoviePlayer.Show(this, @"d:\Test\Inglorious Basterds [2009]\CD1 Inglorious Basterds.avi", null, new Size(0,0)); }
public static bool MakeThumbnail2(string movieFilename, string targetFile) { bool _result = false; double _duration = 0d; // MediaInfoManager.GetDurationMilliseconds(movieFilename); System.Windows.Size _size = new System.Windows.Size(); // MediaInfoManager.GetVideoResolution(movieFilename); MediaInfoManager.GetDurationAndVideoResolution(movieFilename, out _duration, out _size); if (_duration != 0d) { Collection <string> _snaps = new Collection <string>(); Random _rnd = new Random(); Dictionary <TimeSpan, object> _frames = new Dictionary <TimeSpan, object>(); List <string> _filesList = new List <string>(); try { int _cnt = 5; System.Windows.Size _thumbSize = FileManager.Configuration.Options.ThumbnailSize; double _rap = 1; if (_size.Width >= _size.Height) { _rap = _size.Width / _thumbSize.Width; _cnt = (int)Math.Round(_thumbSize.Height / (_size.Height / _rap)); } else { _rap = _size.Height / _thumbSize.Height; _cnt = (int)Math.Round(_thumbSize.Width / (_size.Width / _rap)); } for (int _i = 0; _i < _cnt; _i++) { string _thumb = Helpers.GetUniqueFilename(".jpg"); _filesList.Add(_thumb); int _start = (int)((_i * _duration) / _cnt); int _stop = (int)(((_i + 1) * _duration) / _cnt); _frames.Add(TimeSpan.FromMilliseconds((double)_rnd.Next(_start, _stop)), _thumb); } if (VideoScreenShot.CaptureScreen(new Uri(movieFilename, UriKind.RelativeOrAbsolute), _frames, makeJpeg)) { VideoScreenShot.GenerateThumbnail(_filesList, targetFile); if (FileManager.Configuration.Options.AutogenerateFolderJpg) { try { File.Copy(targetFile, FileManager.Configuration.GetFolderjpgPath(movieFilename, true), FileManager.Configuration.Options.OverwriteExistingThumbs); } catch { } } _result = true; } } finally { foreach (string _file in _filesList) { try { if (File.Exists(_file)) { File.Delete(_file); } } catch { } } } } return(_result); }
public static bool MakeBackdropSnapshot(string movieFilename, string targetFile) { bool _result = false; if (FileManager.Configuration.Options.IsMTNPathSpecified) { if (Path.GetExtension(movieFilename).ToLowerInvariant().Contains(".iso")) { return(false); } double _duration = 0d; System.Windows.Size _size = new System.Windows.Size(); MediaInfoManager.GetDurationAndVideoResolution(movieFilename, out _duration, out _size); // always skip 10% from the beginning and from the end of the movie int _minSkipSeconds = (int)((_duration / 1000) * 0.1); Random _rand = new Random(); _duration = (int)(_duration / 1000); try { int _omitSec = _rand.Next(_minSkipSeconds, (int)_duration / 2 - _minSkipSeconds); // choose a number between minSkipSeconds and half of the duration int _omitEnd = _rand.Next(_minSkipSeconds, (int)_duration / 2 - _minSkipSeconds); // chose a number between minSkipSeconds and half of the duration string _command = string.Format(" -o .tmp -B {0} -E {1} -t -c 1 -r 1 -i -b 0{2}50 -D 6 -P \"{3}\"", _omitSec, _omitEnd, Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator, movieFilename); string _imageUrl = Path.ChangeExtension(movieFilename, ".tmp"); FileManager.AddToGarbageFiles(_imageUrl); try { ProcessStartInfo _pi = new ProcessStartInfo(FileManager.Configuration.Options.MTNPath, _command); _pi.CreateNoWindow = true; _pi.UseShellExecute = false; Process _p = Process.Start(_pi); _p.WaitForExit(8000); Thread.Sleep(1200); // wait for the file to become available if (File.Exists(_imageUrl)) { try { File.Copy(_imageUrl, targetFile, true); _result = true; } catch (Exception ex) { Loggy.Logger.DebugException("Videosnapshot: ", ex); } } } finally { Helpers.RemoveFile(_imageUrl); } } catch (Exception ex) { Loggy.Logger.DebugException("Calculate skip ", ex); } } return(_result); }