private static void TimerTick(Object o, ref GifImage a) { if (frameCount % 2 == 0) { //0, 2, 4, 6, ... if (secondFrameTask.IsCompleted) { var stream = secondFrameTask.Result; try { a = new GifImage(stream) { ReverseAtEnd = false }; Timer timer = new Timer((object obj) => FrameTimerTick(obj, ref a), null, 0, 60); } catch (Exception e) { Console.WriteLine(e.Message); } } } else { //1, 3, 5, 7, ... } GenerateAscii(a.GetNextFrame()); //timeCount++; // if (imageList.Count <= timeCount) // timeCount = 1; //File.WriteAllBytes(@"D:\Test\" + timeCount.ToString() + ".bmp", imageList[timeCount]); //var ms = new MemoryStream(imageList[timeCount]); //Image i = Image.FromStream(ms); GC.Collect(); }
static void Main(string[] args) { GifImage a; Console.CursorSize = 8; path = Console.ReadLine(); imageList = new List <byte[]> { }; frameCount = 0; //check if file is gif or video string ext = Path.GetExtension(path); if (ext.Equals(".gif")) { try { a = new GifImage(path) { ReverseAtEnd = false }; Timer timer = new Timer((object o) => TimerTick(o, ref a), null, 0, 60); } catch (Exception e) { Console.WriteLine(e.Message); } } //gif else { Stream rawBmpOutputStream = new MemoryStream(); var ffProbe = new NReco.VideoInfo.FFProbe(); var videoInfo = ffProbe.GetMediaInfo(path); var videoConv = new FFMpegConverter(); var ffMpegTask = videoConv.ConvertLiveMedia( path, null, // autodetect live stream format rawBmpOutputStream, // this is your special stream that will capture bitmaps Format.gif, new ConvertSettings() { VideoFrameSize = "1280*720", // lets resize to exact frame size VideoFrameRate = 24, // lets consume 24 frames per second MaxDuration = 10 // lets consume live stream for first 5 seconds }); ffMpegTask.Start(); ffMpegTask.Wait(); //var sr = new BinaryReader(rawBmpOutputStream); //sr.BaseStream.Position = 0; //using (var fileStream = File.Create(@"D:\test.gif")) //{ // rawBmpOutputStream.Seek(0, SeekOrigin.Begin); // rawBmpOutputStream.CopyTo(fileStream); //} try { a = new GifImage(rawBmpOutputStream) { ReverseAtEnd = false }; Timer timer = new Timer((object o) => TimerTick(o, ref a), null, 0, 60); } catch (Exception e) { Console.WriteLine(e.Message); } } //video Console.WindowWidth = Console.LargestWindowWidth; Console.WindowHeight = Console.LargestWindowHeight; // var t = new Timer((object o) => TimerTick(o, ref a), null, 0, 100); Console.ReadKey(); }
private static void FrameTimerTick(object o, ref GifImage a) { }