I’m trying to use tensorflow lite to detect a video stored on an android phone.
My approach is to extract all the frames of the video, convert them to a list of bitmaps, and detect each frame like a picture. I learned that MediaMetadataRetriever can get video frames, so I try
val mmr = MediaMetadataRetriever()
val file =
File("/sdcard/Android/fun.mp4")
if (file.exists()) {
mmr.setDataSource(file.absolutePath)
val bitmaps = mmr.getFramesAtIndex(0, 1000)
thread {
bitmaps.forEach { bm ->
runOnUiThread { runObjectDetection(bm) }
}
}
mmr.release()
runObjectDetection
is the same as this example Build and deploy a custom object detection model with TensorFlow Lite (Android)
However, it seems that getFramesAtIndex
can only have a few frames, and the program does not work when numFrames is greater than 100.
It looks like this is not a good solution, what I want is not to detect all frames of the video, but to detect every few frames, the rectangle of the result of the last detection remains on the video.
Is there a better solution?