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

Scoped Storage #34

Closed
Nitish-29 opened this issue Apr 26, 2021 · 10 comments
Closed

Scoped Storage #34

Nitish-29 opened this issue Apr 26, 2021 · 10 comments
Assignees
Labels
android Affect Android platform library Affects the library question Further information is requested saf Issue about storage access framework v4.4 Affects v4.4 release

Comments

@Nitish-29
Copy link

Nitish-29 commented Apr 26, 2021

Current behavior :
Now I am using ffmpegkit 4.4 for testing purpose and the command is
String videoPath = FFmpegKitConfig.getSafParameterForWrite(context, inputUri);
String cmd = "-ss " + start + " -t " + duration + " -accurate_seek" + " -i " + videoPath + " -codec copy -avoid_negative_ts 1 " + outputFile;

While executing the command , session is giving me the protocol not found error. (saf:-1/VID_20210423_053509.mp4: Protocol not found)
Can you help to identify the issue.

Please note : My app targets sdk 30 and have requestLegacyExternalStorage = false

@tanersener tanersener added needs-more-details We need more details to understand what the problem is needs-analysis We don't know that this is. It must be investigated further labels Apr 26, 2021
@tanersener
Copy link
Collaborator

This must be investigated. What are the logs, console output and logcat, saying?

@tanersener tanersener self-assigned this Apr 26, 2021
@Nitish-29
Copy link
Author

Nitish-29 commented Apr 27, 2021

Hi ,
I'm trying to trim the video with command.

String videoPath = FFmpegKitConfig.getSafParameterForWrite(context, inputUri);
String cmd = "-ss " + start + " -t " + duration + " -accurate_seek" + " -i " + videoPath + " -codec copy -avoid_negative_ts 1 " + outputFile;

Whenever I start executeAsync , session gives me the following error
: FFmpegSession{sessionId=1, createTime=Tue Apr 27 05:16:23 EDT 2021, startTime=Tue Apr 27 05:16:23 EDT 2021, endTime=Tue Apr 27 05:16:24 EDT 2021, arguments=-ss 00:00 -t 00:00:16 -accurate_seek -i file:saf:-1/VID_20210423_053509.mp4 -codec copy -avoid_negative_ts 1 /storage/emulated/0/Android/data/com.sample.app/cache/trimmedVideo_20210427_051622.mp4, logs=ffmpeg version v4.4-dev-3015-gc0d0b1c4f6 Copyright (c) 2000-2021 the FFmpeg developers
built with Android (6875598, based on r399163b) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
configuration: --cross-prefix=i686-linux-android- --sysroot=/files/android-sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-x86/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=i686 --cpu=i686 --cc=i686-linux-android24-clang --cxx=i686-linux-android24-clang++ --ranlib=i686-linux-android-ranlib --strip=i686-linux-android-strip --nm=i686-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-x86/cpu-features/lib -lndk_compat' --target-os=android --disable-neon --disable-asm --disable-inline-asm --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-openssl --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gmp --enable-gnutls --enable-libmp3lame --enable-libass --enable-iconv --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxml2 --enable-libopencore-amrnb --enable-libshine --enable-libspeex --enable-libdav1d --enable-libkvazaar --enable-libilbc --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libtwolame --enable-libvo-amrwbenc --enable-zlib --enable-mediacodec
libavutil 56. 65.100 / 56. 65.100
libavcodec 58.123.100 / 58.123.100
libavformat 58. 67.100 / 58. 67.100
libavdevice 58. 12.100 / 58. 12.100
libavfilter 7.106.100 / 7.106.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
file:saf:-1/VID_20210423_053509.mp4: No such file or directory
, state=COMPLETED, returnCode=1, failStackTrace='null'}

I have enabled logging for FFmpegkit but app never seems to goes in to log callabck

Here's my executeAsync call

FFmpegKit.executeAsync(command, session -> {
if (ReturnCode.isSuccess(session.getReturnCode())) {
callback.onFinishTrim(finalOutputFile);
} else if (ReturnCode.isCancel(session.getReturnCode())) {
callback.onError(String.valueOf(session.getReturnCode()));
} else {
Log.d(TAG, String.format("Command failed with state %s and rc %s.%s", session.getState(), session.getReturnCode(), session.getFailStackTrace()));
callback.onError(String.valueOf(session.getReturnCode()));
// FAILURE
}
}, log -> Log.d(TAG, log.getMessage()), statistics -> {
});

@tanersener tanersener added the android Affect Android platform label Apr 27, 2021
@tanersener
Copy link
Collaborator

I have enabled logging for FFmpegkit but app never seems to goes in to log callabck

Which callback do you mean, the global one or session specific one? I see a Log.d(TAG, log.getMessage()) statement in the session specific log callback. That should be called.

There is a problem about your SAF url saf:-1/VID_20210423_053509.mp4. That -1 value after the protocol definition is the FD. And FD must always be a positive integer. Having -1 means error. This section in FFmpegKitConfig is responsible of getting that value from ParcelFileDescriptor. If something unexpected happens an error log is printed to logcat. Could you check logcat please? You should see an error printed there.

@Nitish-29
Copy link
Author

Nitish-29 commented Apr 28, 2021

When I try to get uri from gallery files - I get the following error
InputUri : content://media/external/video/media/287669

ERROR: android.app.RecoverableSecurityException: com.sample.app has no access to content://media/external/video/media/287669

SAF_PATH : saf:-1/VID_20200305_222658_HSR_120~2.mp4

Logs shared in previous comment is for gallery pick video

But If I try to record video and save file into application level file directory and then ffmpegkit I get the following error
InputURI : content://com.sample.app.provider/files/Swaggit/output2.mp4
SAF Video Path : saf:125/output2.mp4

Error : saf:125/output2.mp4: Operation not permitted

Logs
FFmpegSession{sessionId=1, createTime=Wed Apr 28 14:01:20 GMT+05:30 2021, startTime=Wed Apr 28 14:01:20 GMT+05:30 2021, endTime=Wed Apr 28 14:01:20 GMT+05:30 2021, arguments=-ss 00:00 -t 00:00:09 -accurate_seek -i saf:125/output2.mp4 -codec copy -avoid_negative_ts 1 /storage/emulated/0/Android/data/com.sample.app/cache/trimmedVideo_20210428_135948.mp4, logs=ffmpeg version v4.4-dev-3015-gc0d0b1c4f6 Copyright (c) 2000-2021 the FFmpeg developers
built with Android (6875598, based on r399163b) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --ranlib=aarch64-linux-android-ranlib --strip=aarch64-linux-android-strip --nm=aarch64-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --target-os=android --enable-neon --enable-asm --enable-inline-asm --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-openssl --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gmp --enable-gnutls --enable-libmp3lame --enable-libass --enable-iconv --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxml2 --enable-libopencore-amrnb --enable-libshine --enable-libspeex --enable-libdav1d --enable-libkvazaar --enable-libilbc --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libtwolame --enable-libvo-amrwbenc --enable-zlib --enable-mediacodec
libavutil 56. 65.100 / 56. 65.100
libavcodec 58.123.100 / 58.123.100
libavformat 58. 67.100 / 58. 67.100
libavdevice 58. 12.100 / 58. 12.100
libavfilter 7.106.100 / 7.106.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
saf:125/output2.mp4: Operation not permitted
, state=COMPLETED, returnCode=1, failStackTrace='null'}

If possible can you share any sample targeting sdk 30

@blue-peacock
Copy link

I'm facing a similar problem:

First I create a new MediaStore entry with contentResolver.insert.
This gives me a uri like content://media/external/images/media/2945.
getSafParameterForWrite() returns saf:171/testImage.jpg which seems correct.

The ffmpeg command gives the error:
Could not open file : saf:171/testImage.jpg
av_interleaved_write_frame(): I/O error

The file was created, but has 0 Bytes.

@tanersener
Copy link
Collaborator

@Nitish-29 There are several exceptions/errors in your logs. I'm not sure whether you're doing something allowed by Android. Please see Android storage use cases and best practices guide and validate that you're not trying something prohibited by Android.

ERROR: android.app.RecoverableSecurityException: com.sample.app has no access to content://media/external/video/media/287669

saf:125/output2.mp4: Operation not permitted

ffmpeg-kit-test project includes test applications that use SAF feature and target API Level 30. You can see how SAF is used there.

@blue-peacock I'm not good at guessing what is wrong by looking at a few log lines. I suggest creating another issue and filling out issue template fields.

@tanersener tanersener added library Affects the library v4.4 Affects v4.4 release LTS Affects LTS releases saf Issue about storage access framework and removed LTS Affects LTS releases labels May 1, 2021
@a-huk
Copy link
Contributor

a-huk commented May 5, 2021

Yes, I also face the same issue. I am working on Android 10. I get a file uri from a video from the integrated video recorder, then I can't paste it into ffmpeg due to the same error.

@a-huk
Copy link
Contributor

a-huk commented May 6, 2021

OK, so I got past the issue. This is my first android app. But basically, with newer android versions, storage access is harder due to security reasons/measures. What works for me is only tested on android 10, so it might not work on other versions. I want to pass a video as an input for ffmpeg: either a file or record directly a video from the camera recorder. The camera recorder directly returns a working uri. While to get a uri for a given file, look here https://developer.android.com/training/data-storage/shared/documents-files#java , under "open a file". So now that you have a valid uri, you simply pass it to FFmpegKitConfig.getSafParameterForRead . Make sure that you use this method when reading a file. You need a different one FFmpegKitConfig.getSafParameterForWrite to write a file (output ffmpeg file). It was a dumb oversight, but there are two methods, one for reading and the other one for writing. Make sure that you use the right one based on whether you are using it for the ffmpeg input or output file. The two methods should work fine with a normal android uri

@a-huk
Copy link
Contributor

a-huk commented May 6, 2021

I believe that's what is happening to @Nitish-29. @tanersener could I ask you to change the wiki to reflect the difference?

@Nitish-29
Copy link
Author

@a-huk , thanks , yes was the same error.

@tanersener tanersener added question Further information is requested and removed needs-analysis We don't know that this is. It must be investigated further needs-more-details We need more details to understand what the problem is labels Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Affect Android platform library Affects the library question Further information is requested saf Issue about storage access framework v4.4 Affects v4.4 release
Projects
None yet
Development

No branches or pull requests

4 participants