Apparently ffmpeg supports screen capture on Windows according to this:
https://trac.ffmpeg.org/wiki/Capture/Desktop
Attempting to do so using:
FrameGrabber grabber = new FFmpegFrameGrabber("screen-capture-recorder");// As well as FFmpegFrameGrabber("UScreenCapture");
grabber.setFormat("dshow");
grabber.setFrameRate(30);
grabber.start();
Results in:
run:
Exception in thread "main" org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -5: Could not open input "screen-capture-recorder". (Has setFormat() been called?)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:368)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:318)
at testarea.JavaCVDemo.main(JavaCVDemo.java:40)
[dshow @ 154dc160] Malformed dshow input string.
[dshow @ 154dc160] Malformed dshow input string.
Java Result: 1
BUILD SUCCESSFUL (total time: 9 seconds)
This may possibly have something to do with(maybe???): https://trac.ffmpeg.org/wiki/DirectShow#Specifyinginputframerate
This is here as a resource in case other people experience this error and wish to look into it, as well as a reminder to myself to do so in the future.
If you find any solutions or fixes, please let me know.
correct string is new FFmpegFrameGrabber("video=screen-capture-recorder")
@paksv Does it actually work on your machine? That's good to know!
Ya,it does work pretty well. However, almost no configuration possible.
I have the same issue... "video=screen-capture-recorder" returns the same error. how do you configure grabber?
@paksv What do you get when run ffmpeg -list_devices true -f dshow -i dummy?
I get
`[dshow @ 00000000002fe000] DirectShow video devices
[dshow @ 00000000002fe000] Could not enumerate video devices.
[dshow @ 00000000002fe000] DirectShow audio devices
[dshow @ 00000000002fe000] "Microphone (High Definition Aud"
dummy: Immediate exit requested
`
I guess "Could not enumerate video devices." is why it's not working.. Bu I have no idea how to solve this..
BTW, would one of you be willing to write a nice wiki page here https://github.com/bytedeco/javacv/wiki to explain how to do screen capture under Windows? Everyone should have write access, so let me know! It would make a great addition, thanks.
Sorry for missing the thread. Here's the output: https://gist.github.com/paksv/58ff6022ae72dd2cb8b3
Here's the test java code that works for me: https://gist.github.com/paksv/877c7e87779ed289778d
@paksv Could you put this up on the wiki? Everyone has write access, thank you!
three years later he returns.
It seems you guys figured it out. Glad I could point it out. If I have the time in the next few days I'll try and put your findings up on the wiki.
screen recorder works for windows provided you have your desktop input registered as screen recorder. I was facing similar issues. If you run this on ffmpeg CLI. You will get list of input devices. If you see any device listed as screen recorder you can use dshow. Dshow can be used for any input provided the input specified in the call is registered.
https://ffmpeg.org/ffmpeg-devices.html#dshow
ffmpeg -list_devices true -f dshow -i dummy
For windows GdiGrab should be preferred.
https://ffmpeg.org/ffmpeg-devices.html#gdigrab
just use below code it will work for sure.
FrameGrabber grabber = new FFmpegFrameGrabber("desktop");
grabber.setFormat("gdigrab");
grabber.setFrameRate(30);
grabber.start();
@madie89 Great, thanks for the info! Would you also be able to put this up on the wiki?
https://github.com/bytedeco/javacv/wiki
Everyone has write access...
@madie89 Thanks so much! Unfortunately capturing the desktop is very slow, even with a small width/height. Is there any way to improve?
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("desktop");
grabber.setFormat("gdigrab");
grabber.setFrameRate(60);
grabber.setImageWidth(800);
grabber.setImageHeight(600);
grabber.start();
while (!Thread.interrupted()) {
long start = System.currentTimeMillis();
grabber.grabImage();
long elapsed = System.currentTimeMillis() - start;
System.out.println("Took " + elapsed + "ms");
}
I get around an average of 35ms on an i7 6700K @ 4.5GHz with 32GB RAM :disappointed:, looking to try to get it down to around 5ms or less!
@saudet Edited my question, but thanks!
Windows probably doesn't support that, but ask some Windows forum about that somewhere.
@saudet How do I configure options for an FFmpegFrameGrabber? I'd like to use the options as shown here: https://ffmpeg.org/ffmpeg-devices.html#Options-7
@Jire That would be FFmpegFrameGrabber.setOption().
How to use javacv to ScreenCapture on Mac OS? Thanks!
@jliu666 it looks like you should be using the 'avfoundation' format as stated here.
Although whether or not javacv supports it is beyond my paygrade.
This should probably be explained in the wiki page as well, as an addendum to the explanations I just filled out.
Most helpful comment
screen recorder works for windows provided you have your desktop input registered as screen recorder. I was facing similar issues. If you run this on ffmpeg CLI. You will get list of input devices. If you see any device listed as screen recorder you can use dshow. Dshow can be used for any input provided the input specified in the call is registered.
https://ffmpeg.org/ffmpeg-devices.html#dshow
For windows GdiGrab should be preferred.
https://ffmpeg.org/ffmpeg-devices.html#gdigrab
just use below code it will work for sure.