0

I need to read mp4 frame by frame

I made such implementation on Java

public static void read(@NonNull final Context iC, @NonNull final String iPath)
{
    long time;

    int fileCount = 0;

    //Create a new Media Player
    MediaPlayer mp = MediaPlayer.create(iC, Uri.parse(iPath));
    time = mp.getDuration() * 1000;

    Log.e("TAG", String.format("TIME :: %s", time));

    MediaMetadataRetriever mRetriever = new MediaMetadataRetriever();
    mRetriever.setDataSource(iPath);

    long a = System.nanoTime();

    //frame rate 10.03/sec, 1/10.03 = in microseconds 99700
    for (int i = 99700 ; i <= time ; i = i + 99700)
    {
        Bitmap b = mRetriever.getFrameAtTime(i, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);

        if (b == null)
        {
            Log.e("TAG", String.format("BITMAP STATE :: %s", "null"));
        }
        else
        {
            fileCount++;
        }

        long curTime = System.nanoTime();
        Log.e("TAG", String.format("EXECUTION TIME :: %s", curTime - a));
        a = curTime;
    }

    Log.e("TAG", String.format("COUNT :: %s", fileCount));
}

and here execution time

  E/TAG: EXECUTION TIME :: 267982039
  E/TAG: EXECUTION TIME :: 222928769
  E/TAG: EXECUTION TIME :: 289899461
  E/TAG: EXECUTION TIME :: 138265423
  E/TAG: EXECUTION TIME :: 127312577
  E/TAG: EXECUTION TIME :: 251179654
  E/TAG: EXECUTION TIME :: 133996500
  E/TAG: EXECUTION TIME :: 289730345
  E/TAG: EXECUTION TIME :: 132158270
  E/TAG: EXECUTION TIME :: 270951461
  E/TAG: EXECUTION TIME :: 116520808
  E/TAG: EXECUTION TIME :: 209071269
  E/TAG: EXECUTION TIME :: 149697230
  E/TAG: EXECUTION TIME :: 138347269

This time in nanoseconds == +/- 200 milliseconds... It is very slowly... I need around 30 milliseconds by frame.

So, I think this method is execution on CPU, so question if there a method that executing on GPU?

P.S. Android can read mp4 video in good speed(because when you see video, you see it without stab and slowing... You can see video like video), so how can I use the same methods like android use for read mp4?

BDL
  • 21,052
  • 22
  • 49
  • 55
Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • 1
    What exactly are you trying to do? It looks like currently you are getting the number of sync frames in the video. – HB. Jun 30 '19 at 13:48
  • @HB. Actually I need method that will return me frame by frame (by request) or, bunch of frames... Method that I described above is ok in case functionality, but problem is execution time... it is critical for me. I need to reduce it from 200 msec to 30 msec... There is one more my question that is similar https://stackoverflow.com/q/56791589/5709159 – Sirop4ik Jun 30 '19 at 14:01
  • Mediacodec is your best option. You can have a look at the Grafica project, it has great examples - https://github.com/google/grafika/blob/master/app/src/main/java/com/android/grafika/MoviePlayer.java – HB. Jun 30 '19 at 14:04
  • You can also have a look at this question, it might help you - https://stackoverflow.com/q/52036704/8199772 – HB. Jun 30 '19 at 14:06
  • Also this one for importing directly for GPU use:https://stackoverflow.com/questions/54924645/process-every-camera-frame-as-bitmap-with-opengl – solidpixel Jun 30 '19 at 22:01
  • Look here https://stackoverflow.com/a/56984481/5709159 – Sirop4ik Jul 11 '19 at 08:11

0 Answers0