FFmpeg-Android icon indicating copy to clipboard operation
FFmpeg-Android copied to clipboard

use jniLibs to work with targetSdkVersion=29

Open alexcohn opened this issue 5 years ago • 51 comments

Fixing https://github.com/bravobit/FFmpeg-Android/issues/126

alexcohn avatar Aug 11 '19 12:08 alexcohn

Just curious why this hasn't been merged in. Seems straightforward and needed.

darrinps avatar Aug 26 '19 15:08 darrinps

@darrinps there are some good reasons why this was not merged. One, as you noticed, is that this still lacks 64 bit, which makes this solution unsatisfactory for majority of the people who need to target Android Q. Second, people may consider renaming the executable to lib…so to be a dirty trick. Third, this removes a lot of code people had wrote, debugged, and invested into. Not a very nice feeling for a maintainer.

alexcohn avatar Aug 26 '19 18:08 alexcohn

I'm strongly looking forward speedy marge and release, and next one as completely fix.

HiroyukiTamura avatar Sep 08 '19 19:09 HiroyukiTamura

I would like to target Q as well but cannot until ffmpeg is working with it. Is this code in a fork with a release that can be included?

pcm2a avatar Sep 26 '19 21:09 pcm2a

@pcm2a what is your incentive to target Q? Remember, you can use Q APIs in a project that targets earlier SDK. At any rate, if you don't set min supported SDK to Q, you have to check the availability of these APIs before using them.

alexcohn avatar Sep 29 '19 07:09 alexcohn

@alexcohn just planning ahead. When R is released in 2020 all apps will be forced to target Q I plan on being ready in advance vs rushing to the finish line.

pcm2a avatar Sep 29 '19 14:09 pcm2a

@pcm2a if you think this PR is important, feel free to vote for it.

alexcohn avatar Oct 01 '19 17:10 alexcohn

Waiting for this merge

kartik1225 avatar Dec 27 '19 20:12 kartik1225

Besides this fix, for this library to work when targeting Q, we need an option to pass a FileDescriptor instead of having to pass the file path.

For example, instead of:

String[] command = {"-i", mStringFilePath, "-crf", "18", "-c:v", "libx264", "-c:a", "copy", pathToAppDirectory};
FFmpeg.getInstance(this).execute(command, new ExecuteBinaryResponseHandler()...

We could be given an option to pass a FileDescriptor, like this:

FileDescriptor fd = getContentResolver().openFileDescriptor(Uri, "r").getFileDescriptor();
//Note that there is no input path provided below
String[] command = {"-crf", "18", "-c:v", "libx264", "-c:a", "copy", pathToAppDirectory};
FFmpeg.getInstance(this).execute(command, fd, new ExecuteBinaryResponseHandler()...
//and when the developer doesn't want to use the FileDescriptor
FFmpeg.getInstance(this).execute(command, null, new ExecuteBinaryResponseHandler()

HBiSoft avatar Feb 03 '20 08:02 HBiSoft

@HBiSoft Passing FileDescriptor still won't let you work around the scoped storage. You need significant changes on the ffmpeg binary as well, to handle this: pass these file descriptors via Unix sockets.

If you switch to an ffmpeg in-process library solution, e.g. https://github.com/tanersener/mobile-ffmpeg, you can transparently pass your FileDescriptor with the /proc/self/fd/%d trick or pipe: protocol or use it through a custom AVIOContext.

alexcohn avatar Feb 03 '20 10:02 alexcohn

@alexcohn The owner of FFmpegMediaMetadataRetriever did something similar, have a look here:

https://github.com/wseemann/FFmpegMediaMetadataRetriever/blob/b42986fb4044c54131379407598d8ac0ff1a3326/gradle/fmmr-library/library/src/main/jni/metadata/ffmpeg_mediametadataretriever.c#L304

You can also have a look at my post on the mobile-ffmpeg library which is related to this - https://github.com/tanersener/mobile-ffmpeg/issues/334#issuecomment-581254355

I believe the owner of this library can easily implement this as well.

HBiSoft avatar Feb 03 '20 12:02 HBiSoft

@HBiSoft they have their struct State that can handle such URI, that's not how FFmpeg-Android is built.

alexcohn avatar Feb 03 '20 14:02 alexcohn

@alexcohn I was able to get it working on mobile-ffmpeg using the pipe protocol.

What suggestions do you have if we want to achieve the same using this library?

HBiSoft avatar Feb 04 '20 05:02 HBiSoft

@HBiSoft on the one hand, ffmpeg supports the pipe protocol out-of-the-box, and I believe that the Android port did not damage this functionality. On the other hand, the pipe protocol is not seekable, which may be a significant limitation for some ffmpeg file formats and some applications. I won't propose it as a panacea.

alexcohn avatar Feb 04 '20 06:02 alexcohn

@alexcohn I tested it with this library and it didn't work. Even if it does, it's not the solution. This library will either have to be rebuild in a way that excepts Uri's and can handle them properly or I can't see it working after developers are forced to target API level 29 (which will probably be within the next few months).

HBiSoft avatar Feb 04 '20 08:02 HBiSoft

@HBiSoft

I tested it with this library and it didn't work.

I am confused. Did you test pipes or the /proc/self/fd trick?

alexcohn avatar Feb 04 '20 10:02 alexcohn

@alexcohn I tested with pipe ->

String safUriToFFmpegPath(final Uri uri) {
    try {
        ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r");
        return String.format(Locale.getDefault(), "pipe:%d", parcelFileDescriptor.getFd());
    } catch (FileNotFoundException e) {
        return "";
    }
}

HBiSoft avatar Feb 04 '20 10:02 HBiSoft

The pipe: protocol has its own limitations, but in my limited experiments, the /proc/…/fd/… trick worked as expected. Only note that you cannot use /proc/self/fd here, you must put the actual Process.myPid() instead.

alexcohn avatar Feb 08 '20 23:02 alexcohn

@HBiSoft please see https://github.com/alexcohn/FFmpeg-Android/commit/686c4b50653e39c5acb181b0d09cec03e873af5d – for me it resolves the problem with Android Q. I only care about input, but I have no doubt you can follow the same approach to use an output directory out of the app sandbox.

alexcohn avatar Feb 08 '20 23:02 alexcohn

@alexcohn Thank you for your reply.

I have tested the above and I get /proc/4759/fd/70: Permission denied when selecting from the SD Card.

I see you mentioned this:

Work around the API 29 new [restrictions on use of external storage]

HBiSoft avatar Feb 09 '20 09:02 HBiSoft

I have tested the above and I get /proc/4759/fd/70: Permission denied when selecting from the SD Card.

Yes, it seems to only work for Downloads.

alexcohn avatar Feb 10 '20 09:02 alexcohn

Thanks to @Le-Dinh-Nam #126 comment, I could clean up a bit more. It seems that later platform versions extract all files from lib folder, not filtering by the lib.so pattern, as earlier.

UPDATE no, it does not, see Google Issue. I was forced to revert this change.

alexcohn avatar Mar 08 '20 14:03 alexcohn

Looks good! @Brianvdb Please merge this.

Aditya94A avatar Mar 13 '20 14:03 Aditya94A

Any update about this?

maxirosson avatar Mar 26 '20 22:03 maxirosson

waiting for this to be merged..

magicseal avatar Mar 28 '20 04:03 magicseal

Thanks @alexcohn for merging these changes. When will you release new version of library with this merge?

mshahidjanjua avatar Apr 06 '20 08:04 mshahidjanjua

Any update about this?

serkanucar avatar Apr 13 '20 19:04 serkanucar

Any update about this? When can I expect a new version?

SoluLabLive avatar May 05 '20 06:05 SoluLabLive

Any update about this?

maxirosson avatar Jun 03 '20 11:06 maxirosson

any update ??

Ahmed-Basalib10 avatar Jul 19 '20 07:07 Ahmed-Basalib10