I am using MediaMetadataRetriever as well as MLkit to do pose detection on a saved video file. I have attached some of my code here:
public ArrayList<ArrayList<Float>> extractPoses() throws FileNotFoundException {
//public Bitmap extractPoses() throws FileNotFoundException {
Log.e("DATA SOURCE: ", videoUri.getPath());
URIPathHelper uph = new URIPathHelper();
String videoInputPath = uph.getPath(applicationContext, videoUri).toString();
File vidInputFile = new File(videoInputPath);
File inputFile = new File(vidInputFile.getAbsolutePath());
if (!inputFile.canRead()) {
throw new FileNotFoundException("Unable to read $inputFile");
}
mdr.setDataSource(inputFile.getAbsolutePath());
ArrayList<ArrayList<Float>> totalVideoPose = new ArrayList<>();
int count = 0;
while (true) {
try {
Bitmap bmp = mdr.getFrameAtIndex(count);
InputImage inputImg = InputImage.fromBitmap(bmp, 0);
poseDetector.process(inputImg)
.addOnSuccessListener(new OnSuccessListener<Pose>() {
@Override
public void onSuccess(Pose pose) {
Log.e("POSE DETECT: ", "success");
if(!(pose.getAllPoseLandmarks().isEmpty())) {
ArrayList<Float> framePoseMarks = new ArrayList<Float>();
PoseLandmark left_shoulder = pose.getPoseLandmark(PoseLandmark.LEFT_SHOULDER);
framePoseMarks.add(left_shoulder.getPosition().x);
framePoseMarks.add(left_shoulder.getPosition().y);
totalVideoPose.add(framePoseMarks);
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("POSE DETECT: ", "pose detect on failure listener");
}
});
Log.e("Pose processing: ", "incrementing count");
count++;
} catch (IllegalArgumentException e) {
Log.e("POSE DETEC:", "Pose detec ended");
Log.e("POSE DETEC length: ", String.valueOf(totalVideoPose.size()));
for (ArrayList<Float> frame: totalVideoPose) {
Log.e("POSE DETEC SUBS: ", String.valueOf(frame.size()));
}
break;
}
}
return totalVideoPose;
//return null;
}
I know the bitmaps I am using are correct, as I have displayed them in an ImageView to verify. I am not sure why neither is executing - I dont see the output for Log.e("POSE DETECT: ", "success");
or for Log.e("POSE DETECT: ", "pose detect on failure listener");
. I appreciate any help and I am happy to answer any follow up questions!