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

Created on 27 Apr 2020  路  15Comments  路  Source: bytedeco/javacv

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.

bug

All 15 comments

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.

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

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.

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.

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?

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.)

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.

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

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.

Right, I think we'll need to do something about that as well. It doesn't work the way it is now?

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锛宩ust 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.

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

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Maleandr picture Maleandr  路  3Comments

The-Crocop picture The-Crocop  路  5Comments

Bahramudin picture Bahramudin  路  3Comments

kongqw picture kongqw  路  4Comments

eldhosengeorge picture eldhosengeorge  路  3Comments