-
-
Notifications
You must be signed in to change notification settings - Fork 796
Support Android scoped storage #440
Support Android scoped storage #440
Conversation
I have another improvement for scoped storage, where I take care of the "content" Uri in C, thus cleaning up the Java code and possibly, serving people who want to use the C API directly from their Android app. I put it in an "experiment" branch for now, because I am still not certain whether this is a good thing. |
I see that this PR is no longer in progress. First of all, why do we need this? I thought that Android reverted some of their changes in the API and so we no longer had issues about it. |
First of all, it's cool. You can work with I have a separate experiment in progress (close to final), that does all this on the C side, even more cool. A developer can use mobile_ffmpeg from Java or from native code, pass Yes, Android 11 intends to step back on the restrictions of extracting the 'real path' from such Uri, but it's still not released, we don't know how it will evolve. And anyways, there are tons of Android 10 devices that are not going to disappear where the workaround of With this protocol, we have a better, cleaner solution. We don't need the external storage permissions, it works on sd-card where others seem to have troubles… Recently, I came across another problem with mobile-ffmpeg: https://stackoverflow.com/a/62439309/192373. The output file must be exposed to MediaStore. With the I don't want to press you to embrace this change. Please see the two feature branches https://github.com/alexcohn/mobile-ffmpeg/tree/feature/scoped-storage and https://github.com/alexcohn/mobile-ffmpeg/tree/feature/scoped-storage-jni (in your spare time) and if you have any thoughts about it, let me know. |
@alexcohn Sorry, I had deleted it, after seeing the SAF section in wiki. But it did not help, I read somewhere that it does not work for mp4 files due to seeking problems. Currently i'm in the process of building ffmpeg using your pull request. How do I use it in the command? will this syntax work?
Previously commented |
Your expression has extra
But I suggest that you try another branch that hides all these troubles on the C side, https://github.com/alexcohn/mobile-ffmpeg/tree/feature/scoped-storage-jni. The command will simply look as
|
@alexcohn hey, I have tried both of them. Jni one was definitely easier, but I am getting some problems.
This goes for very long, lasts about 2-3 seconds and then starts executing command. This does not happen in the current pull request. (only occurs in the jni branch)
Thanks a lot for your help! |
@JayParikh20 Thanks. Could you post the ffmpeg commands that were used in the two cases? |
@alexcohn yes, sure. I have hardcoded some stuff.
This one is for image files:
|
I'm looking at the changes in this PR. There are a few things that I don't understand. For example, |
Here is why: ffmpeg looks at the file name (both on input and on output) to determine the file type. On input, this is usually not critical, and sniffing the content can resolve the ambiguity. On output, this is the only source of information, unless you set the format explicitly (people rarely do). So, the protocol handler for The name part is optional. Everything will still work if it is not appended (if the system can choose the output format). |
Okay, thanks. Have you considered implementing this protocol as a more general solution that non-Android users can use as well? If |
This is weird, video files are not working even if I use a file path. (both branches) |
@JayParikh20, are you sure you have libx264 enabled? Also, if it takes few seconds to run on a single jpg for you, try a real short video to begin with. |
Have you got a use case for this protocol on iOS? Because for Android I could simply extend the pipe: protocol, by borrowing the seekable option from file:. The As you see, using JNI removes a lot of complexity from the API, and makes it much more robust. |
Are you asking if there is a module on iOS similar to Scoped Storage that returns fds? I don't know. In fact, I don't think we need to have such a module to introduce this protocol on iOS/tvOS. This solution is based on file descriptors and file descriptors can be used to access files in any os which is posix complaint, not only iOS/tvOS.
This can break the |
@alexcohn, I checked it again, x264 is enabled. I tried it with 10 seconds mp4 video, waited for approx 5 mins, no output. [using both uri & file] |
@JayParikh20 Let us switch to another thread, maybe here: alexcohn#1. |
Not exactly. I wonder what use cases for passing file descriptors may exist on iOS (except classical pipes). As for breaking the pipe: protocol: don't worry, the idea is to only extend it with optional seekable. Such extension is clean and follows the pattern of other ffmpeg protocols (file: included). The point is that a pipe: is controlled by the parent, and actually so is saf: protocol, the Java app opens all the files (inputs and outputs) and passes them by descriptor to ffmpeg. On the other hand, content: is different: here, ffmpeg decides when a file must be opened and when it will be closed. |
Extending a protocol is always possible. My main concern is about maintaining that protocol. Those changes are applied inside |
I have found a problem with my approach: the image2 logic breaks because they interpret the context: string as file path, and they can find |
I don't know the details of |
With |
Apparently |
4ca25d6
to
609d0b9
Compare
@tanersener In the end, I feel quite confident with the minimalistic approach. You can see the changes to |
sure |
It took some while to get back to this, but here is a change that seems to answer your expectations. It adds a simple SAF tab. What do you think? |
Thanks @alexcohn |
Thanks, I'm planning to test these changes this week. I have a few questions regarding the protocol definition. Is it possible to use this protocol without using Also, I'm looking at the syntax of other protocols supported by |
This is not a 'protocol'. In the end, I am using custom AVIO and the You cannot prepare a compliant The special string prefix closely follows the way custom protocols are defined in There is a live discussion about the files with spaces in their display name, so before closing this PR, let's see that @HBiSoft has no outstanding questions. |
I guess the spaces problem has finally been resolved for good. |
android/test-app/src/main/java/com/arthenica/mobileffmpeg/test/SafTabFragment.java
Outdated
Show resolved
Hide resolved
android/test-app/src/main/java/com/arthenica/mobileffmpeg/test/SafTabFragment.java
Show resolved
Hide resolved
Tested the changes. Everything, except saving to cloud worked during my tests. Saving to cloud crashes for me unfortunately. Was that tested? |
Also, some code cleanup in SafTabFragment.
…ore options to choose.
keep the temp files open, we must keep the ParcelFileDecriptor until the fd is closed
I confirm that write to Google Drive was failing. Unfortunately, the fix requires JNI. Please see alexcohn@cdb4bdf |
So, there are no unresolved issues anymore, and write to drive works now. Is there anything else missing? |
No, it was necessary to re-run the tests after your latest commit. Just finished running them and merged the changes. Thanks for working on that 👍 |
I just tried this and it crashes: This is the ffprobe command executed:
And this is the sigabrt crash:
Tested targeting android 11 using a pixel 4. |
Well, I must rest Android 11. Also, where does the media file actually located? |
It's on |
I confirm this problem on Android API 30. |
* development: (155 commits) fix android async example update ios manual test application update android test app support iOS 14, fixes tanersener#553 Support Android scoped storage (tanersener#440) Update arch-common.sh (tanersener#534) fix monitorWait method for android, fixes tanersener#520 reorganise android.mk for cpu-features update the packaging for android arm-v7a and arm-v7a-neon architectures and remove custom abi rules for releases, fixes tanersener#511 fix proguard rules, fixes tanersener#508 target android api level 30 update android gradle version Update README move tooltips to resources fix android release packaging script update ios test-app settings fix ios/tvos system library indexes in ffmpeg build scripts use v4.4.LTS in test applications release v4.4.LTS fix mobile-ffmpeg videotoolbox flags for tvos ... # Conflicts: # ios/configure # ios/src/MobileFFmpeg.h # ios/src/MobileFFmpeg.m # src/ffmpeg/configure # src/ffmpeg/libswscale/aarch64/hscale.S # src/libvorbis/doc/Vorbis_I_spec.html # src/libvorbis/doc/Vorbis_I_spec.pdf
This intends to answer #334 and #185. Inspired by https://stackoverflow.com/a/60702386/192373.
This works with all videos received from ACTION_OPEN_DOCUMENT on all Android versions (tested 21, 29, and R), including custom document provider (I tested Google Drive) and removable sdcard on Android 10.
This also works for output, as set with ACTION_CREATE_DOCUMENT, and understands the media suffix (e.g.
mp3
) to create file format automatically (if the user requests so).The same protocol can also be used to properly read bundled assets on Android (see https://stackoverflow.com/q/24701029/192373). This PR does not demo this use case.