permission is denied using Android Q ffmpeg": error=13, Permission denied

后端 未结 5 2139
逝去的感伤
逝去的感伤 2020-12-28 15:24

I want to get the frames from the RTSP video using ffmpeg. But for android 10 above I am getting error as below.

 E/FFmpeg: Exception while trying to run: [L         


        
相关标签:
5条回答
  • 2020-12-28 15:51

    I experienced the same when I used FFmpeg-Android-Java. It seems that this library is no more supported... So I just shifted to MobileFFmpeg and works like a charm!

    The only thing that you have to take care of is adding the followings in your module-level build.gradle if you use gradle plugin 4.0.0 (and above):

    android {
        packagingOptions {
            pickFirst 'lib/x86/libc++_shared.so'
            pickFirst 'lib/x86_64/libc++_shared.so'
            pickFirst 'lib/armeabi-v7a/libc++_shared.so'
            pickFirst 'lib/arm64-v8a/libc++_shared.so'
        }
    }
    
    0 讨论(0)
  • 2020-12-28 15:54

    From Android Q onwards, you cannot execute binaries in your app's private data directory.

    From the issuetracker: https://issuetracker.google.com/issues/128554619

    The change to block exec() on application data files for targetAPI >= Q is working-as-intended. Please see https://android-review.googlesource.com/c/platform/system/sepolicy/+/804149 for background on this change. Calling exec() on writable application files is a W^X (https://en.wikipedia.org/wiki/W%5EX) violation and represents an unsafe application practice. Executable code should always be loaded from the application APK.

    While exec() no longer works on files within the application home directory, it continues to be supported for files within the read-only /data/app directory. In particular, it should be possible to package the binaries into your application's native libs directory and enable android:extractNativeLibs=true, and then call exec() on the /data/app artifacts. A similar approach is done with the wrap.sh functionality, documented at https://developer.android.com/ndk/guides/wrap-script#packaging_wrapsh .

    Additionally, please be aware that executables executed via exec() are not managed according to the Android process lifecycle, and generally speaking, exec() is discouraged from Android applications. While not Android documentation, Using "exec()" with NDK covers this in some detail. Relying on exec() may be problematic in future Android versions.

    0 讨论(0)
  • 2020-12-28 15:56

    Change only on Build.gradle file targetSdkVersion 29 to 28 and Re-Install your app on your device - It is resolved your permission issue for temporary because of the targetSdkVersion 29 is required platform for released build on play store so I suggest to you use this library

    https://github.com/tanersener/mobile-ffmpeg

    0 讨论(0)
  • 2020-12-28 16:04

    The earlier answer correctly explains the problem you are hitting. This is also an open issue raised last September, discussed on the forum of the library you are using (from what I can see in the stack trace).

    The solution to compile for SDK 29 would be to stop putting binaries in the /data/ directory, and ensure they are in the native libs directory. That can't be achieved after the APK is installed and unpacked on non-rooted devices, and so should be done correctly when preparing the Android project (e.g. through gradle settings), and to make sure that upon installation the contents get properly unpacked: android:extractNativeLibs=true.

    In your case, this code moves binaries that are packaged as 'assets' into the users data directory:

    https://github.com/WritingMinds/ffmpeg-android-java/blob/master/FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/FileUtils.java

    That's a security concern running any executables in a location that is read/writeable. That source code I linked to above would need to be removed, instead, the native binaries packaged in /libs. The change is more secure as the /libs location inside your apps install directory is executable but not writable.

    In summary, the 3rd party lib needs to address it, or you could do it and contribute a pull request. Or fork your own and recompile it for yourself.

    There's still a problem, if your app actually downloads content after it is installed, and expects to execute any downloads. That's now impossible as far as I can tell in Android 10.

    The future-proof solution is to stop using external binaries, and to compile the dependencies as NDK projects. They will need jni wrappers around native code (a bit of work). There is a related project I know of you could look into.

    0 讨论(0)
  • 2020-12-28 16:13

    Based on the answer by @Saurabh Thorat, I made a pull request which fixes the problem. You can find it here.

    Quick summary:

    Moved ffmpeg binary to the libs folder and added android:extractNativeLibs = "true" to the manifest so it can copy itself into /data/app/{package_name}/lib/{arch}/ and then execute it from there (which is supported on Android 10).

    EDIT (for general use): In order for the executable files to be copied into /data/app/{package_name}/lib/{arch}/, the file names have to be lib(something).so. If the names don't start with lib and end with .so, they won't be copied.

    0 讨论(0)
提交回复
热议问题