public TVViewer() { // initialize sdl stuff screen = Sdl.SDL_SetVideoMode(720, 576, 32, Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF); yuvOverlay = Sdl.SDL_CreateYUVOverlay(720, 576, Sdl.SDL_YUY2_OVERLAY, screen); rect = new Sdl.SDL_Rect(0, 0, 720, 576); pixels = Marshal.ReadIntPtr(Marshal.ReadIntPtr(yuvOverlay, 20)); // initialize adapter adapter = new Adapter("/dev/video0"); adapter.SetControlValue(Control.Mute, 0); // set desired capture method adapter.CaptureMethod = CaptureMethod.ReadWrite; // set video format VideoCaptureFormat format = new VideoCaptureFormat(720, 576); format.PixelFormat = v4l2_pix_format_id.YUYV; format.Field = v4l2_field.Interlaced; adapter.SetFormat(format); adapter.Input = adapter.Inputs[adapter.Inputs.IndexOf("Name", "Television")]; adapter.Standard = adapter.Standards[adapter.Standards.IndexOf("Name", "PAL")]; Events.Quit += quit; Events.KeyboardDown += keyDown; }
static void RawToPGM(string extra,long stamp, VideoCaptureFormat format, byte[] buffer, bool save) { if (!save) { return; } int w = (int)format.Width, h = (int)format.Height; string name = stamp.ToString("000000000000") + extra + ".pgm"; FileStream fs = File.Open(name,FileMode.CreateNew,FileAccess.Write,FileShare.Read); string header = "P5 "+w+" "+h+" 65535 "; byte[] bh = Encoding.ASCII.GetBytes(header); fs.Write(bh,0,bh.Length); fs.Write(buffer,0,buffer.Length); fs.Close(); }
static byte[] Init(Adapter adapter, out VideoCaptureFormat format) { format = new VideoCaptureFormat() { Field = Video4Linux.Analog.Kernel.v4l2_field.Any ,Width = 358,Height = 288 ,PixelFormat = Video4Linux.Analog.Kernel.v4l2_pix_format_id.GREY }; adapter.SetFormat(format); //adapter.GetFormat(format); int count = (int)(format.Width*format.Height*2); byte[] buffer = new byte[count]; //WL("Method "+adapter.CaptureMethod+" "+format.Width+" "+format.Height+" "+format.PixelFormat+" "+format.Field+" "+format.BytesPerLine+" "+count); return buffer; }