Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can javacv open the camera in Android? #1692

Closed
liming1010 opened this issue Sep 14, 2021 · 22 comments
Closed

How can javacv open the camera in Android? #1692

liming1010 opened this issue Sep 14, 2021 · 22 comments

Comments

@liming1010
Copy link

liming1010 commented Sep 14, 2021

hello, I'm an Android Developer, I'm going to use javacv for live broadcast processing, How can javacv open the camera in Android?
In opencv for Android, it is implements camerabridgeviewbase.cvcameraviewlistener2

@saudet
Copy link
Member

saudet commented Sep 15, 2021

There are currently no "AndroidFrameGrabber", but we can already capture video from Java in that case, for example:
https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java

@saudet
Copy link
Member

saudet commented Nov 25, 2021

It looks like FFmpeg supports the Android Camera API now:
https://www.ffmpeg.org/ffmpeg-devices.html#android_005fcamera

So this kind of code should work:

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("");
grabber.setFormat("android_camera");
grabber.start();

Please let me know if that doesn't work though! Thanks

@kshitijgarg2609
Copy link

@saudet It is giving the exception, Here is the screenshot

image

@saudet
Copy link
Member

saudet commented Nov 25, 2021

What is the content of the exception? And what does FFmpeg prints out to the log?

@kshitijgarg2609
Copy link

I/System.out: org.bytedeco.javacv.FFmpegFrameGrabber$Exception: av_find_input_format() error: Could not find input format "android_camera". (For more details, make sure FFmpegLogCallback.set() has been called.)
I/System.out: at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:880)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:846)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:841)
at com.example.javacv8test.MainActivity$1.run(MainActivity.java:86)

@saudet
Copy link
Member

saudet commented Nov 29, 2021

Could you also provide the information that you get when FFmpegLogCallback.set() has been called?

saudet added a commit to bytedeco/javacpp-presets that referenced this issue Nov 29, 2021
@saudet
Copy link
Member

saudet commented Nov 29, 2021

I see what the problem is. The Android Camera API that OpenCV and FFmpeg support was introduced first in Android 7.0. Since about 90% of users have Android 7.0 or newer these days, I guess it makes sense to upgrade the minimum requirements. I've done that in commit bytedeco/javacpp-presets@cd28830, so it should now work with both FFmpegFrameGrabber and OpenCVFrameGrabber, which just uses VideoCapture. Please give it a try with the snapshots: http://bytedeco.org/builds/

@kshitijgarg2609
Copy link

I have extracted jar files, do we have to keep include folder which contains .hpp files? Should I send mail you the whole code with file structure?

@saudet
Copy link
Member

saudet commented Dec 1, 2021

What do you mean? JAR files for snapshots are the same as for releases. Do the same thing as you're used to do.

@kshitijgarg2609
Copy link

I mean, there are jar file files like ffmpeg, openblas, opencv, javacv and javacpp, I have copied in lib folder where as jar files containing .so files of android platform, I have extracted .so files and copied inside jniLibs folder.

@kshitijgarg2609
Copy link

I am sharing my android code folder https://drive.google.com/drive/folders/1N3zgCLJD3DOjV_lW_V8COuxMdgahmPc4?usp=sharing. Please do check

@saudet
Copy link
Member

saudet commented Dec 2, 2021 via email

@kshitijgarg2609
Copy link

@saudet I have already seen this example in which deprecated android.hardware.camera is used. My ques is why can't we use VideoCapture on camera if bytedeco ffmpeg supports android. Please help me out it would be great help. Bytedeco projects really works on desktop amazingly and the project is really really amazing.

@saudet
Copy link
Member

saudet commented Dec 2, 2021 via email

@kshitijgarg2609
Copy link

VideoCapture.open function always returns false

@saudet
Copy link
Member

saudet commented Dec 3, 2021

Ok, please try FFmpegFrameGrabber instead. It's usually better than OpenCV for video capture anyway.

@kshitijgarg2609
Copy link

Tried but failed

@saudet
Copy link
Member

saudet commented Dec 3, 2021 via email

@kshitijgarg2609
Copy link

I am getting exception

@saudet
Copy link
Member

saudet commented Dec 3, 2021 via email

@saudet
Copy link
Member

saudet commented Feb 10, 2022

This should be working now with JavaCV 1.5.7, but please let me know if you're still not able to get this working. Thanks!

@saudet saudet closed this as completed Feb 10, 2022
@saudet
Copy link
Member

saudet commented Mar 5, 2022

Note: There is a known bug in JavaCV 1.5.7 that prevents this from working smoothly, see issue #1756. We can work around it by calling FFmpegFrameGrabber.tryLoad() before anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants