private IEnumerable <IImage> GetEnumerable() { using (var capture = new FileCapture(path)) { capture.Seek(skipStart, SeekOrigin.Begin); var l = length ?? capture.Length; for (int i = 0; i < l; i++) { var enumerable = capture.Read(); yield return(enumerable); capture.Seek(skip); } } }
public static void Main() { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";runtimes/win10-x64/"); //only needed if projects are directly referenced var sourceName = String.Empty; //video over pipe (direct link and Youtube) (do not support seek) //var pipeName = new Uri("http://trailers.divx.com/divx_prod/divx_plus_hd_showcase/BigBuckBunny_DivX_HD720p_ASP.divx").NamedPipeFromVideoUri(); //web-video var pipeName = new Uri("https://www.youtube.com/watch?v=Vpg9yizPP_g").NamedPipeFromYoutubeUri(); //Youtube sourceName = String.Format(@"\\.\pipe\{0}", pipeName); //video http link (Supports seek) //sourceName = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"; //--------------------------------------------- ImageStreamReader reader = new FileCapture(sourceName); reader.Open(); //seek if you can if (reader.CanSeek) { reader.Seek((int)(reader.Length * 0.25), System.IO.SeekOrigin.Begin); } //read video frames Bgr <byte>[,] frame = null; while (true) { reader.ReadTo(ref frame); if (frame == null) { break; } frame.Show(scaleForm: false); ((double)reader.Position / reader.Length).Progress(); } Console.WriteLine("The end."); //--------------------------------------------------------------------------- UI.CloseAll(); Console.WriteLine("Downloading video..."); string fileExtension; var downloadPipeName = new Uri("https://www.youtube.com/watch?v=Vpg9yizPP_g").NamedPipeFromYoutubeUri(out fileExtension); //Youtube downloadPipeName.SaveNamedPipeStream("out" + fileExtension); Console.WriteLine("Video saved."); Process.Start("out" + fileExtension); //open local file }
public static void Main() { var sourceName = String.Empty; //video over pipe (direct link and Youtube) (do not support seek) //var pipeName = new Uri("http://trailers.divx.com/divx_prod/divx_plus_hd_showcase/BigBuckBunny_DivX_HD720p_ASP.divx").NamedPipeFromVideoUri(); //web-video var pipeName = new Uri("https://www.youtube.com/watch?v=Vpg9yizPP_g").NamedPipeFromYoutubeUri(); //Youtube sourceName = String.Format(@"\\.\pipe\{0}", pipeName); //video http link (Supports seek) //sourceName = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"; //--------------------------------------------- ImageStreamReader reader = new FileCapture(sourceName); reader.Open(); //seek if you can if (reader.CanSeek) { reader.Seek((int)(reader.Length * 0.25), System.IO.SeekOrigin.Begin); } //read video frames Bgr <byte>[,] frame = null; do { reader.ReadTo(ref frame); if (frame == null) { break; } frame.Show(scaleForm: true); ((double)reader.Position / reader.Length).Progress(); }while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)); Console.WriteLine("The end."); //--------------------------------------------------------------------------- Console.WriteLine("Downloading video..."); string fileExtension; var downloadPipeName = new Uri("https://www.youtube.com/watch?v=Vpg9yizPP_g").NamedPipeFromYoutubeUri(out fileExtension); //Youtube downloadPipeName.SaveNamedPipeStream("out" + fileExtension); Console.WriteLine("Video saved."); Process.Start("out" + fileExtension); //open local file }
private void SetFrame(int frame) { CurrentHotFrame = null; if (frame >= 0) { if (frame != currentFrame) { if (reader == null) { timer.Stop(); return; } // has to seek? if (currentFrame + 1 != frame) { reader.Seek(frame, System.IO.SeekOrigin.Begin); } if (frameBox.Image != null) { frameBox.Image.Dispose(); } reader.ReadTimeout = timer.Interval; Image <Bgr <byte> > img = reader.ReadAs <Bgr <byte> >(); //ResizeNearestNeighbor filter = new ResizeNearestNeighbor(400, 300); //Bitmap newImage = filter.Apply(img.ToBitmap()); if (img != null) { frameBox.Image = img.ToBitmap(); frameBox.ZoomToFit(); } currentFrame = frame; } } else { frameBox.Image = null; if (frame < 0) { currentFrame = 0; trackBar.Value = 0; } toolStripStatus.Text = "Outside of the stream time limits."; } }
public override void Load(IServiceProvider provider) { var context = (ITypeVisualizerContext)provider.GetService(typeof(ITypeVisualizerContext)); var visualizerElement = ExpressionBuilder.GetVisualizerElement(context.Source); capture = (FileCapture)ExpressionBuilder.GetWorkflowElement(visualizerElement.Builder); videoPlayer = new VideoPlayer { Dock = DockStyle.Fill }; videoPlayer.LoopChanged += (sender, e) => capture.Loop = videoPlayer.Loop; videoPlayer.PlayingChanged += (sender, e) => capture.Playing = videoPlayer.Playing; videoPlayer.PlaybackRateChanged += (sender, e) => capture.PlaybackRate = videoPlayer.PlaybackRate == frameRate ? 0 : Math.Max(1, videoPlayer.PlaybackRate); videoPlayer.Seek += (sender, e) => capture.Seek(e.FrameNumber); var visualizerService = (IDialogTypeVisualizerService)provider.GetService(typeof(IDialogTypeVisualizerService)); if (visualizerService != null) { visualizerService.AddControl(videoPlayer); } base.Load(provider); }