/*
This functions opens a video file and extracts the frames and put them into a vector of Mat(its the class for representing an img)
*/
void extract_frames(const string &videoFilePath,vector<Mat>& frames){
	
	try{
		//open the video file
  	VideoCapture cap(videoFilePath); // open the video file
  	if(!cap.isOpened())  // check if we succeeded
  		CV_Error(CV_StsError, "Can not open Video file");
	
  	//cap.get(CV_CAP_PROP_FRAME_COUNT) contains the number of frames in the video;
  	for(int frameNum = 0; frameNum < cap.get(CV_CAP_PROP_FRAME_COUNT);frameNum++)
  	{
  		Mat frame;
  		cap >> frame; // get the next frame from video
  		frames.push_back(frame);
  	}
  }
  catch( cv::Exception& e ){
    cerr << e.msg << endl;
    exit(1);
  }
	
}

/*
It saves a vector of frames into jpg images into the outputDir as 1.jpg,2.jpg etc where 1,2 etc represents the frame number
*/
void save_frames(vector<Mat>& frames, const string& outputDir){
  vector<int> compression_params;
  compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
	compression_params.push_back(100);
  
	for(std::vector<Mat>::iterator frame = frames.begin(),frameNumber=0; frame != frame.end(); ++frame){
	  string filePath = outputDir + to_string(static_cast<long long>(frameNumber))+ ".jpg";
	  imwrite(filePath,*frame,compression_params);
	}
	
	
}