MATLAB Answers

Displaying video file on App Designer Axes

49 views (last 30 days)
Zachary Swinnerton
Zachary Swinnerton on 2 Jul 2020
Answered: Geoff Hayes on 3 Jul 2020
Hello, I have read multiple previous posts on how to display a video file on a GUI axes but none of them seem to work. I have already wrote the sequence of images to an avi video file. In my GUI I have a menu bar that has open. I have successfully written the code to select a video file to open but it will not display on the axes in the GUI.
So far I have this under openmenuselected function:
[file, path] = uigetfile('.avi', 'Select Video File');
if isequal(file, 0)
disp('User selected cancel');
else
disp(['User selected ', fullfile(path,file)]);
%Displaying Video on Axes
input_video_file = fullfile(path,file);
video = vision.VideoFileReader(input_video_file);
... I have also tried VideoReader without vision. and a few other methods such as screenshot and frames
****I am stuck on how to display the avi file on Axes1. Can someone help?
Currently my video is 20fps and only has 50 frames but i dont want to limit to 50 frames incase there is a larger file read to be displayed.

  0 Comments

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 3 Jul 2020
Zachary - please see the example found at Read Video Using Frame Index and Time Interchangeably. I suspect that you could do something similar.
[file, path] = uigetfile('.avi', 'Select Video File');
if isequal(file, 0)
disp('User selected cancel');
else
disp(['User selected ', fullfile(path,file)]);
%Displaying Video on Axes
input_video_file = fullfile(path,file);
vidObj = VideoReader(input_video_file);
while(hasFrame(vidObj))
frame = readFrame(vidObj);
imshow(frame, 'Parent', app.UIAxes); % <--- use the Parent property
pause(2/vidObj.FrameRate);
end
end
The above code uses the VideoReader object to read the frames from the avi file. Each frame is shown on the axes specified by Parent property with the value app.UIAxes which is most likely named differently for your app (or it could be the same). I'm assuming that your above code is aware of the app object and so knows about the axes object defined in that app.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by