VideoWriter generating unexpected results
Mostrar comentarios más antiguos
I believe the VideoWriter in R2023b has a bug. It can be reproduced with this piece of code:
v = VideoWriter('test.mp4', 'MPEG-4'); % use h264 encoding
v.FrameRate = 30;
v.Quality = 100;
open(v)
vidFrame = ones([1920, 1080, 3]);
writeVideo(v, vidFrame);
close(v)
There are black lines appearing in the output video:

I am on MacOS Sonoma 14.1.2 (M2 Ultra).
11 comentarios
Walter Roberson
el 11 de Dic. de 2023
I do not reproduce that in R2023b on MacOS Sonoma 14.2 (Intel)
Note: some video formats effectively cannot encode only a single frame, and might need a minimum of 2 frames written to the file.
Timothée Mouterde
el 20 de Dic. de 2023
Dear Walter, I also tested this issue.
I reproduce it on Sonoma (Silicon) and I just reinstalled Matlab 2023b Intel with Rosetta 2 to confirm that the bug is related only to the Silicon version (no bug on Intel).
As I mentioned in my response to Aishwarya, the bug is only with MPEG-4
Aishwarya
el 2 de En. de 2024
Hi Timothée,
I have also reporduced this issue. I found a possible workaround by using the frame width as multiple of 8.
Timothée Mouterde
el 14 de Mzo. de 2024
@Aishwarya thank you for the information.
I've reported this bug to Matlab and it is apparently on Apple's side to fix it.. It's been now several months and still no real fix to the best of my knowledge.
应盈
el 3 de Abr. de 2024
+1
Patch Kessler
el 9 de Jun. de 2024
I find that resizing the figure window can get around this bug. I'm not sure if it's the size or the aspect ratio, but after several tries I'm always able to get a movie without this problem.
Raphaël Nussbaumer
el 7 de Nov. de 2024
+1
Raphaël Nussbaumer
el 7 de Nov. de 2024
hFig = figure('position',[0 0 800 800])
I'm also getting this bug on Apple Silicon version. I've seen people talk about setting the figure size as a multiple of 8 to fix the problem, but both my width and heights are multiples of 8. In fact, the original poster here used 1920x1080, which are also multiples of 8. Can you expand on what you mean by multiple of 8?
By trial and error:
Height dimension doesn't seem to matter
Width is crucial. Get distortion is use some numbers e.g. 456, 458, 460, 462, however 464 works. Also 2x456 = 920 works fine.
Shaozhen
el 29 de Abr. de 2025
Same here. Apple Silicon M4, running 2024a
I tried different resolutions too, but none of them work. The only work-around I have is to use Uncompressed AVI.
Pierre
el 30 de Sept. de 2025
Same bug on 2025a. It seems incredibly difficult to fix.
Respuestas (0)
Categorías
Más información sobre Audio and Video Data en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!