Is it possible to export RGB + alpha channel using the VideoFileWriter?
Show older comments
Hi guys, I am currently trying to export a video file using VideoFileWriter function from the computer vision toolbox. Apparently, my video contains information on the alpha channel (transparency). I was wondering whether there would be a way to do this? Many thank's in advance.
Ronny
Answers (1)
Darshak
on 20 Feb 2025
Hi Ronny,
While working with videos and the computer vision toolbox, I too faced issues with the handling of alpha values. The “vision.VideoFileWriter” has the capability to handle the alpha values but that is file format dependent. The export works with the following formats:
- MJ2000 (Motion JPEG 2000)
- MPEG4 (H.264)
The following sample code can you help with the same maybe:
vidReader = VideoReader('inputVideo.mp4');
videoFWriter = vision.VideoFileWriter('outputVideo.mj2', ...
'FrameRate', vidReader.FrameRate, ...
'Quality', 95); % Adjust quality as needed
while hasFrame(vidReader)
videoFrame = readFrame(vidReader);
end
release(videoFWriter);
The documentation for the “vision.VideoFileWriter” might help you a bit more with the working and usage of the function:
I hope this helps with your issue.
1 Comment
Walter Roberson
on 20 Feb 2025
You do not show an example of writing alpha component -- your code does not use videoFWriter after creating it.
The documented image format is
Filename = videoFWriter(videoFrame) writes one frame of video, videoFrame, to the output file. The input video can be an M-by-N-by-3 truecolor RGB video frame, or an M-by-N grayscale video frame..
which does not allow for the possibility of an alpha component, and there is no Alpha input port.
Categories
Find more on Process Point Clouds in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!