Skip to content

Instantly share code, notes, and snippets.

@skl-songkiat
Last active October 16, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skl-songkiat/841f85be8913fa35f81f20d4a9d47149 to your computer and use it in GitHub Desktop.
Save skl-songkiat/841f85be8913fa35f81f20d4a9d47149 to your computer and use it in GitHub Desktop.
String fileName = Environment.getExternalStorageDirectory().toString() + "/DCIM/videosample/sample.mp4";
Log.i(TAG, "fileName="+fileName);
String aviFileName = Environment.getExternalStorageDirectory().toString() + "/DCIM/videosample/video_out.avi";
Log.i(TAG, "aviFileName="+aviFileName);
int rc = FFmpeg.execute("-i " + fileName + " -vcodec mjpeg " + aviFileName);
if(rc == RETURN_CODE_SUCCESS){
Log.i(TAG,"Success");
}else if(rc == RETURN_CODE_CANCEL){
Log.i(TAG, "CANCEL");
}else {
Log.i(TAG,String.format("Command execute failed with rc=%d and the output below.", rc));
}
VideoCapture cap = new VideoCapture();
cap.open(aviFileName);
Mat frame = new Mat();
int frameCount = 0;
if(cap.isOpened()){
Log.d(TAG,"Video Open");
while (true){
Log.d(TAG,"frameCount = " + frameCount);
cap.read(frame);
Imgcodecs.imwrite( Environment.getExternalStorageDirectory().toString() + "/DCIM/videosample/image_output_"+ frameCount + ".jpeg",frame);
frameCount++;
if(frameCount == 25){
break;
}
}
}else {
Log.d("VIDEOCAPTURE","Video Open FAILED");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment