Re: [OpenCV] Is it somehow possible to take a screenshot with OpenCV?

1,426 views
Skip to first unread message

Samuel Audet

unread,
May 31, 2010, 9:39:44 AM5/31/10
to jav...@googlegroups.com, Lyubov Kolosovska
Hello,

On 2010-05-31 20:04, Lyubov Kolosovska wrote:
> thank you for your answer! I've checked the ffmpeg wrapper, but haven't
> found any example of how to actually wrap the ffmpeg command to Java
> code. Do you have some examples?

Actually, I never tested the x11grab device, and JavaCV was missing a
few things to enable screen capture. The modifications were pretty minor
and I was able to make them in half an hour. Please download and let me
know if you have any trouble with these test packages:
http://www.ok.ctrl.titech.ac.jp/~saudet/javacv.jar
http://www.ok.ctrl.titech.ac.jp/~saudet/ffmpeg-java.jar

Once installed, you should be able to do what you want with a program
like the following. (It displays back on the screen the captured images,
so you will get a double-mirror-like effect there... pretty neat :)


import name.audet.samuel.javacv.*;
public class ScreenCastingTest {
public static void main(String[] args) throws Exception {
CanvasFrame frame = new CanvasFrame("ScreenCastingTest", 1.0);
FrameGrabber grabber = new FFmpegFrameGrabber(":0.0", "x11grab");
grabber.setImageWidth(1024);
grabber.setImageHeight(768);
grabber.setFrameRate(10);
grabber.start();

while (frame.isVisible()) {
frame.showImage(grabber.grab());
}
grabber.stop();
frame.dispose();
}
}


Samuel

lyuba

unread,
Jun 2, 2010, 7:02:45 AM6/2/10
to javacv
Samuel,

I am sorry for the late response - had the problems with Internet
connection. Many thanks that you help me in solving this compelling
task :)

However, I might doing something wrong, because get the mistake:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error
looking up function 'avcodec_decode_video2': /usr/lib/i686/cmov/
libavcodec.so: undefined symbol: avcodec_decode_video2
at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:345)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:325)
at com.sun.jna.Native.register(Native.java:1319)
at com.sun.jna.Native.register(Native.java:1014)
at net.sf.ffmpeg_java.AVCodecLibrary.<clinit>(AVCodecLibrary.java:24)
at
name.audet.samuel.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:
76)
at main.ScreenCast.main(ScreenCast.java:15)

What do you think about it?

Many thanks!

Samuel Audet

unread,
Jun 2, 2010, 7:11:57 AM6/2/10
to jav...@googlegroups.com
You need to install FFmpeg 0.5 or more recent. Ubuntu does not come with
a package of FFmpeg 0.5 or more recent. You need to compile it from
source... :(

Samuel

lyuba

unread,
Jun 2, 2010, 3:09:59 PM6/2/10
to javacv
Samuel,

I've actually done it before posting the question.
I followed this guide step by step: http://ubuntuforums.org/showthread.php?t=786095

So, I checkouted ffmpeg from svn today.

What may be also a reason, how do you think?

Thank you very much for your help!

lyuba

unread,
Jun 5, 2010, 2:11:02 PM6/5/10
to javacv
Samuel,

I've just recompiled ffmpeg, but the problem is still here.
By the way, JavaCV is now working fine with ffmpeg.

How do you think where is the mistake with this /usr/lib/i686/cmov/
libavcodec.so?
Is it ffmpeg problem so I should ask them through their mailing list?
Or that is some problem with the wrapper?
Or probably I have to specially configure ffmpeg when installing?

Waiting for a tip from you, thanks!

Thank you for your answer in advance.

Samuel Audet

unread,
Jun 5, 2010, 8:56:38 PM6/5/10
to jav...@googlegroups.com
On 2010-06-06 03:11, lyuba wrote:
> Samuel,
>
> I've just recompiled ffmpeg, but the problem is still here.
> By the way, JavaCV is now working fine with ffmpeg.
>
> How do you think where is the mistake with this /usr/lib/i686/cmov/
> libavcodec.so?
> Is it ffmpeg problem so I should ask them through their mailing list?
> Or that is some problem with the wrapper?
> Or probably I have to specially configure ffmpeg when installing?

I don't know, I do not use Ubuntu. This guy seems to have a solution though:
http://linux-tipps.blogspot.com/2009/05/pretending-package-is-installed-by.html

But if this does not work, then please ask other people who use Ubuntu
how to get ffmpeg working properly. I do not know, since I do not use
Ubuntu. I hope this is clear.

Samuel

lyuba

unread,
Jun 6, 2010, 3:08:42 AM6/6/10
to javacv
Okay, I'll try to figure out. Will post the solution here if find it.

Thank you for the tip :)

On Jun 6, 3:56 am, Samuel Audet <samuel.au...@gmail.com> wrote:
> On 2010-06-06 03:11, lyuba wrote:
>
> > Samuel,
>
> > I've just recompiled ffmpeg, but the problem is still here.
> > By the way, JavaCV is now working fine with ffmpeg.
>
> > How do you think where is the mistake with this  /usr/lib/i686/cmov/
> > libavcodec.so?
> > Is it ffmpeg problem so I should ask them through their mailing list?
> > Or that is some problem with the wrapper?
> > Or probably I have to specially configure ffmpeg when installing?
>
> I don't know, I do not use Ubuntu. This guy seems to have a solution though:http://linux-tipps.blogspot.com/2009/05/pretending-package-is-install...

lyuba

unread,
Jun 7, 2010, 3:30:15 AM6/7/10
to javacv
Nobody has given me any tip so far, so right now I'm running
screencasting as the separate process like this:
Process p = Runtime.getRuntime().exec("ffmpeg -f x11grab -s cif -r 30 -
s 1366x768 -i :0.0 /tmp/screenshot.mpg");

And I process the images from this video afterwards.

Not very good, but it's all that works for now. Probably will help
anybody.

Samuel Audet

unread,
Jun 8, 2010, 8:32:02 AM6/8/10
to jav...@googlegroups.com
I thought of a simple modification to FFmpeg-Java that could make it
work in the case when FFmpeg is installed from SVN in the standard way
(i.e.: "./configure --enable-shared; make; make install"), even when
other broken versions (like the one from Ubuntu) remain on the system...
You may try these new test packages to see if it works:
http://www.ok.ctrl.titech.ac.jp/~saudet/javacv.jar
http://www.ok.ctrl.titech.ac.jp/~saudet/ffmpeg-java.jar

Samuel

Samuel Audet

unread,
Jun 8, 2010, 9:52:50 AM6/8/10
to jav...@googlegroups.com
Oops, that would be "./configure --enable-shared --enable-x11grab
--enable-gpl", otherwise x11grab won't work... And after that, you also
need to see x11_grab_device in the list of "Enabled indevs" at the end
of the output.

Samuel

Samuel Audet

unread,
Jun 10, 2010, 12:50:05 AM6/10/10
to jav...@googlegroups.com
Hello,

Just to say that I have updated, tested, and confirmed that, with FFmpeg
plus x11grab installed from SVN that way, these test packages work:
http://www.ok.ctrl.titech.ac.jp/~saudet/javacv.jar
http://www.ok.ctrl.titech.ac.jp/~saudet/ffmpeg-java.jar

Happy x11grabbing...

Samuel

Reply all
Reply to author
Forward
0 new messages