Display video and save frames in the same time !
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Jan
2018년 2월 4일
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.
답변 (1개)
Jan
2018년 2월 4일
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
Jan
2018년 2월 4일
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');
참고 항목
카테고리
Help Center 및 File Exchange에서 Manage Products에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!