Video writer in java not saving
Hello all,
I want to record the frames I'm processing in my android smarthpone but nothing is being saved. I'm not getting any error either...
First I created the object in the MainActivity:
private VideoWriter videoWriter;
In the method onCreate I've initialized it and opened
videoWriter = new VideoWriter("saved_video.avi", VideoWriter.fourcc('M','J','P','G'), 25.0D, new Size(mOpenCvCameraView.getWidth(),mOpenCvCameraView.getHeight())); videoWriter.open("saved_video.avi", VideoWriter.fourcc('M','J','P','G'), 25.0D, new Size(mOpenCvCameraView.getWidth(),mOpenCvCameraView.getHeight()));
In the method onCameraFrame I've put the following
if(!videoWriter.isOpened()){ Log.w("opened video", "OPENED"); videoWriter.open("saved_video.avi", VideoWriter.fourcc('M','J','P','G'), 25.0D, new Size(mOpenCvCameraView.getWidth(),mOpenCvCameraView.getHeight())); videoWriter.write(frame); } else if(frameCounter<50) { videoWriter.write(frame); Log.w("saved frame", "SAVED"); } }
Every frame I run returns videoWriter.isOpened()==false. I'm not using any ".release" method because I didn't know where to put it.
Thanks in advance!
once would have been enough. * if it did not open the 1st time, guess what -- retrying with the same params won't work * please check isOpened() or the load() return value * "saved_video.avi" -- where would that be ? * 'm' 'j' 'p' 'g' is not a valid fourcc (uppercase !). please don't guess, but look those things up.
Hello berak,
(1) thanks,
(2) isOpened() is returning false
(3) I was hoping it would simply save it to the smartphone root. Am I doing it incorrectly? Previously I've tried to save it to the download folder "/Phone/Download/saved_video.avi"
(4) I had 'M' 'J' 'P' 'G' at first and it didn't work. Later I found a solution that someone was using 'm' 'j' 'p' 'g', so I decided to try it also and forgot to switch it back to MJPG. (edited the Question)
Thank you for your patience
Some more tweaks in the parameters that unfortunately also didn't work: - adding "apiPreference"= -1 and "isColour"=true in the parameters - removing character '_' from the name of the video - changing fps parameter to an integer (25)
any additional suggestions?