Document usage with OpenCV
Please provide an example on how to use with PIL or OpenCV data, or more specific, existing NumPy arrays (which are used with OpenCV).
Maybe having a helper function would be nice as well...
Than you for your interest in using yuvio with PIL and OpenCV data. I'll try my best to explain the application for your use case. I'll also have a look whether it might be sensible to expose the internal numpy array data packaging in the public interface. Please let me know if you have any further questions or remarks.
At its core, yuvio is designed to read from and write to any raw memory, be it on disk, in memory, or elsewhere. It is possible to read from / write to any file-like object adhering to io.IOBase. If your numpy array data is organized according to one of the supported pixel formats, it can directly be read into a yuvio frame.
To use yuvio with data available in memory, e.g. a 1920x1080 yuv444p video frame available as a numpy array from opencv or PIL, you can use io.BytesIO and proceed as follows:
import io
import yuvio
data = ... # e.g. np.ndarray
buffer = io.BytesIO(data)
yuv_frame = yuvio.imread(buffer, 1920, 1080, "yuv444p")
To write back to memory, you can proceed as follows:
out_buffer = io.BytesIO()
yuvio.imwrite(out_buffer, yuv_frame)