Implement the VideoCapture and VideoWriter functionality for reading and writing video files using Intel Media SDK (MFX) in OpenCV. The implementation should reside in the /app/ directory and adhere to the following requirements to ensure that the provided test cases pass:
VideoCapture Class:
Implement a method open that accepts a filename and a backend identifier (CAP_INTEL_MFX). The method should attempt to open the specified video file. If the file does not exist or cannot be opened, isOpened should return false.
Implement the operator >> for VideoCapture to read frames. If no frames can be read (either because the capture is not opened or the end of the video file is reached), it should provide an empty Mat object.
Ensure that isOpened() returns false when trying to read from a non-existent or invalid file.
VideoWriter Class:
Implement a method open that accepts a filename, codecs (using VideoWriter::fourcc), FPS, frame size, and a boolean indicating whether the video should be written in color. The method should validate:
The frame size must have both width and height as even numbers and must be greater than zero.
The codecs used for writing must be valid (returning -1 for unknown codecs).
FPS must be greater than zero.
If any of these validations fail, isOpened should return false.
Implement the operator << to write frames to the video file. If an invalid frame (incorrect size/format) is attempted to be written, it should be handled gracefully, and not write to the file.
Error Handling:
Ensure that all exceptions from failed operations are captured, and no exceptions are thrown during operations, as this is validated in the tests.
Resource Management:
Implement a release method for both classes to properly release the resources used for reading or writing video files. Ensure that after the release() method is called, isOpened() returns false.
Cleanup:
Ensure that temporary files created during the test executions are removed after completion.
Your implementation should be modular, maintainable, and effectively utilize OpenCV’s capabilities to interact with the Intel Media SDK efficiently, ensuring compliance with the expected behaviors described in the test cases.