Display video and save frames in the same time !
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to display a video on GUI and in the same time I want it to convert video to frames and save on another folder automatically !
It's create a folder but the folder is empty ! also, I have some errors after I closed the window !
Code:
function Display_Callback(hObject, eventdata, handles)
filename = get(handles.edit1, 'String');
if ~exist(filename, 'file')
warndlg( 'Text in edit box is not the name of a file');
return
end
try
obj = VideoReader(filename);
catch
warndlg( 'File named in edit box does not appear to be a usable movie file');
return
end
ax = handles.ax1;
while hasFrame(obj)
vidFrame = readFrame(obj);
image(vidFrame, 'Parent', ax);
set(ax, 'Visible', 'off');
pause(1/obj.FrameRate);
end
OutVideoDir = 'Frames';
mkdir(OutVideoDir);
for i = 1:obj.NumberOfFrames
img = read(obj,i);
baseFileName = sprintf('%d.png', i);
fullFileName = fullfile(OutVideoDir, baseFileName);
imwrite(img, fullFileName);
end
1 Kommentar
Jan
am 4 Feb. 2018
If you get some errors and want us to help you to fix them, it is a good idea to post the messages. Please do not let the readers guess, which problem you have and what you observe.
Antworten (1)
Jan
am 4 Feb. 2018
What does "in the same time" mean? Currently you run two loops after each other. What about inserting the code in one loop?
OutVideoDir = 'Frames';
mkdir(OutVideoDir);
ax = handles.ax1('NextPlot', 'add', 'Visible', 'off');
ImageH = image([], 'Parent', ax);
while hasFrame(obj)
vidFrame = readFrame(obj);
set(ImageH, 'CData', vidFrame);
baseFileName = sprintf('%d.png', i);
fullFileName = fullfile(OutVideoDir, baseFileName);
imwrite(img, fullFileName);
pause(1/obj.FrameRate);
end
It is cheaper to create one image and update its CData afterwards.
2 Kommentare
Jan
am 4 Feb. 2018
If handles.ax1 is the handle of an axes object, this line:
ax = handles.ax1('NextPlot', 'add', 'Visible', 'off');
tries to convert the character arrays 'NextPlot', 'add' and so on to numerical indices. You mean:
ax = handles.ax1;
set(ax, 'NextPlot', 'add', 'Visible', 'off');
Siehe auch
Kategorien
Mehr zu Manage Products finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!