Add VideoFrameDecoder to support decoding video frames from any source.#689
Conversation
| import coil.size.Size | ||
| import kotlin.math.roundToInt | ||
|
|
||
| internal class VideoFrameDecoderDelegate(private val context: Context) { |
There was a problem hiding this comment.
This class is basically pulled out entirely from VideoFrameFetcher without changes.
| size: Size, | ||
| options: Options | ||
| ): DecodeResult { | ||
| val tempFile = File.createTempFile("tmp", null, context.cacheDir.apply { mkdirs() }) |
There was a problem hiding this comment.
We don't need write permissions to do this, right?
There was a problem hiding this comment.
Yep! The cacheDir is free to write to.
Jawnnypoo
left a comment
There was a problem hiding this comment.
👍 Great work, I know this is much appreciated from those who need it.
|
It doesn't look like a workable solution in conjunction with streaming content urls (mpd - MPEG DASH, m3u8 - HLS), right? |
|
@ultraon It should work with any format supported by Android as long as the stream is not live and has completed. If you need video frames while the stream is in process I'd use ExoPlayer. |
|
it still didn't work with me in compose and this is my example or this code if there is any solution please let me know |
|
after a lot of pain the solution is |
|
could we make a buffer of something like that as if the video is long it takes too much time to load the image ? as i think it loaded the fully video then get its thumbnail |
…e. (#689) * Add VideoFrameDecoder. * Ensure directory exists. * Updates. * Catch IOException. * Docs. * Add a test. * Update Application. * Docs.
Fixes #687.
This finally adds support for decoding video frame from any source (including the network!) with an important caveat.
VideoFrameDecodercreates a short lived file on disk to buffer the source into. This is less performant than decoding the file in memory and it requires enough space on disk to copy the video which could be a problem for very large video files.VideoFrameFileFetcherandVideoFrameUriFetcherdon't have this caveat which is why they're not deprecated. Long term (possibly in the next major version) we'll hopefully be able to remove this limitation onVideoFrameDecoderand deprecate the fetchers.