user140888
user140888

Reputation: 609

how to read video file and split it into frames

I have this question: how can I load, in Android, a video file stored in my device, and how can I split it into frames? I'm using IntelliJ and I want to split the video into frames in order to process them with some image processing techniques (with OpenCv for Android library).

Upvotes: 3

Views: 6218

Answers (2)

Anup Cowkur
Anup Cowkur

Reputation: 20553

You don't strictly need to use OpenCV for this. You can use the MediaMetaDataRetreiver class provided by the SDK. It provides methods to extract metadata from all kinds of media files. You can try something like:

MediaMetadataRetriever retriever = new MediaMetadataRetriever();

retriever.setDataSource(file.getAbsolutePath());

imgView.setImageBitmap(retriever.getFrameAtTime(TIME_OFFSET,MediaMetadataRetriever.OPTION_CLOSEST));

where TIME_OFFSET is in microseconds.

Upvotes: 1

praks411
praks411

Reputation: 1992

Grabbing a video frame in OpenCV is pretty easy. There are lots of examples on OpenCV site. However crucial thing is to set-up opencv on andriod. You can follow this link on getting started with Opencv on andriod.

http://opencv.org/android

Once you have opencv installed on andriod. You can easily load video file and grab frame in Mat structure and then do some processing on it.

Here is the sample one. It will need some modification to run it on andriod. I think you will need to used NDK on andriod for this.

int main(int argc, char*argv[])
{

    char *my_file = "C:\\vid_an2\\desp_me.avi";
    std::cout<<"Video File "<<my_file<<std::endl;
    cv::VideoCapture input_video;

    if(input_video.open(my_file))
    {
         std::cout<<"Video file open "<<std::endl;
    }
    else
    {
        std::cout<<"Not able to Video file open "<<std::endl;

    }
    namedWindow("My_Win",1);
    namedWindow("Segemented", 1);
    Mat cap_img;
    for(;;)
    {
         input_video >> cap_img;
         imshow("My_Win", cap_img);
          waitKey(0);
    }
   return 0;
 }

Upvotes: 0

Related Questions