I'd like to use this library for my remote desktop software but it does not seem to be working.
Here is my test class:
public class FFMPEG {
public static void main(String[] args) throws Exception {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("video=\"screen-capture-recorder\"");
grabber.setFormat("dshow");
grabber.setImageWidth(2560);
grabber.setImageHeight(1440);
grabber.start();
CanvasFrame frame = new CanvasFrame("Screen Capture");
while (frame.isVisible()) {
frame.showImage(grabber.grab());
}
frame.dispose();
grabber.stop();
}
}
and here is what I have in my gradle.build
repositories {
mavenCentral()
}
configurations {
all*.exclude group: 'org.bytedeco', module: 'javacpp-presets'
}
dependencies {
compile "org.bytedeco:javacv:1.2"
compile "org.bytedeco:javacpp:1.2.4"
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.1.2-1.2'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.1.2-1.2', classifier: 'windows-x86_64'
}
Here is the error I get when running that class:
Exception in thread "main" org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -5: Could not open input "video="screen-capture-recorder"". (Has setFormat() been called?)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:437)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:385)
at FFMPEG.main(FFMPEG.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
[dshow @ 000000000179c5e0] Could not enumerate video devices (or none found).
[dshow @ 000000000179c5e0] Could not enumerate video devices (or none found)
Does it work with the ffmpeg command line tool?
@saudet it works fine from the command line (ffmpeg -f dshow -i video="screen-capture-recorder" output.flv)
Thanks!!
So, could you try to do the same in Java and not set the height or the width?
@saudet still the same error when removing them
Might want to try gdigrab then: https://ffmpeg.org/ffmpeg-devices.html#gdigrab
gdigrab is working. Thanks!
gdigrab format is not working either. It does not accept any arguments:
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("-framerate ntsc -offset_x 10 -offset_y 20 -video_size 640x480 -show_region 1 -i desktop");
grabber.setFormat("gdigrab");
grabber.start();
Exception in thread "main" org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -5: Could not open input "-framerate ntsc -offset_x 10 -offset_y 20 -video_size 640x480 -show_region 1 -i desktop". (Has setFormat() been called?)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:437)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:385)
at FFMPEG.main(FFMPEG.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
[gdigrab @ 0000000000fdc660] Please use "desktop" or "title=<windowname>" to specify your target.
[gdigrab @ 0000000000fdc600] Please use "desktop" or "title=<windowname>" to specify your target.
Try to use setOption() instead
Hi Jonatino,
Hope you are doing good.
I come across below error when i am trying to access OEM device (EasyCap) to grab frame form Set top box
Code:
FFmpegFrameGrabber grabber =new FFmpegFrameGrabber("video=\"OEM Device\":audio=\"OEM Device\"");
grabber.setFormat("dshow");
grabber.setImageWidth(640);
grabber.setImageHeight(480);
grabber.start();
CanvasFrame frame = new CanvasFrame("Screen Capture");
while (frame.isVisible()) {
frame.showImage(grabber.grab());
}
frame.dispose();
grabber.stop();
Error:
Exception in thread "main" org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -5: Could not open input "video="OEM Device":audio="OEM Device"". (Has setFormat() been called?)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:429)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:377)
at stbTesting.FFmpegEasyCap.main(FFmpegEasyCap.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
[dshow @ 000000000050c760] Could not find video device with name ["OEM Device"] among source devices of type video.
[dshow @ 000000000050c760] Could not find video device with name ["OEM Device"] among source devices of type video.
Please help me out to resolve the above issue
From command line using ffmpeg i am able to play as well as record the Set top box video using easycap
For Direct Play:
ffplay -f dshow -crossbar_video_input_pin_number 1 -crossbar_audio_input_pin_number 2 -rtbufsize 500000k -framerate 29.97 -i video="OEM Device":audio="OEM Device"
For Recording:
ffmpeg -f dshow -crossbar_video_input_pin_number 1 -crossbar_audio_input_pin_number 2 -rtbufsize 500000k -framerate 29.97 -i video="OEM Device":audio="OEM Device" C:stbtestVideoTest.avi
@Nitinvermaa1 You might want to try to set the options with setOption(), setAudioOption() and setVideoOption().