class VideoInputFrameGrabber extends FrameGrabber {
    public static String[] getDeviceDescriptions() throws Exception {
        tryLoad();

        int count = videoInput.listDevices();
        String[] descriptions = new String[count];
        for (int i = 0; i < descriptions.length; i++) {
            descriptions[i] = videoInput.getDeviceName(i).getString();
        }
        return descriptions;
    }

    public static VideoInputFrameGrabber createDefault(File deviceFile)   throws Exception { throw new Exception(VideoInputFrameGrabber.class + " does not support device files."); }
    public static VideoInputFrameGrabber createDefault(String devicePath) throws Exception { throw new Exception(VideoInputFrameGrabber.class + " does not support device paths."); }
    public static VideoInputFrameGrabber createDefault(int deviceNumber)  throws Exception { return new VideoInputFrameGrabber(deviceNumber); }

    private static Exception loadingException = null;
    public static void tryLoad() throws Exception {
        if (loadingException != null) {
            throw loadingException;
        } else {
            try {
                Loader.load(org.bytedeco.videoinput.global.videoInputLib.class);
            } catch (Throwable t) {
                throw loadingException = new Exception("Failed to load " + VideoInputFrameGrabber.class, t);
            }
        }
    }

    public VideoInputFrameGrabber(int deviceNumber) {
        this.deviceNumber = deviceNumber;
    }
    public void release() throws Exception {
        stop();
    }
    @Override protected void finalize() throws Throwable {
        super.finalize();
        release();
    }

    private int deviceNumber = 0;
    private videoInput myVideoInput = null;
    private IplImage bgrImage = null, grayImage = null;
    private BytePointer bgrImageData = null;
    private FrameConverter converter = new OpenCVFrameConverter.ToIplImage();

    @Override public double getGamma() {
        // default to a gamma of 2.2 for cheap Webcams, DV cameras, etc.
        if (gamma == 0.0) {
            return 2.2;
        } else {
            return gamma;
        }
    }

    @Override public int getImageWidth() {
        return myVideoInput == null ? super.getImageWidth() : myVideoInput.getWidth(deviceNumber);
    }

    @Override public int getImageHeight() {
        return myVideoInput == null ? super.getImageHeight() : myVideoInput.getHeight(deviceNumber);
    }

    public void start() throws Exception {
        start(-1);
    }
    public void start(int connection) throws Exception {<FILL_FUNCTION_BODY>}

    public void stop() throws Exception {
        if (myVideoInput != null) {
            myVideoInput.stopDevice(deviceNumber);
            myVideoInput = null;
        }
    }

    public void trigger() throws Exception {
        if (myVideoInput == null) {
            throw new Exception("videoInput is null. (Has start() been called?)");
        }
        int w = myVideoInput.getWidth(deviceNumber), h = myVideoInput.getHeight(deviceNumber);
        if (bgrImage == null || bgrImage.width() != w || bgrImage.height() != h) {
            bgrImage = IplImage.create(w, h, IPL_DEPTH_8U, 3);
            bgrImageData = bgrImage.imageData();
        }

        for (int i = 0; i < numBuffers+1; i++) {
            myVideoInput.getPixels(deviceNumber, bgrImageData, false, true);
        }
    }

    public Frame grab() throws Exception {
        if (myVideoInput == null) {
            throw new Exception("videoInput is null. (Has start() been called?)");
        }
        int w = myVideoInput.getWidth(deviceNumber), h = myVideoInput.getHeight(deviceNumber);
        if (bgrImage == null || bgrImage.width() != w || bgrImage.height() != h) {
            bgrImage = IplImage.create(w, h, IPL_DEPTH_8U, 3);
            bgrImageData = bgrImage.imageData();
        }

        if (!myVideoInput.getPixels(deviceNumber, bgrImageData, false, true)) {
            throw new Exception("videoInput.getPixels() Error: Could not get pixels.");
        }
        timestamp = System.nanoTime()/1000;

        if (imageMode == ImageMode.GRAY) {
            if (grayImage == null) {
                grayImage = IplImage.create(w, h, IPL_DEPTH_8U, 1);
            }
            cvCvtColor(bgrImage, grayImage, CV_BGR2GRAY);
            return converter.convert(grayImage);
        } else {
            return converter.convert(bgrImage);
        }
    }
}

        myVideoInput = new videoInput();
        if (frameRate > 0) {
            myVideoInput.setIdealFramerate(deviceNumber, (int)frameRate);
        }
        if (!myVideoInput.setupDevice(deviceNumber, imageWidth  > 0 ? imageWidth  : 640,
                                                    imageHeight > 0 ? imageHeight : 480, connection)) {
            myVideoInput = null;
            throw new Exception("videoInput.setupDevice() Error: Could not setup device.");
        }
        if (format != null && format.length() > 0) {
            int f = format.equals("VI_NTSC_M")   ? VI_NTSC_M   :
                    format.equals("VI_PAL_B")    ? VI_PAL_B    :
                    format.equals("VI_PAL_D")    ? VI_PAL_D    :
                    format.equals("VI_PAL_G")    ? VI_PAL_G    :
                    format.equals("VI_PAL_H")    ? VI_PAL_H    :
                    format.equals("VI_PAL_I")    ? VI_PAL_I    :
                    format.equals("VI_PAL_M")    ? VI_PAL_M    :
                    format.equals("VI_PAL_N")    ? VI_PAL_N    :
                    format.equals("VI_PAL_NC")   ? VI_PAL_NC   :
                    format.equals("VI_SECAM_B")  ? VI_SECAM_B  :
                    format.equals("VI_SECAM_D")  ? VI_SECAM_D  :
                    format.equals("VI_SECAM_G")  ? VI_SECAM_G  :
                    format.equals("VI_SECAM_H")  ? VI_SECAM_H  :
                    format.equals("VI_SECAM_K")  ? VI_SECAM_K  :
                    format.equals("VI_SECAM_K1") ? VI_SECAM_K1 :
                    format.equals("VI_SECAM_L")  ? VI_SECAM_L  :
                    format.equals("VI_NTSC_M_J") ? VI_NTSC_M_J :
                    format.equals("VI_NTSC_433") ? VI_NTSC_433 : -1;
            if (f >= 0 && !myVideoInput.setFormat(deviceNumber, f)) {
                throw new Exception("videoInput.setFormat() Error: Could not set format " + format + ".");
            }
        }
    
<methods>public non-sealed void <init>() ,public void close() throws org.bytedeco.javacv.FrameGrabber.Exception,public static org.bytedeco.javacv.FrameGrabber create(Class<? extends org.bytedeco.javacv.FrameGrabber>, Class#RAW, java.lang.Object) throws org.bytedeco.javacv.FrameGrabber.Exception,public static org.bytedeco.javacv.FrameGrabber create(java.lang.String, java.io.File) throws org.bytedeco.javacv.FrameGrabber.Exception,public static org.bytedeco.javacv.FrameGrabber create(java.lang.String, java.lang.String) throws org.bytedeco.javacv.FrameGrabber.Exception,public static org.bytedeco.javacv.FrameGrabber create(java.lang.String, int) throws org.bytedeco.javacv.FrameGrabber.Exception,public org.bytedeco.javacv.FrameGrabber.Array createArray(org.bytedeco.javacv.FrameGrabber[]) ,public static org.bytedeco.javacv.FrameGrabber createDefault(java.io.File) throws org.bytedeco.javacv.FrameGrabber.Exception,public static org.bytedeco.javacv.FrameGrabber createDefault(java.lang.String) throws org.bytedeco.javacv.FrameGrabber.Exception,public static org.bytedeco.javacv.FrameGrabber createDefault(int) throws org.bytedeco.javacv.FrameGrabber.Exception,public void delayedGrab(long) ,public void flush() throws org.bytedeco.javacv.FrameGrabber.Exception,public static Class<? extends org.bytedeco.javacv.FrameGrabber> get(java.lang.String) throws org.bytedeco.javacv.FrameGrabber.Exception,public double getAspectRatio() ,public int getAudioBitrate() ,public int getAudioChannels() ,public int getAudioCodec() ,public java.lang.String getAudioCodecName() ,public int getAudioDisposition() ,public Map<java.lang.String,java.lang.String> getAudioMetadata() ,public java.lang.String getAudioMetadata(java.lang.String) ,public java.lang.String getAudioOption(java.lang.String) ,public Map<java.lang.String,java.lang.String> getAudioOptions() ,public Map<java.lang.String,java.nio.Buffer> getAudioSideData() ,public java.nio.Buffer getAudioSideData(java.lang.String) ,public int getAudioStream() ,public int getBitsPerPixel() ,public java.nio.charset.Charset getCharset() ,public static Class<? extends org.bytedeco.javacv.FrameGrabber> getDefault() ,public org.bytedeco.javacv.Frame getDelayedFrame() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException,public long getDelayedTime() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException,public java.lang.String getFormat() ,public int getFrameNumber() ,public double getFrameRate() ,public double getGamma() ,public int getImageHeight() ,public org.bytedeco.javacv.FrameGrabber.ImageMode getImageMode() ,public int getImageScalingFlags() ,public int getImageWidth() ,public int getLengthInFrames() ,public long getLengthInTime() ,public int getMaxDelay() ,public Map<java.lang.String,java.lang.String> getMetadata() ,public java.lang.String getMetadata(java.lang.String) ,public int getNumBuffers() ,public java.lang.String getOption(java.lang.String) ,public Map<java.lang.String,java.lang.String> getOptions() ,public int getPixelFormat() ,public int getSampleFormat() ,public org.bytedeco.javacv.FrameGrabber.SampleMode getSampleMode() ,public int getSampleRate() ,public long getSensorPattern() ,public int getTimeout() ,public long getTimestamp() ,public int getVideoBitrate() ,public int getVideoCodec() ,public java.lang.String getVideoCodecName() ,public int getVideoDisposition() ,public Map<java.lang.String,java.lang.String> getVideoMetadata() ,public java.lang.String getVideoMetadata(java.lang.String) ,public java.lang.String getVideoOption(java.lang.String) ,public Map<java.lang.String,java.lang.String> getVideoOptions() ,public Map<java.lang.String,java.nio.Buffer> getVideoSideData() ,public java.nio.Buffer getVideoSideData(java.lang.String) ,public int getVideoStream() ,public abstract org.bytedeco.javacv.Frame grab() throws org.bytedeco.javacv.FrameGrabber.Exception,public org.bytedeco.javacv.Frame grabAtFrameRate() throws org.bytedeco.javacv.FrameGrabber.Exception, java.lang.InterruptedException,public org.bytedeco.javacv.Frame grabFrame() throws org.bytedeco.javacv.FrameGrabber.Exception,public static void init() ,public boolean isDeinterlace() ,public boolean isTriggerMode() ,public abstract void release() throws org.bytedeco.javacv.FrameGrabber.Exception,public void resetStartTime() ,public void restart() throws org.bytedeco.javacv.FrameGrabber.Exception,public void setAspectRatio(double) ,public void setAudioBitrate(int) ,public void setAudioChannels(int) ,public void setAudioCodec(int) ,public void setAudioCodecName(java.lang.String) ,public void setAudioDisposition(int) ,public void setAudioMetadata(Map<java.lang.String,java.lang.String>) ,public void setAudioMetadata(java.lang.String, java.lang.String) ,public void setAudioOption(java.lang.String, java.lang.String) ,public void setAudioOptions(Map<java.lang.String,java.lang.String>) ,public void setAudioSideData(Map<java.lang.String,java.nio.Buffer>) ,public void setAudioSideData(java.lang.String, java.nio.Buffer) ,public void setAudioStream(int) ,public void setBitsPerPixel(int) ,public void setCharset(java.nio.charset.Charset) ,public void setDeinterlace(boolean) ,public void setFormat(java.lang.String) ,public void setFrameNumber(int) throws org.bytedeco.javacv.FrameGrabber.Exception,public void setFrameRate(double) ,public void setGamma(double) ,public void setImageHeight(int) ,public void setImageMode(org.bytedeco.javacv.FrameGrabber.ImageMode) ,public void setImageScalingFlags(int) ,public void setImageWidth(int) ,public void setMaxDelay(int) ,public void setMetadata(Map<java.lang.String,java.lang.String>) ,public void setMetadata(java.lang.String, java.lang.String) ,public void setNumBuffers(int) ,public void setOption(java.lang.String, java.lang.String) ,public void setOptions(Map<java.lang.String,java.lang.String>) ,public void setPixelFormat(int) ,public void setSampleFormat(int) ,public void setSampleMode(org.bytedeco.javacv.FrameGrabber.SampleMode) ,public void setSampleRate(int) ,public void setSensorPattern(long) ,public void setTimeout(int) ,public void setTimestamp(long) throws org.bytedeco.javacv.FrameGrabber.Exception,public void setTriggerMode(boolean) ,public void setVideoBitrate(int) ,public void setVideoCodec(int) ,public void setVideoCodecName(java.lang.String) ,public void setVideoDisposition(int) ,public void setVideoMetadata(Map<java.lang.String,java.lang.String>) ,public void setVideoMetadata(java.lang.String, java.lang.String) ,public void setVideoOption(java.lang.String, java.lang.String) ,public void setVideoOptions(Map<java.lang.String,java.lang.String>) ,public void setVideoSideData(Map<java.lang.String,java.nio.Buffer>) ,public void setVideoSideData(java.lang.String, java.nio.Buffer) ,public void setVideoStream(int) ,public abstract void start() throws org.bytedeco.javacv.FrameGrabber.Exception,public abstract void stop() throws org.bytedeco.javacv.FrameGrabber.Exception,public abstract void trigger() throws org.bytedeco.javacv.FrameGrabber.Exception,public boolean waitForTimestamp(org.bytedeco.javacv.Frame) throws java.lang.InterruptedException<variables>public static final long SENSOR_PATTERN_BGGR,public static final long SENSOR_PATTERN_GBRG,public static final long SENSOR_PATTERN_GRBG,public static final long SENSOR_PATTERN_RGGB,protected double aspectRatio,protected int audioBitrate,protected int audioChannels,protected int audioCodec,protected java.lang.String audioCodecName,protected int audioDisposition,protected Map<java.lang.String,java.lang.String> audioMetadata,protected Map<java.lang.String,java.lang.String> audioOptions,protected Map<java.lang.String,java.nio.Buffer> audioSideData,protected int audioStream,protected int bpp,protected java.nio.charset.Charset charset,protected boolean deinterlace,private org.bytedeco.javacv.Frame delayedFrame,private long delayedTime,private java.util.concurrent.ExecutorService executor,protected java.lang.String format,protected int frameNumber,protected double frameRate,private Future<java.lang.Void> future,protected double gamma,protected int imageHeight,protected org.bytedeco.javacv.FrameGrabber.ImageMode imageMode,protected int imageScalingFlags,protected int imageWidth,public static final List<java.lang.String> list,protected int maxDelay,protected Map<java.lang.String,java.lang.String> metadata,protected int numBuffers,protected Map<java.lang.String,java.lang.String> options,protected int pixelFormat,protected int sampleFormat,protected org.bytedeco.javacv.FrameGrabber.SampleMode sampleMode,protected int sampleRate,protected long sensorPattern,protected long startTime,protected int timeout,protected long timestamp,protected boolean triggerMode,protected int videoBitrate,protected int videoCodec,protected java.lang.String videoCodecName,protected int videoDisposition,protected Map<java.lang.String,java.lang.String> videoMetadata,protected Map<java.lang.String,java.lang.String> videoOptions,protected Map<java.lang.String,java.nio.Buffer> videoSideData,protected int videoStream