MATLAB online video creation trouble

The following test code runs in 3 seconds natively with v2025a but stalls and never completes in MATLAB online. Any suggestion appreciated.
% Quick animation video test (works in MATLAB Online and Desktop)
clear; close all; clc;
tic
% ---- Output file (timestamped) ----
outdir = 'testvideos';
if ~(exist(outdir,'dir')==7), mkdir(outdir); end
ts = char(datetime('now','Format','yyyyMMdd_HHmmss'));
base = fullfile(outdir, ['ball_line_' ts]);
vidfile = [base '.avi'];
vw = VideoWriter(char(vidfile));
vw.FrameRate = 30;
vw.Quality = 90;
open(vw);
% ---- Figure & axes (keep simple for Online) ----
figW = 640; figH = 360; % modest, consistent size
animFig = figure('Color','w','Units','pixels', ...
'Position',[100 100 figW figH], 'Resize','off');
ax = axes('Parent',animFig); hold(ax,'on'); axis(ax,'equal'); axis(ax,'off');
plot(ax, [0 1], [0 0], 'k-', 'LineWidth',2); % the line
xlim(ax,[0 1]); ylim(ax,[-0.2 0.2]);
% ---- Ball (drawn as a filled circle) ----
r = 0.05; y0 = 0;
hBall = rectangle(ax, 'Position',[0.05-r y0-r 2*r 2*r], ...
'Curvature',[1 1], 'FaceColor',[0.20 0.35 0.85], 'EdgeColor','none');
% ---- Simple motion & capture loop ----
duration_sec = 2; % 2-second clip
nframes = duration_sec * vw.FrameRate;
xs = linspace(0.05, 0.95, nframes); % left -> right
for k = 1:nframes
set(hBall, 'Position', [xs(k)-r, y0-r, 2*r, 2*r]);
drawnow('expose'); % ensure the frame is rendered
fr = getframe(animFig); % capture the figure
writeVideo(vw, fr);
end
close(vw);
disp("Wrote video: " + string(vidfile));
Wrote video: testvideos/ball_line_20251014_201746.avi
toc
Elapsed time is 4.104192 seconds.

 Accepted Answer

The code completes successfully for me when I run it. It took 13-15 seconds.
Given that it does run, I'd suggest the typical actions for browser-based tools.
  1. Check that you meet the browser requirements.
  2. Try a different browser
  3. Try clearing your cookies and cache
  4. Try signing out and signing back in. I'd suggest waiting ~15 mins to ensure you get a fresh worker.
If it still doesn't work, follow these instructions to reset your session.
If that doesn't work, contact technical support.

4 Comments

Cris,
Thanks so much. I was running on Chrome (Version 141.0.7390.108 (Official Build) (arm64)) latest (blessed). I tried that test script on Safari and it worked fine. I cleared cache and cookies (everything) on Chrome, updated it, and signed out and back in, and this test script thjen worked on Chrome, though more slowly. That was a test script. My actual video making script ( https://www.mathworks.com/matlabcentral/fileexchange/182264-two-dimensional-newton-cradles?s_tid=srchtitle ) runs great and snappily natively (MacBook Pro M1 Max) and in MATLAB Online on Safari, and at a total snail pace with MATLAB Online with my Chrome. Logged in and out of MATLAB Online. Deleted old session files to no avail. Grrr...Other scripts that do not make videos have always run fine natively and online with Chrome. It is hard for me to understand why there might be a browser dependency. And the the real script is making but a 20 MB final video - it's not that I am hitting my online storage limit. My script is not trying to display the video, just writing the file. 'WHat's love, oops I mean the browser, got to do with it?'
"What's a browser but a second-hand emoticon?"
For performance issues, please report those directly to MathWorks: https://www.mathworks.com/support/contact_us.html

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!