Coder Social home page Coder Social logo

Scoped Storage about ffmpeg-kit HOT 10 CLOSED

arthenica avatar arthenica commented on June 22, 2024
Scoped Storage

from ffmpeg-kit.

Comments (10)

tanersener avatar tanersener commented on June 22, 2024

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

from ffmpeg-kit.

Nitish-29 avatar Nitish-29 commented on June 22, 2024

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 -> {
});

from ffmpeg-kit.

tanersener avatar tanersener commented on June 22, 2024

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.

from ffmpeg-kit.

Nitish-29 avatar Nitish-29 commented on June 22, 2024

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

from ffmpeg-kit.

blue-peacock avatar blue-peacock commented on June 22, 2024

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.

from ffmpeg-kit.

tanersener avatar tanersener commented on June 22, 2024

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

from ffmpeg-kit.

a-huk avatar a-huk commented on June 22, 2024

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.

from ffmpeg-kit.

a-huk avatar a-huk commented on June 22, 2024

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

from ffmpeg-kit.

a-huk avatar a-huk commented on June 22, 2024

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

from ffmpeg-kit.

Nitish-29 avatar Nitish-29 commented on June 22, 2024

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

from ffmpeg-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.