代码之家  ›  专栏  ›  技术社区  ›  user489041

如何使用JMF捕获视频,但不安装JMF

  •  13
  • user489041  · 技术社区  · 14 年前

    我正在研究的一个视频会议项目使用JMF捕获视频和音频,并将其传输到另一个端点。一个问题是,我的团队不希望产品的用户必须安装JMF。

    我认为分享我们解决这个问题的方法是值得的。它起作用了。它工作得很好。我想问你的是:有没有更好的方法?

    环境:Windows、XP及以上

    1. 把它安装到你的机器上

    2. 找到以下位置 dll 在jmf安装后的system32文件夹中:


      jcam.dll
      jmcvid.dll
      jmdaud.dll
      jmdaudc.dll
      jmdraw.dll
      jmfjawt.dll
      jmg723.dll

      jmsm.dll

      jmh263enc.dll
      jmjpeg.dll
      jmmci.dll

      jmmpegv.dll
      jmutil.dll
      jmvcm.dll
      jmvfw.dll
      jmvh263.dll
      jsound.dll

    3. 复制 放入临时文件夹

    4. 找到 jmf.properties
    5. 下载JMF源代码
      在源代码中,找到以下文件:

    JMFinit.java

    注册表.java
    java注册

    1. 创建一个包;我称之为 JMFNoInstall
    2. 添加步骤6中列出的文件
    3. 将名为Main的类添加到此包中,如下所示:

    package JMFNoInstall;
    // add your imports and whatnot here
    public class Main()
    {
        public Main()
        {
            JMFinit.main(null);
            JMFPropertiesGen.main(null);
            Registry.main(null);
            RegistryGen.main(new String[] {
                new File(".").getAbsolutePath(),
                "registrylib"
            });
        }
    }
    

    这个 jmf.属性 文件需要与具有 main 主要的 方法。
    动态链接库 我们需要进入 win32 文件夹。你可以让你的程序检查它们是否在 32年 文件夹。如果不是,你可以让它从某个地方复制过来。这个 jmf.属性 每当 Main jmf.jar 文件和 jmfcom.jar 与Windows JMF一起下载的文件包含在类路径中。你现在可以走了。JMF的所有功能实际上不需要安装它。

    有没有人找到更好的方法来做这件事?这样做有几个陷阱。

    编辑:我认为分享一些我创建的代码是值得的。当然你需要修改它来处理你的问题。它不可能编译,但是丢失的东西应该很容易重新创建。但我认为这可能是帮助人们的一个好的起点。detectCaptureDevices功能可能会帮助大多数人。我去的时候会更新这个类。

    
    import GUI.Window;
    import GlobalUtilities.OS;
    import GlobalUtilities.ProgressBar;
    import GlobalUtilities.FileUtilities;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.Vector;
    import javax.swing.text.Utilities;
    
    
    /**
     * This class providex easy access to the most needed info about JMF. You can test
     * a JMF install (Windows only currently) and also get info about the captrue
     * devices hooked up to JMF.
     * @author dvargo
     */
    public class JMFRunner
    {
        /**
         * Show the status of operations
         */
        final ProgressBar theBar = new ProgressBar();
        /**
         * Location where the dll's JMF relies on need to be placed
         */
        final String windowsDllFolder = "C:\\WINDOWS\\system32\\";
    
        final String linuxDllFolder = "/usr/lib/";
    
        /**
         * Dll's that JMF uses
         */
        final String[] windowsDllList = new String[]{
            "jmacm.dll",
            "jmam.dll",
            "jmcvid.dll",
            "jmdaud.dll",
            "jmdaudc.dll",
            "jmddraw.dll",
            "jmfjawt.dll",
            "jmg723.dll",
            "jmgdi.dll",
            "jmgsm.dll",
            "jmh261.dll",
            "jmh263enc.dll",
            "jmjpeg.dll",
            "jmmci.dll",
            "jmmpa.dll",
            "jmmpegv.dll",
            "jmutil.dll",
            "jmvcm.dll",
            "jmvfw.dll",
            "jmvh263.dll",
            "jsound.dll"};
    
        String[] linuxDllList = new String[]{
            "libjmcvid.so",
            "libjmdaud.so",
            "libjmfjawt.so",
            "libjmg723.so",
            "libjmgsm.so",
            "libjmh261.so",
            "libjmh263enc.so",
            "libjmjpeg.so",
            "libjmmpa.so",
            "libjmmpegv.so",
            "libjmmpx.so",
            "libjmutil.so",
            "libjmv4l.so",
            "libjmxlib.so"
        };
    
        String [] dlls= null;
        String dir = null;
    
        /**
         * List of the video capture devices found by JMF
         */
        Vector videoDevices = null;
        /**
         * List of the audio capture devices found by JMF
         */
        Vector audioDevices = null;
    
        public JMFRunner()
        {
            if(OS.isWindows())
            {
                dlls = windowsDllList;
                dir = windowsDllFolder;
            }
            else if(OS.isLinux())
            {
                dlls = linuxDllList;
                dir = linuxDllFolder;
            }
            else
            {
                Window.getLogger().severe("Operating system does not support JMF");
            }
    
        }
    
        /**
         * Adds new capture devices
         */
        public void detectCaptureDecives()
        {
    
    
            Thread theTread = new Thread(theBar);
            theTread.start();
            theBar.repaint();
    
            JMFInit.main(new String[] {""});
            JMFPropertiesGen.main(new String[] {""});
            Registry.main(new String[] {""});
            RegistryGen.main(new String[] {"-d",
                new File(".").getAbsolutePath(),
                "registrylib"
            });
    
            theBar.setMessage("");
            theBar.stop();
        }
    
        /**
         * Verifies that all the dll's that JMF needs are in their correct spot
         * @return True if all dlls are in their correct spot, false otherwise
         */
        public boolean detectDlls()
        {
            boolean retVal = true;
            String currFile;
            for(String currDll : dlls)
            {
                currFile = dir + currDll;
                if(! new File(currFile).exists())
                {
                    Window.getLogger().severe("Can not find dll " + currFile + " for JMF");
                    retVal = false;
                }
            }
            return retVal;
        }
    
        //Doesnt work quite yet
        public boolean installLibraryFiles()
        {
            boolean retVal = true;
            String currFile;
            for(String currDll : dlls)
            {
                currFile = dir + currDll;
                File newDll = new File(currFile);
                //see if this dll is already there
                if(!newDll.exists())
                {
                    //its not there so lets copy it
                    try
                    {
                        FileUtilities.copy(newDll,FileUtilities.getResourceFile("/JMFManager/Resources/"+currDll,currDll));
                    }
                    catch(Exception e)
                    {
                        retVal =  false;
                    }
                }
            }
            return retVal;
        }
    
        /**
         * Returns the location of the jmf.properties file that STix is using
         * @return THe locaiton of the JMF properties
         */
        public String getJMFPropertiesFileLocation()
        {
            return Registry.getJMFPropertiesFileLocation();
        }
    
        /**
         * Returns a list of the audio devices found by JMF
         * @return Returns an Arraylist containing info about the audio capture devices
         */
        public ArrayList getAudioDevices()
        {
            DeviceFinder df = new DeviceFinder();
            audioDevices = df.getSoundCaptureDevices();
            return new ArrayList(audioDevices);
        }
    
        /**
         * Returns a list of the video decives deteced by JMF
         * @return returns an arraylist with info of the video capture devices
         */
        public ArrayList getVideoDevices()
        {
            DeviceFinder df = new DeviceFinder();
            videoDevices = df.getVideoCaptureDevices();
            return new ArrayList(videoDevices);
        }
    
    
        public static void main(String [] args)
        {
            JMFRunner x = new JMFRunner();
            //x.detectCaptureDecives();
            x.installLibraryFiles();
            System.out.println(x.detectDlls());
            System.out.println(x.getJMFPropertiesFileLocation());
            System.out.println(x.getAudioDevices());
            System.out.println(x.getVideoDevices());
        }
    }
    
    

    DeviceFinder.java软件

    
    import java.util.Vector;
    import javax.media.*;
    import javax.media.format.*;
    
    /**
     * this class gets information about capture devices (mics and cameras)
     */
    public class DeviceFinder {
    
        Vector videoDevices = new Vector();
        Vector audioDevices = new Vector();
    
       /**
       * Constructor
       * Creates a new DeviceFinder
       */
       public DeviceFinder()
       {
          /*retrieve ALL video and audio devices*/
          videoDevices = CaptureDeviceManager.getDeviceList(new VideoFormat(null));
          audioDevices = CaptureDeviceManager.getDeviceList(new AudioFormat(null));
       }
    
       /**
       * purpose:  Get information on all Video capture devices on the system
       * @return java.util.Vector 
    a vector of attributes */ public Vector getVideoCaptureDevices() { return videoDevices; } /** * purpose: Get information on all audio capture devices on the system * @return java.util.Vector
    a vector of attributes */ public Vector getSoundCaptureDevices() { return audioDevices; } /** * retrieve the first video capture device */ public CaptureDeviceInfo getPrimaryVideoCaptureDevice() { return (CaptureDeviceInfo)videoDevices.get(0); } /*retrieve the first audio capture device*/ public CaptureDeviceInfo getPrimaryAudioCaptureDevice() { return (CaptureDeviceInfo)audioDevices.get(0); } /** * get the first video device name * @return String
    the name of the video device */ public String getVideoCaptureDeviceName() { return ((CaptureDeviceInfo)videoDevices.get(0)).getName(); } /** * get the first audio device name * @return String
    the name of the audio device */ public String getAudioCaptureDeviceName() { return ((CaptureDeviceInfo)audioDevices.get(0)).getName(); } /** * get the first video device media locator * @return MediaLocator */ public MediaLocator getVideoMediaLocator() { return ((CaptureDeviceInfo)videoDevices.get(0)).getLocator(); } /** * get the first audio device media locator * @return MediaLocator */ public MediaLocator getAudioMediaLocator() { return ((CaptureDeviceInfo)audioDevices.get(0)).getLocator(); } /** * get the video device media locator at index idx * @param idx index of the media locator (0 is the first/default, * as ordered by *
    the JMFRegistry) * @return MediaLocator */ public MediaLocator getVideoMediaLocator(int idx) { if(idx >= videoDevices.size()) { return null; } return ((CaptureDeviceInfo)videoDevices.get(idx)).getLocator(); } /** * get the audio device media locator at index idx * @param idx index of the audio device (as ordered by the JMFRegistry) * @return MediaLocator */ public MediaLocator getAudioMediaLocator(int idx) { return ((CaptureDeviceInfo)audioDevices.get(idx)).getLocator(); } /** * * @param args */ public static void main(String[] args) { DeviceFinder df = new DeviceFinder(); //DEBUG: System.out.println(df.getVideoMediaLocator()); System.out.println(df.getAudioMediaLocator()); } }
    1 回复  |  直到 5 年前
        1
  •  4
  •   Berin Loritsch    14 年前

    我想没有更好的办法了。除非dll是按路径名显式加载的,否则您只需要确保它们位于系统路径中,因此如果它们位于JVM可执行文件旁边,那么它也应该可以工作。Windows确实隐式地在系统路径中包含程序启动的目录,因此这是另一个可能的位置。

    一般来说,Java的一个优点是不需要安装它就可以工作。实际上,一旦在一个系统上执行了JRE的安装,就可以将其打包并作为zip文件在另一个系统上使用。Java不需要显式地注册dll,因为它根据需要动态地加载它们。