FMJ Webcam capture example
Asked Answered
L

3

7

I've been searching for while now and I can't find a simple example of how to capture a webcam stream with FMJ. Are there any tutorials or examples available which could help me?

Leu answered 14/8, 2009 at 12:32 Comment(0)
B
3

I have been working with FMJ for a while and I haven't found many examples to start with either. What I would do is to explore the FmjStudio class that has the webcam functionality integrated and its pretty straight forward.

For bob:

What you want is FMJ. FMJ uses an DataSource implementation for civil to use it with JMF. I would recommend you to go to http://fmj-sf.net/ download the latest source and explore FmjStudio aswell since it uses civil to capture.

For theDude:

You are right, you can use JMF aswell but the same code you use for JMF will most likely work with FMJ (maybe with a coupla changes) and the performance will be much better, specially if you want a wide range of different webcams to work with your software.

Broeder answered 23/3, 2010 at 7:47 Comment(0)
E
1

I know this isn't what you want to hear, but I've used JMF for this task and it works very well. There are enough examples online to get a simple web cam capture app running pretty easily. I'll post more if you're interested.

Extremist answered 14/8, 2009 at 13:44 Comment(3)
I have a JMF example with the following problem https://mcmap.net/q/1626565/-painting-over-jmf-component Thats why I wanted to try FMJLeu
I know this is old, but could you point me to a working JMF example?Macrography
Check this question: #17586417Extremist
F
0

The following code would get you started.

GlobalCaptureDevicePlugger.addCaptureDevices(); 
    Vector<CaptureDeviceInfo> audioCapDevList = CaptureDeviceManager.getDeviceList(null);
    if (audioCapDevList.size() != 0) {
        for (int i = 0; i < audioCapDevList.size(); i++) {
            audioCapDevInfo = audioCapDevList.elementAt(i);
            Format[] videoFormats = audioCapDevInfo.getFormats();
            System.out.println(audioCapDevInfo);
            if (audioCapDevInfo.getName().startsWith("vfw:")) { // assume the name of the webcam starts with vfw:
                for (int j = 0; j < videoFormats.length; j++) {
                    if (videoFormats[j] instanceof VideoFormat) {
                        currentFormat = (VideoFormat) videoFormats[i];
                        break;
                    }
                }
                System.out.println(currentFormat);
                if (currentFormat == null) {
                    System.err.println("Search for VideoFormat failed");
                    System.exit(-1);
                }
                audioCapDevLoc = audioCapDevInfo.getLocator();
            }

        }
    }

Please make sure the native libraries (civil.dll and jdshow.dll) are loaded into the JVM. Otherwise, you would get an java.lang.UnsatisfiedLinkError. The following code may do the job for you.

    System.setProperty("java.library.path", "D:/fmj-sf/native/win32-x86/");
    Field fieldSysPath;
    try {
        fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
        fieldSysPath.setAccessible(true);
        fieldSysPath.set(null, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
Fess answered 24/10, 2019 at 0:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.