mirror of
https://github.com/immich-app/immich.git
synced 2025-07-31 15:08:44 -04:00
scale video frame when possible
This commit is contained in:
parent
a3fc5d80bb
commit
8a8eb6e19d
@ -96,16 +96,25 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi {
|
|||||||
private fun decodeVideoThumbnail(assetId: String, targetWidth: Int, targetHeight: Int): Bitmap {
|
private fun decodeVideoThumbnail(assetId: String, targetWidth: Int, targetHeight: Int): Bitmap {
|
||||||
val uri =
|
val uri =
|
||||||
ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, assetId.toLong())
|
ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, assetId.toLong())
|
||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
contentResolver.loadThumbnail(uri, Size(targetWidth, targetHeight), null)
|
return contentResolver.loadThumbnail(uri, Size(targetWidth, targetHeight), null)
|
||||||
} else {
|
}
|
||||||
val retriever = MediaMetadataRetriever()
|
|
||||||
try {
|
val retriever = MediaMetadataRetriever()
|
||||||
retriever.setDataSource(ctx, uri)
|
try {
|
||||||
retriever.getFrameAtTime(0L) ?: throw RuntimeException("Failed to extract video frame")
|
retriever.setDataSource(ctx, uri)
|
||||||
} finally {
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
retriever.release()
|
retriever.getScaledFrameAtTime(
|
||||||
}
|
0L,
|
||||||
|
MediaMetadataRetriever.OPTION_NEXT_SYNC,
|
||||||
|
targetWidth,
|
||||||
|
targetHeight
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
retriever.getFrameAtTime(0L)
|
||||||
|
} ?: throw RuntimeException("Failed to extract video frame")
|
||||||
|
} finally {
|
||||||
|
retriever.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user