-
Notifications
You must be signed in to change notification settings - Fork 685
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
VideoFrameDecoder
creates large .tmp
which are not cleaned up if the app is killed
#2550
Comments
Actual file seems to be created by this call:
Specifically: Which calls this: coil/coil-base/src/main/java/coil/decode/ImageSource.kt Lines 274 to 278 in ce14e14
Path comes from here: coil/coil-base/src/main/java/coil/decode/ImageSource.kt Lines 298 to 304 in ce14e14
Okay so regarding this:
I can pass my own path via |
I'm wondering if calling |
…n creating video previews When SD Maid generates thumbnails for large videos via coil, then large `.tmp` files can be created. If SD Maid is killed before thumbnail generation has finished, then these `.tmp` can stay around until manually deleted. This PR changes the path where these files are stored, and deleted any orphaned files `.tmp` files on the next app launch. Also see coil-kt/coil#2550
…reviews When SD Maid generates thumbnails for large videos via coil, then large `.tmp` files can be created. If SD Maid is killed before thumbnail generation has finished, then these `.tmp` can stay around until manually deleted. This PR changes the path where these files are stored, and deleted any orphaned files `.tmp` files on the next app launch. Also see coil-kt/coil#2550
Hmm I thought Unfortunately |
Via Java NIO API, https://stackoverflow.com/questions/28752006/alternative-to-file-deleteonexit-in-java-nio I currently can't test it, because I can't get coil to build on my local machine.
I've got a custom IO API that handles access via different permissions, including root and adb, that exposes a |
|
Could I provide Coil with an |
I found the experimental API for I've changed my API to return a @OptIn(ExperimentalCoilApi::class)
internal fun FileHandle.toImageSource(
options: Options,
): ImageSource {
val handle = this
val sourceBuffer = this.source().buffer()
val mediaDataSource = object : MediaDataSource() {
override fun readAt(position: Long, buffer: ByteArray, offset: Int, size: Int): Int {
return handle.read(position, buffer, offset, size)
}
override fun getSize(): Long {
return handle.size()
}
override fun close() {
sourceBuffer.close()
handle.close()
}
}
return ImageSource(
source = sourceBuffer,
context = options.context,
metadata = MediaSourceMetadata(mediaDataSource),
)
} |
Replace the previous sepperate read/write functions. Allows `Coil` to efficiently load video thumbnails. Improves SAF performance. See #1434 See coil-kt/coil#2550
Replace the previous sepperate read/write functions. Allows `Coil` to efficiently load video thumbnails. Improves SAF performance. See #1434 See coil-kt/coil#2550
Replace the previous sepperate read/write functions. Allows `Coil` to efficiently load video thumbnails. Improves SAF performance. See #1434 See coil-kt/coil#2550
Nice! For cleaning up temp files, unfortunately I don't think there's a great solution. We already delete the temp file in a From my research it sounds like temp files won't be cleaned up when the app is closed, however they're likely to be cleared when the device needs space or the device is rebooted. Overall, they shouldn't last forever and will be cleaned up eventually. |
Also as an aside I used some of your code here to fix using |
So as I've found a solution for my issue and the "app-death" handling of tmp files is kinda out of scope (coil would have to keep track of the tmp files in some kind of DB), I think we can close this. What exactly did #2570 fix? |
@d4rken Using custom Okio |
Describe the bug
I think what happens is that
VideoFrameDecoder
creates some large.tmp
files to get a thumbnail. This creation can take time, e.g. for a 4GB video from my phone, it may take a few seconds to get that thumbnail. If the app is killed during that time, then coil looses track of these .tmp files.This can happen if by the user not waiting for thumbnails to finish loading and swipes the app away from the "recents" screen.
Disabling disk cache (
diskCachePolicy(CachePolicy.DISABLED)
) does not affect this.Do I need to check for orphaned tmp files and delete them on app launch?
Is there a way to configure the file name or path for these?
To Reproduce
Logs/Screenshots

Version
2.7.0
reproduced it on a Pixel 6 running Android 15The text was updated successfully, but these errors were encountered: