Ask Your Question
0

Unable to extract frames from saved video file using opencv + python

asked 2015-06-14 13:26:10 -0600

Hi, I have already one video file and i want to extract frames from the same. Can you please suggest me some code to do the same?

edit retag flag offensive close merge delete

Comments

have a look at the tutorials

berak gravatar imageberak ( 2015-06-15 00:51:50 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2015-07-20 12:16:52 -0600

Hi, one example below.

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

    int num, i = 0;
VideoCapture cap(argv[1]);

if(!cap.isOpened())
{
    cout<<"ERRO: O Video não pode ser aberto! ";
    return -1;
}

int nframes = cap.get(CV_CAP_PROP_FRAME_COUNT);
cout << "Total de frames: " << nframes << endl;

int ini = atoi(argv[2]);
int fim = atoi(argv[3]);

if( ini < 0 || fim < 1 || ini+fim > nframes) {
    cout << "Inicio e fim invalidos para o video." << endl;
    return -1;
}


for( int i=0; i<ini; i++)
{
    Mat frame;
    cap >> frame;
}

for( int i=ini; i<ini+fim; i++)
{
    Mat frame;
    cap >> frame;

    stringstream ss;
    ss << argv[1] << "-frame-" << i << ".png";

    cout << ss.str() << endl;
    imwrite(ss.str(), frame, compression_params);

}

cout << "Concluido." << endl;
return 0;

}

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-06-14 13:26:10 -0600

Seen: 211 times

Last updated: Jun 14 '15