【问题标题】:How to capture video using JMF, but without installing JMF如何使用 JMF 捕获视频,但无需安装 JMF
【发布时间】:2010-10-28 19:48:10
【问题描述】:

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

我认为分享我们对这个问题的解决方案可能是值得的。有用。它运作良好。我的问题是:有人有更好的方法吗?

环境:Windows、XP及以上

  1. 下载适用于 Windows 的 JMF
  2. 在你的机器上安装它

  3. jmf安装后在system32文件夹中找到如下dlls:

    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

  4. dlls 复制到临时文件夹中

  5. 找到jmf.properties 文件(在您的计算机上搜索)
  6. 下载 JMF 源代码
    在源代码中,找到以下文件:

JMFinit.java
JMRPropertiesGen.java
Registry.java
RegistryGen.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.properties 文件需要与具有 main 方法的类位于同一文件夹中,或者与包含 main 方法的 JAR 存档位于同一文件夹中。
dlls 需要进入 win32 文件夹。您可以让您的程序检查它们是否在win32 文件夹中。如果不是,您可以让它从某个位置复制它们。只要上面列出的Main 类运行,jmf.properties 文件就会更新。您只需要运行一次,第一次运行程序,或者如果用户想添加新的捕获设备。最后,只需确保 Windows JMF 下载附带的 jmf.jar 文件和 jmfcom.jar 包含在类路径中。你现在可以走了。无需实际安装即可使用 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()); } }

【问题讨论】:

  • 在此示例/示例代码和一些步骤上分享更多信息会是一个更好的主意,我也在尝试类似的方法。并且正在考虑转向 JMF 或本地访问?
  • @Stackfan 如果对任何人有帮助,我已经添加了一些代码
  • @user489041 你说“dll需要进入win32文件夹”你的意思是system32
  • @MikeNereson 是的,对不起。我的意思是 system32 文件夹。我真的需要更新这篇文章。我已经大大简化了这个过程。
  • @user489041 更新它!那简直太好了。我跟着做,但在提取 DLL 后链接到 DLL 时出现错误。我在运行它的计算机上得到这个。你有什么见解吗? pastie.org/private/ug8gdu8ohj3fxpasgumpw -- 我可以搁置这个项目,但 8 周后我又回来了。

标签: java distribution jmf java-native-library


【解决方案1】:

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

安装程序是一把双刃剑,他们可以轻松地添加新功能并在以后将其删除,但也使得部署使用该产品的解决方案变得更加困难。

一般来说,Java 的优点之一是您无需安装它即可工作。本质上,一旦您在一个系统上安装了 JRE,您就可以将它捆绑起来并作为 zip 文件在另一个系统上使用。 Java 不需要显式注册 DLL,因为它会根据需要动态加载它们。

【讨论】:

  • 这都是真的。另一方面,JMF 确实需要安装。这正是您所说的原因,"One of the nice things about Java in general is that you don't have to install it for it to work." 我们不希望最终用户必须安装其他任何东西才能使我们的应用程序正常工作。如果应用程序作为小程序运行,这也是非常正确的。我们希望能够在幕后复制文件并使一切正常。模拟 JMF 的安装并不容易。有很多属性是在幕后设置的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多