linkedin / LiTr

Lightweight hardware accelerated video/audio transcoder for Android.
BSD 2-Clause "Simplified" License
611 stars 85 forks source link

FileNotFoundException when transforming the video #181

Open RishabJaiswal opened 2 years ago

RishabJaiswal commented 2 years ago

I am getting the following error java.io.FileNotFoundException: /storage/emulated/0/Movies/MyApp/video.mp4: open failed: EEXIST (File exists)

This happens while using the below api specifically on Android Devices above Android 10. It works fine below Android 10.

 MediaTransformer.transform(@NonNull String requestId,
                          Uri inputUri,
                          String outputFilePath,
                          MediaFormat targetVideoFormat,
                          MediaFormat targetAudioFormat,
                          TransformationListener listener,
                          TransformationOptions transformationOptions) 

Inside the above api MediaTargetException is thrown

com.linkedin.android.litr.exception.MediaTargetException: java.io.FileNotFoundException: /storage/emulated/0/Movies/MyApp/video.mp4: open failed: EEXIST (File exists)Media transformation failed for job id: null
Failed to open the media target for write.
Output file path or Uri encoded string: /storage/emulated/0/Movies/MyApp/video.mp4
MediaMuxer output format: 0

I believe this might have to do with the new File system changes introduced from Android 10

izzytwosheds commented 2 years ago

Thank you for reporting this! We will look into it.

RishabJaiswal commented 2 years ago

I think we should open a FileOutputStream or provide FileDescriptor just like the android-transcoder library does. Please find it here

izzytwosheds commented 2 years ago

Yes, I am planning to use a FileDescriptor as well.

izzytwosheds commented 2 years ago

There is a PR in flight, that should help. We already use FileDescriptor in MediaMuxerTarget but it was not exposed via transform method. It is now: https://github.com/linkedin/LiTr/pull/182 Let me know if this solves your issue.

RishabJaiswal commented 2 years ago

Thank you so much! Are we expecting a new release for the SDK with this fix?

izzytwosheds commented 2 years ago

Yes. We are preparing a new release. Meanwhile, you can try a snapshot release by adding following to your gradle build files (I didn't try it myself yet): repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } }

RishabJaiswal commented 2 years ago

Thank you !

RishabJaiswal commented 2 years ago

Can't find the snapshot. Please help.

izzytwosheds commented 2 years ago

Version 1.5.0 is being released now. Let me know if it fixes your issue.