简体   繁体   English

正确使用VLCj

[英]Correct using VLCj

I try to use VLCj to get access to web-cameras. 我尝试使用VLCj来访问网络摄像机。 I am using this code: 我正在使用此代码:

public static void main(String[] args) {
    // Create player.
    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
    DirectMediaPlayer mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(
            320, 240, 
            new RenderCallback() {
                @Override
                public void display(Memory arg0) {
                    // Do nothing.
                }
         });

    // Options setup.
    String[] options = new String[]{};
    String mrl = "v4l2:///dev/video0"; // Linux

    // Start preocessing.
    mediaPlayer.startMedia(mrl, options);

    BufferedImage bufImg;
    for (int i = 0; i < 1000; ++i) {
        bufImg = mediaPlayer.getSnapshot();

        // Do something with BufferedImage...
        // ...
    }

    // Stop precessing.
    mediaPlayer.stop();
    mediaPlayer = null;

    System.out.println("Finish!");
}

And this code partially works -- I can get and work with BufferedImage , but: 这段代码部分起作用 -我可以使用BufferedImage并与之一起工作,但是:

  • I got an error in to output : [0x7f0a4c001268] main vout display error: Failed to set on top 输出错误[0x7f0a4c001268] main vout display error: Failed to set on top 输出 [0x7f0a4c001268] main vout display error: Failed to set on top
  • When main loop is finished and camera was disabled program don't finished ! 当主循环完成并且相机被禁用时, 程序就不会完成 I see Finish! 我看到Finish! message, but program not return control into IDE or console. 消息,但程序无法将控制权返回到IDE或控制台。

UPD: I am using openSUSE 12.2 x64, VLC 2.0.3 installed and working properly for all video files, library VLCj 2.1.0. UPD:我使用的是openSUSE 12.2 x64,已安装VLC 2.0.3,并且对于所有视频文件(库VLCj 2.1.0)正常工作。

This code working properly: 此代码正常工作:

public static void main(String[] args) {
    // Configure player factory.
    String[] VLC_ARGS = {
            "--intf", "dummy",          // no interface
            "--vout", "dummy",          // we don't want video (output)
            "--no-audio",               // we don't want audio (decoding)
            "--no-video-title-show",    // nor the filename displayed
            "--no-stats",               // no stats
            "--no-sub-autodetect-file", // we don't want subtitles
            "--no-inhibit",             // we don't want interfaces
            "--no-disable-screensaver", // we don't want interfaces
            "--no-snapshot-preview",    // no blending in dummy vout
    };
    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(VLC_ARGS);

    // Create player.
    HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();

    // Select input device.
    String mrl = "v4l2:///dev/video0";  // Linux

    // Start processing.
    mediaPlayer.startMedia(mrl);

    BufferedImage bufImg;
    for (int i = 0; i < 1000; ++i) {
        bufImg = mediaPlayer.getSnapshot();

        // Do something with BufferedImage...
        // ...
    }

    // Stop processing.
    mediaPlayer.stop();

    // Finish program.
    mediaPlayer.release();
    mediaPlayerFactory.release();
}

Re your native window: VLCj opens a shared instance to the VLC library. 重新显示本机窗口:VLCj将共享实例打开到VLC库。

A headless media palyer is NOT intended to have a video or audio output! 无头媒体播放器不打算具有视频或音频输出!

In fact, if you need anything to play (and not to stream to anywhere else) you need to create either an output window or use a direct media player (may be much more complicated) So, if a headless player needs to play something it opens a native window to perform the playback! 实际上,如果您需要播放任何内容(而不是流向其他任何地方),则需要创建输出窗口或使用直接媒体播放器 (可能会更加复杂),因此,如果无头播放器需要播放某些内容,打开一个本机窗口以执行播放!

Source: http://www.capricasoftware.co.uk/wiki/index.php?title=Vlcj_Media_Players 资料来源: http : //www.capricasoftware.co.uk/wiki/index.php? title= Vlcj_Media_Players

Re the error: the video display component MUST be the top component of the panel, window or whereever it is added to. 重新出现错误: 视频显示组件必须是面板,窗口或其添加到的任何地方的顶部组件 Otherwise it will throw the error 否则会抛出错误

main vout display error: Failed to set on top 主vout显示错误:无法设置在最前面

Furthermore, if you put anything over the component it will destroy the video output which won't work anymore! 此外,如果在组件上放任何东西,它将破坏视频输出 ,将不再起作用!

Anyway, I don't know how the DirectMediaPlayer works in detail but VLCj has some weird behaviour... Maybe getSnapshot() needs a video display component but I'm not sure. 无论如何,我不知道DirectMediaPlayer的详细工作原理,但是VLCj有一些奇怪的行为...也许getSnapshot()需要一个视频显示组件,但是我不确定。

Re your not finishing program: you join to finish your own thread. 关于您尚未完成的程序:您加入以完成自己的线程。 This can't work because your thread "sleeps" until the other thread who is waited for has been terminated but as this is your own thread it "sleeps" and won't terminate. 是行不通的,因为您的线程“休眠”直到另一个正在等待的线程终止,但是由于这是您自己的线程,因此它“休眠”并且不会终止。 You can test this behaviour with this short code in a main method: 您可以使用以下简短代码在main方法中测试此行为:

System.out.println("Test start");
Thread.currentThread().join();
System.out.println("Test stop");

You will NEVER reach the "Test stop" statement. 您将永远不会到达“测试停止”语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM