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

The "helloworld" code in the ffmpeg.java's doc doesn't work on android platform. #1410

Closed
qq12cvhj opened this issue Apr 27, 2020 · 15 comments
Closed
Labels

Comments

@qq12cvhj
Copy link

I'm here again.I'm trying to Integrate ffmpeg into android App.The code in ffmpeg.java's doc file doesn't work.

  • String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);

  • `ProcessBuilder pb = new ProcessBuilder(ffmpeg, "-i", "/path/to/input.mp4", "-vcodec", "h264",

"/path/to/output.mp4");`

  • pb.inheritIO().start().waitFor();

When I'm trying to load the executable file path,I find the filename to find is like "platform/ffmpeg",and via classLoader,it can't be found.The platform means android-x86,android-x86_64,android-arm or android-arm64.
Instead,I find it that when I change the filename param to "lib/platform/ffmpeg",the executable file will be found by classLoader.Here,the platform means arm64-v8a,armeabi-v7a,x86, or x86_64.
This occurs only on Android platform so far in my environments.Below is the cache file tree of the app.
截图录屏_选择区域_20200427233328

Hope that you can get what I'm talking.Emmm,my English skill is poor,thanks. Just the "helloworld" code doesn't work on android.

@saudet
Copy link
Member

saudet commented Apr 27, 2020

The paths are found in these properties files:
https://github.com/bytedeco/javacpp/tree/master/src/main/resources/org/bytedeco/javacpp/properties
Make sure that ProGuard or something doesn't remove them from your APK.

@qq12cvhj
Copy link
Author

thanks。I'll take it a try. You open a good gate for me these days.
THANKS !

@qq12cvhj
Copy link
Author

qq12cvhj commented Apr 28, 2020

I've tried it.The .so libraries are all in the lib dir,and the .property file is also in the apk.It can be read by the Java Property class,the proguard also works.However when I'm trying to load the cache executable file,I make a breakpoint in the src code of the Loader.java of the Javacpp.There doesn't exist a folder named android-x86,instead when I set the subdir value to lib/x86,it works.I make breakpoint at line 1240 of Loader.java.Below is the values of the debug process.
截图录屏_选择区域_20200428102425

I think the problem is not related to the proguard,since the .property is loaded to the env,however it doesn't work.

@saudet
Copy link
Member

saudet commented Apr 28, 2020

I see, yes, the Loader doesn't take into account the "platform.library.path" property. We'll need to fix this. Thanks for pointing this out.

@saudet saudet added the bug label Apr 28, 2020
@qq12cvhj
Copy link
Author

I just use ffmpeg.So if I get the path ffmpeg file to execute,it will work,yes?The libs are all packed to the apk.And since I get the ffmpeg path,the left work is not related to the loader?

saudet added a commit to bytedeco/javacpp that referenced this issue Apr 28, 2020
@saudet
Copy link
Member

saudet commented Apr 28, 2020

As far as I know, all the files need to be extracted since the libraries are not going to get loaded as part of the main process, but I may be wrong.

I made some changes that should fix this in the last commit of JavaCPP. I have not tested them, but please give it a try with 1.5.4-SNAPSHOT: http://bytedeco.org/builds/ (It should work by overriding only the version of JavaCPP itself.)

@qq12cvhj
Copy link
Author

qq12cvhj commented Apr 28, 2020

Good job,It works!But I wonder why here you add a "/" at the beginning? As a fact ,add the "/" or not,the file path in the cache will both be returned,and the path is the same.
String subdir = (libraryPath.length() > 0 ? "/" + libraryPath : platform + (extension == null ? "" : extension)) + "/";

A more detailed feedback about this will be posted here if further problems occurs.Thank u.

@saudet
Copy link
Member

saudet commented Apr 28, 2020

The / specifies an absolute path for Loader.findResources(). It's just more efficient that way because we know it's an absolute path, even though it's not absolutely necessary because it will search anyway: https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/Loader.java#L831-L842

@qq12cvhj
Copy link
Author

qq12cvhj commented Apr 29, 2020

The new problem occurs.You'll find that in the cache dir,there's only a file,ffmpeg.The others(the *.so files)are not here.After I manually calling the method cacheResource,for example I call it this way:
Loader.cacheResource("lib/x86/libavcodec.so");,
then the libavcodec.so file will be there in the same cache directory,like this :
截图录屏_选择区域_20200429152451
All the .so libs will not appear in the cache dir unless you call the method cacheResource.This is the further problem after the fix of yesterday.So consider cache all the necessary libs to the same cache dir before cache executable file?
Thanks.

@saudet
Copy link
Member

saudet commented Apr 29, 2020 via email

@qq12cvhj
Copy link
Author

Yesterday I just get the path to the executable file.However,I can not run it,and all the libs are not there.What's more interesting is that,in the dir(path method Loader.load() returns) we don't have the permission to run it,it is just access for the root user.That's a bad news for users.like this:
截图录屏_选择区域_20200429160941

But in the /data/data/my-app-package/lib dir ,I find it we have the permission to access them.This folder will be there in the file system after you install the app.

Another problem confusing me is that ,on Android 8,the ffmpeg and ffprobe file(They are not .so files,just executable files.) will be there in the dir /data/data/my-app-package/lib ,in this dir I can run these two files. However,on Android 6,these two files are not packed here,there are just .so files.
Like this,on Android 8,we have can access these two executable files and all necessary files are here.
截图录屏_选择区域_20200429161307
But on Android 6,we can also access to all the files,but these two executable files are not packed to the dir.Like this:
截图录屏_选择区域_20200429162343

These problems just happens on android platform.We don't need consider the permission problem on other platforms but on android we have to.
Thanks.

@saudet
Copy link
Member

saudet commented May 1, 2020

Right, so we'll probably have to extract by ourselves everything we need to the cache directory...

saudet added a commit to bytedeco/javacpp that referenced this issue May 4, 2020
@saudet
Copy link
Member

saudet commented May 4, 2020

Ok, I fixed that as well in the last commit and it works fine on Android 7.0 for me! Enjoy

@qq12cvhj
Copy link
Author

qq12cvhj commented May 4, 2020

Thanks @saudet .I'll do some test later when I finish my current work.Further feedback I'wll post here.

@saudet
Copy link
Member

saudet commented Sep 10, 2020

The fix has been released with JavaCV 1.5.4. Thanks for reporting and testing this out!

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

No branches or pull requests

2 participants