static void Main(string[] args) { //initialize capture and buffer VideoCaptureBase capture = new FileCapture("../Resources/video-vignette.mp4"); // /*or*/ capture = new CameraCapture(); Bgr <byte>[,] frame = null; //initialize devignetting alg capture.ReadTo(ref frame); var devignetting = new Devignetting(frame, optimizeVignettingCentre: true); Bgr <byte>[,] correctedIm = frame.CopyBlank(); //do the job do { capture.ReadTo(ref frame); if (frame == null) { break; } frame.Show("Original"); frame.CopyTo(correctedIm, Point.Empty); bool isDone = devignetting.DevignetteSingleStep(correctedIm); correctedIm.Show("Corrected"); Console.WriteLine("Frame: {0:000}, is done: {1}", capture.Position, isDone); }while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)); capture.Close(); }
/// <summary> /// Get a list of frames from a video file in AVI format. /// </summary> /// <param name="filename">Input video filename.</param> /// <returns>Frame list.</returns> private List <Texture2D> frameListFromAvi(string filename) { List <Texture2D> frames = new List <Texture2D>(); using (FileCapture reader = FileCaptureX.CaptureLocalFile(filename)) { Console.WriteLine("reading file " + filename); foreach (Image <Bgr <byte> > image in reader) { Texture2D frame = new Texture2D(Graphics, image.Width, image.Height); Bgr <byte>[,] data = new Bgr <byte> [image.Height, image.Width]; Color[] linear = new Color[image.Width * image.Height]; image.CopyTo(data); int h = 0; for (int k = 0; k < image.Height; k++) { for (int i = 0; i < image.Width; i++) { linear[h++] = new Color(data[k, i].R, data[k, i].G, data[k, i].B); } } Console.WriteLine("frame " + reader.Position); frame.SetData(linear); frames.Add(frame); } Console.WriteLine("done."); reader.Close(); } return(frames); }
static void Main() { //var reader = new CameraCapture(0); //capture from camera var reader = new FileCapture(Path.Combine(getResourceDir(), "Welcome.mp4")); reader.Open(); var writer = new VideoWriter(@"output.avi", reader.FrameSize, /*reader.FrameRate does not work Cameras*/ 30); //TODO: bug: FPS does not work for cameras writer.Open(); Bgr <byte>[,] frame = null; do { reader.ReadTo(ref frame); if (frame == null) { break; } using (var uFrame = frame.Lock()) { writer.Write(uFrame); } frame.Show(scaleForm: true); }while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)); reader.Dispose(); writer.Dispose(); UI.CloseAll(); }
static void Main() { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";runtimes/win10-x64/"); //only needed if projects are directly referenced Console.WriteLine("Press ESC to stop playing"); //var reader = new CameraCapture(0); //capture from camera //(reader as CameraCapture).FrameSize = new Size(640, 480); var reader = new FileCapture(Path.Combine(getResourceDir(), "Welcome.mp4")); //capture from video //var reader = new ImageDirectoryCapture(Path.Combine(getResourceDir(), "Sequence"), "*.jpg"); reader.Open(); Bgr <byte>[,] frame = null; do { reader.ReadTo(ref frame); if (frame == null) { break; } frame.Show(autoSize: true); }while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)); reader.Dispose(); ImageUI.CloseAll(); }
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 reader = new CameraCapture(0); //capture from camera var reader = new FileCapture(Path.Combine(getResourceDir(), "Welcome.mp4")); reader.Open(); var writer = new VideoWriter(@"output.avi", reader.FrameSize, /*reader.FrameRate does not work Cameras*/ 30); //TODO: bug: FPS does not work for cameras writer.Open(); Bgr <byte>[,] frame = null; do { reader.ReadTo(ref frame); if (frame == null) { break; } using (var uFrame = frame.Lock()) { writer.Write(uFrame); } frame.Show(autoSize: true); }while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)); reader.Dispose(); writer.Dispose(); ImageUI.CloseAll(); }
static void Main() { Console.WriteLine("Press ESC to stop playing"); //var reader = new CameraCapture(0); //capture from camera //(reader as CameraCapture).FrameSize = new Size(640, 480); var reader = new FileCapture(Path.Combine(getResourceDir(), "Welcome.mp4")); //capture from video //var reader = new ImageDirectoryCapture(Path.Combine(getResourceDir(), "Sequence"), "*.jpg"); reader.Open(); Bgr <byte>[,] frame = null; do { reader.ReadTo(ref frame); if (frame == null) { break; } frame.Show(scaleForm: true); }while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)); reader.Dispose(); }
public static void Main() { //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 ImageStreamReader reader = new FileCapture(String.Format(@"\\.\pipe\{0}", pipeName)); reader.Open(); 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; pipeName = new Uri("https://www.youtube.com/watch?v=Vpg9yizPP_g").NamedPipeFromYoutubeUri(out fileExtension); //Youtube pipeName.SaveNamedPipeStream("out" + fileExtension); Console.WriteLine("Video saved."); }
private void VideoStreamWnd_Shown(object sender, EventArgs e) { try { project = ((MainForm)this.MdiParent).Project; VideoDataLine startDataLine = (VideoDataLine)dataStream.DataLines[0]; OpenVideo(startDataLine); trackBar.Minimum = 0; trackBar.Maximum = Convert.ToInt32(dataStream.Length * reader.FrameRate); SetFrameByTime(dataStream.StartTime); this.Text = "Video Stream: " + dataStream.ShortName; Refresh(); } catch (Exception ex) { reader = null; logger.WriteLineError(ex.ToString()); MessageBox.Show("Error during opening the file: " + ex.Message, "Error during opening video file", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult result = MessageBox.Show("Do you want to reload stream for appropriate video format?", "Reloading stream!", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { dataStream.WriteMetadata(logger); MessageBox.Show("Stream reloaded! Open stream again!", "Open stream again!", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } }
/// <summary> /// Uses the dotImaging library to extract each frame from a video and saving it. /// </summary> /// <param name="savePath">Where the frames should be saved.</param> /// <param name="filePath">Path to videofile.</param> public void videoImageExtractor(String savePath, String filePath) { var reader = new FileCapture(filePath); reader.Open(); reader.SaveFrames(savePath, "{0}.png"); reader.Close(); }
public override void Unload() { base.Unload(); videoPlayer.Dispose(); videoPlayer = null; capture = null; captureCache = null; }
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 }
private static FileCapture EmptyConstructedFileCapture() { FileCapture fc = (FileCapture)FormatterServices.GetUninitializedObject(typeof(FileCapture)); Console.WriteLine(fc); var baseconstructor = typeof(VideoCaptureBase).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] {}, null); baseconstructor.Invoke(fc, new object[] {}); return(fc); }
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 static void extractVideo(string fileName) { //get output dir (same as file name and in the same folder as video) var fileInfo = new FileInfo(fileName); var fileNameNoExt = fileInfo.Name.Replace(fileInfo.Extension, String.Empty); string outputDir = Path.Combine(fileInfo.DirectoryName, fileNameNoExt); //open video var reader = new FileCapture(fileName); reader.Open(); reader.SaveFrames(outputDir, "{0}.jpg", p => Console.Write($"\rExtracting: {(int)(p * 100)} %")); ImageUI.CloseAll(); }
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); } } }
private static void extractVideo(string fileName) { //get output dir (same as file name and in the same folder as video) var fileInfo = new FileInfo(fileName); var fileNameNoExt = fileInfo.Name.Replace(fileInfo.Extension, String.Empty); string outputDir = Path.Combine(fileInfo.DirectoryName, fileNameNoExt); //open video var reader = new FileCapture(fileName); reader.Open(); reader.SaveFrames(outputDir, "{0}.jpg", (percentage) => { ((double)percentage).Progress(message: "Extracting " + fileNameNoExt); }); UI.CloseAll(); }
private static void extractVideo(string fileName) { //get output dir (same as file name and in the same folder as video) var fileInfo = new FileInfo(fileName); var fileNameNoExt = fileInfo.Name.Replace(fileInfo.Extension, String.Empty); string outputDir = Path.Combine(fileInfo.DirectoryName, fileNameNoExt); //open video var reader = new FileCapture(fileName); reader.Open(); Console.WriteLine("Extracting video frames - {0}...", fileNameNoExt); reader.SaveFrames(outputDir, "{0}.jpg", (percentage) => { Console.Write("\r Completed: {0} %", (int)(percentage * 100)); }); Console.WriteLine(); }
/// <summary> /// Creates capture object from a local file. /// </summary> /// <returns>Capture object..</returns> /// <param name="fname">File name.</param> public static FileCapture CaptureLocalFile(string fname) { FileCapture fc = EmptyConstructedFileCapture(); string fileExt = Path.GetExtension(fname); if (supportedLocalFiles.Any(x => x.Equals(fileExt.ToLower())) == false) { throw new UriFormatException(String.Format("File must be a supported video file ({0}).", String.Join(", ", supportedLocalFiles))); } typeof(FileCapture).GetProperty("CanSeek").SetValue(fc, true); typeof(FileCapture).GetField("fileName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(fc, fname); //fc.CanSeek = true; //fc.fileName = fname; fc.Open(); //to enable property change return(fc); }
private void OpenVideo(VideoDataLine dataLine) { if (this.currentDataLine != null) { reader.Close(); } try { reader = new FileCapture(project.Folder + "\\" + dataStream.SubFolder + "\\" + dataLine.VideoFileName); reader.Open(); timer.Interval = Convert.ToInt32((1 / reader.FrameRate) * 1000); currentDataLine = dataLine; lblStatus.Text += "Current file: " + dataLine.VideoFileName; } catch (Exception ex) { lblStatus.Text = "Error: " + ex.Message; logger.WriteLineError("Error occured: " + ex.Message); throw ex; } }
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); }