opencv_dart icon indicating copy to clipboard operation
opencv_dart copied to clipboard

[Bug] iOS Simulator VideoWriter not working correctly

Open kreazyme opened this issue 1 year ago • 6 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior: I want to save a video to document directory by this code:


    final video1 = cv.VideoCapture.create(file1!.path);
    final double frameWidth = video1.get(3);
    final double frameHeight = video1.get(4);
    final double fps = video1.get(5);
    final path = await getApplicationDocumentsDirectory();
    final outputPath = '${path.path}${Platform.pathSeparator}videotest.mp4';
    final outputVideo = cv.VideoWriter.open(
      outputPath,
      'MJPG',
      fps,
      (
        frameWidth.toInt(),
        frameHeight.toInt(),
      ),
    );

I try to use imwrite inside video1.read(), the result is perfectly. But when i try to using outputVideo.write(frame), the video size is zero

Expected behavior Video save correctly

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac M1 14.4 Simulator

Smartphone (please complete the following information):

  • Device: [e.g. Android 11]
  • ABI Version [e.g. arm64-v8a]

Additional context Add any other context about the problem here.

kreazyme avatar Aug 14 '24 07:08 kreazyme

I tried to import both .MOV and .MP4 file, but nothing difference :(

kreazyme avatar Aug 14 '24 07:08 kreazyme

The same issues in Android 13 Samsung physic device. I try to run VideoWriter many time but this code was not created this path. It seem like VideoWriter's bug

Evidence:

image

kreazyme avatar Aug 14 '24 09:08 kreazyme

get it. I finally managed to reproduce it. take a look at https://github.com/rainyl/awesome-opencv_dart/tree/main/examples/videoio first please.

image

I am not very familiar with android development, but I think it's because the permissions.

In the above example, when the destination path dst was selected manually from external storage (by clicking Save to), opencv complained that it cant find the path, but if we save to source file's parent directory directly, it worked fine.

rainyl avatar Aug 14 '24 14:08 rainyl

The same issues in Android 13 Samsung physic device. I try to run VideoWriter many time but this code was not created this path. It seem like VideoWriter's bug

Does the directory cache exists?

rainyl avatar Aug 14 '24 14:08 rainyl

@rainyl In some minutes, I think the error like that. Then, I changed to download Directory, give permission,... but nothing happen. After that, I try to use cv.imwrite() to save an image and this working fine. I think the permission and directory has no problem. Thank for your reply :D and have nice day

kreazyme avatar Aug 14 '24 16:08 kreazyme

@kreazyme thx~

but i still have 2 questions:

  • did you solved it?
  • have you tried .avi format? since i just noticed that you are writing to .mp4

rainyl avatar Aug 14 '24 23:08 rainyl