Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cv2.VideoWritter not working #542

Closed
fahad-humanoid-robots-1998 opened this issue Sep 14, 2021 · 3 comments
Closed

cv2.VideoWritter not working #542

fahad-humanoid-robots-1998 opened this issue Sep 14, 2021 · 3 comments

Comments

@fahad-humanoid-robots-1998
Copy link

fahad-humanoid-robots-1998 commented Sep 14, 2021

I am facing the problem in writing the file:
> I have check all things like checking the rect , frame
> nothing of them is empty or false
> I am getting the processed frame MAT
> What I am facing is that the file does not save and there is no error or anything... Please guide me about this...
> I have read your other Issues like #303 and #143 but I don't have much knowledge about FFmpeg write now. So please
make me clear according to my scenario...
> Here is some Code to make it more clear...

    fourcc = cv2.VideoWriter_fourcc(*'MP4V')

    cap = cv2.VideoCapture(filename)
    flag = 1
    if (cap.isOpened() == False):
        print("Error opening video stream or file")
    exit_key = ord('q')
    while (cap.isOpened()):
        ret, frame = cap.read()
        if flag:
            height, width, _ = frame.shape
            out = cv2.VideoWriter(output+output_name, fourcc, 20.0, (2*width, height)) 
            flag = 0
        if ret:
            print('Video is processing..', end='\r')
            full_image = np.concatenate((frame, matte), axis=1)
            full_image = np.uint8(cv2.resize(full_image, (2*width, height), cv2.INTER_AREA))
            out.write(full_image)


  > I am reading files and want to save files into the internal storage what I have done for that is:


                --> This location is for the new processed file:
                                 path = join(os.environ["HOME"], path)  // path is suppose "output/"
                                 os.makedirs(path, exist_ok=True)
                                 if not path.endswith('/'):
                                 path += '/'
                                 return path


                 --> From Java Writing a file to Internal Storage:
                                  Uri data = null;
                                  if (result.getData() != null) {
                                      data = result.getData().getData();
                                      try {
                                          b = new byte[getContentResolver().openInputStream(data).available()];
                                          getContentResolver().openInputStream(data).read(b,0,b.length);
                                          String myFilePath = getFilesDir() + "/" + "fahad.mp4";
                                          File myFile = new File(myFilePath);
                                          FileOutputStream fos = new FileOutputStream(myFile);
                                          fos.write(b);
                                          fos.close();
                                      } catch (IOException e) {
                                          e.printStackTrace();
                                      }
@mhsmith
Copy link
Member

mhsmith commented Sep 14, 2021

As it says in #140, our builds of OpenCV don't support either reading or writing video files.

There's an example at #435 (comment) of using mobile-ffmpeg to convert the input video to PNG files, which you can then load and save individually in OpenCV. I'm not very familiar wth FFmpeg, but I guess there's probably a way of converting a sequence of PNG files back into a video, so that should solve your problem.

@fahad-humanoid-robots-1998
Copy link
Author

Will FFmpeg be supported in future..?

@mhsmith
Copy link
Member

mhsmith commented Sep 14, 2021

It won't be supported directly in the near future, but you can use mobile-ffmpeg as a workaround, like I said.

@mhsmith mhsmith closed this as completed Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants