简体   繁体   English

记录并显示视频JMF

[英]Record and show video JMF

I want record a video from a web camera and see what I am recording on the screen. 我想从网络摄像机录制视频,然后在屏幕上查看我正在录制的内容。 Individually, I can either see it on the screen that takes web camera, or record a video, but not both. 单独地,我可以在带有网络摄像头的屏幕上看到它,也可以录制视频,但不能两者兼有。 When I am recording, the jpanel is not updated. 录制时,jpanel不会更新。 It reports no errors at all. 它根本没有报告任何错误。 How do I fix this? 我该如何解决? Thank you very much. 非常感谢你。 Sorry for my English. 对不起我的英语不好。

public class NewJFrame extends javax.swing.JFrame implements ActionListener {

    private static boolean debugDeviceList = false;
    private static String defaultVideoDeviceName = "Microsoft WDM Image Capture";
    private static String defaultAudioDeviceName = "DirectSoundCapture";
    private static String defaultVideoFormatString = "size=640x480, encoding=yuv, maxdatalength=614400";
    private static String defaultAudioFormatString = "linear, 48000.0 hz, 16-bit, stereo, signed";
    private Timer timer = new Timer(40, this);
    private Player player;

    public NewJFrame(){
        initComponents();


        MediaLocator videoMediaLocator = new MediaLocator("vfw://0");
        DataSource myDataSource = Manager.createDataSource(videoMediaLocator);

        player = Manager.createPlayer(myDataSource);
        player.start();                                    

        DataSource videoDataSource = myDataSource;
        MediaLocator audioMediaLocator = new MediaLocator("dsound://");
        DataSource audioDataSource = null;

        audioDataSource = Manager.createDataSource(audioMediaLocator);

        DataSource dArray[] = new DataSource[2];
        dArray[0] = videoDataSource;
        dArray[1] = audioDataSource;
        DataSource mixedDataSource = null;

        mixedDataSource = Manager.createMergingDataSource(dArray);


        FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.MSVIDEO);

        Format outputFormat[] = new Format[2];
        outputFormat[0] = new VideoFormat(VideoFormat.INDEO50);
        outputFormat[1] = new AudioFormat(AudioFormat.GSM_MS);

        processorModel = new ProcessorModel(mixedDataSource, outputFormat, outputType);

        processor = Manager.createRealizedProcessor(processorModel);

        source = processor.getDataOutput();

        dest = new MediaLocator("file:.\\testcam.avi");

        dataSink = null;
        dataSinkListener = null;
        dataSink = Manager.createDataSink(source, dest);
        dataSinkListener = new MyDataSinkListener();
        dataSink.addDataSinkListener(dataSinkListener);
        dataSink.open();
    }                     

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        timer.start();
        dataSink.start();
        processor.start();
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        timer.stop();
        processor.stop();
        processor.close();

        dataSinkListener.waitEndOfStream(10);
        dataSink.close();

        Stdout.log("[all done]");
    }                                        

    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                    new NewJFrame().setVisible(true);
            }
        });
    }


    public BufferedImage grabFrameImage() {
        Image image = null;
        FrameGrabbingControl fGrabbingControl = null;
        if (player != null) {
            fGrabbingControl = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
        }
        javax.media.Buffer buffer = fGrabbingControl.grabFrame();
        if (buffer != null) {
            image = new BufferToImage((VideoFormat) buffer.getFormat()).createImage(buffer);
        }
        if (image != null) {
            return (BufferedImage) image;
        }
        return null;
    }
}

Try using the jmapps jmstudio source code, good code for that in there. 尝试使用jmapps jmstudio源代码,那里的代码很好。 It's about the data sink and the filetype descriptor. 它与数据接收器和文件类型描述符有关。

Concept: record from source via capture device, you need a data sink there and then load the system, store to a file and load a player from the file. 概念:通过捕获设备从源进行记录,您需要在那里存在一个数据接收器,然后加载系统,存储到文件并从该文件加载播放器。

If you don't read from the file in the Player it doesn't work in JMF. 如果您没有从Player中读取文件,则它在JMF中不起作用。 Been online for 14.5 years and no problems with JMF live video. 上线已有14.5年,并且JMF实时视频没有问题。

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

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