VideoWriter from file results in 0 bytes file
VideoWriter.fromFile seems not working?
following code: ` Future<String> processVideo(String filePath,String destFolder) async{ cv.VideoCapture cap = cv.VideoCapture.fromFile(filePath); double width = cap.get(cv.CAP_PROP_FRAME_WIDTH); double height = cap.get(cv.CAP_PROP_FRAME_HEIGHT); double fps = cap.get(cv.CAP_PROP_FPS);
String newFilePath = PathUtils.join(destFolder,"processed_${PathUtils.basename(filePath)}");
File f = File(newFilePath);
if(!f.existsSync()){
f.createSync(recursive: true);
}
cv.VideoWriter writer = cv.VideoWriter.fromFile(newFilePath,"MP4V", fps, (width.toInt(),height.toInt()));
while(cap.isOpened){
var (success, frame) = cap.read();
if(!success){
break;
}
if(frame.isEmpty){
print("empty frame");
}
else {
await writer.writeAsync(frame);
}
}
writer.release();
if(f.existsSync()){
int len = await f.length();
print(len);
}
return newFilePath;
} ` file should not be empty, I have checked that await writer.writeAsync(frame); is called and frames are not empty
Android 14
Any idea?
@letisoft Which version of opencv_dart and Flutter do you use? I need more info to reproduce.
Also, for android, you should be careful to permissions, check whether the newFilePath is valid.
Hello,
thanks for your quick response, really appreciated!
afeter setting log level I found the issue and the solution:
- VideoWriter.fromFile MP4V is not supported on android, so far so good, the problem is that this will not give any signes it failed, unless you enable logging
- I found the following workaround: VideoWriter.fromFile(newFilePath,"MP4V" if(!writer.isOpened){ writer.open(newFilePath,"MJPG", fps, (width.toInt(),height.toInt())); }
so I have sorted it, and it have anything to do with dart port
All right, glad that you solved it.
But we have nothing to do to inform users about supported fourcc, opencv c++ doesn't provide an API to get it.
Will add if opencv itself support it.