Output a Java window as a webcam stream

故事扮演 提交于 2021-02-10 03:59:57

问题


I would like to write a program perferably in Java that can display animated overlays on a screen.

The screen will then be broadcast streamed over the internet using a separate program called x-split.

A good way to do this would be to create a transparent window in java which will display animated files (with transparancy) and the output of this window (Its display) should ideally appear in the webcam device list so it can be easily picked up by x-split which will allow it to be arranged ontop of the game screen I'm currently broadcasting.

An example program of this type would be one where a webcam image is displayed and "virtual glasses" overlayed over the image of a persons face which could then be transmitted as an output cam.

I have found the java 6u10-translucent-shapes library to create the transparent window but I don't know how to stream it.

I've read a few things to suggest that JMF and FFMpeg might be the way to go, but I'm not sure what to install and how.

Any help or pointers to tutorials would be greatly appreciated.


回答1:


I don't know exactly what you are trying to achieve, but what about an external program which streams your screen? Something like http://screen-stream.en.softonic.com ?




回答2:


Use java.awt's Robot class. It has a getScreenCapture(Rectangle) method which can be used to get BufferedImages of a portion of the screen. These BufferedImages can be edited with code, then can made to be flashed by having a full screen application display itself (and disappear to recapture the new Image.). Alternatively, you could filter it by using a transparent java full screen application using the above method, and displaying it on your applet to be "x-treamed".

However, my biggest question is how do you expect to control your game anyway? Also, why are you expected to something this big for something that can be easily solved.

It would be simpler and way more synchronized if you just used a screen recording software to turn it into a movie, then use Windows Movie Maker to modify it to your needs. You do not need to waste your time on code. =)

I hope this helped.




回答3:


You could make an undecorated JFrame and the AWTUtilities class (I think that was what you found in Java6u10 for Window transparency) and do all your animation there. Use java.awt.Robot.getScreenCapture(Rectangle) to capture an image every x milliseconds. Use javax.swing.Timer to do the timing:

Timer timer = new Timer(x, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        arrayOfImages[imageCount] = java.awt.Robot.getScreenCapture(r);
        count++;
    }
});

I found a Java wrapper - Jffmpeg - to use (http://jffmpeg.sourceforge.net/download.html). You'll need JMF - http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html - and some other stuff written in the Jffmpeg Documentation page. FMJ (http://fmj-sf.net/ffmpeg-java/getting_started.php) is another option.

FFmpeg needs to be downloaded with Git

Finally, this thread from another forum (http://www.blackhatworld.com/blackhat-seo/youtube/330165-command-line-program-convert-image-video.html) somewhat shows you how to convert saved images to video. You may want to skip the Jffmeg step altogther. Instead you could save all the images to file, and the convert it to video using Runtime.getRuntime().exec(String) to execute the command line. But if you do this you won't be able to make your program platform-independent

Videos in Java are a bit tedious and annoying, so you may want to switch to another language, with easier libraries and API's, altogether.



来源:https://stackoverflow.com/questions/10939429/output-a-java-window-as-a-webcam-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!