필터 지우기
필터 지우기

converting video to images by secends

조회 수: 1 (최근 30일)
caesar
caesar 2017년 12월 8일
댓글: KSSV 2020년 1월 30일
Hi I am trying to convert a video( MP4) to images such that the number of resulted images are same as the length of the video in seconds. for example, 2 minutes video would be 120 images each image is representing one second shot from the video. i have tried the following code
%
path = fullfile('C:\','Users','user','Downloads','data_test','videos');
movieFullFileName = fullfile(path, 'GP020165.mp4');
v = VideoReader(movieFullFileName)
D=v.Duration
[path, baseFileName, extentions] = fileparts(movieFullFileName);
path = pwd;
outputFolder = sprintf('%s/Movie Frames from %s', path, baseFileName);
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
for k = 1:D
this_frame = readFrame(v);
outputBaseFileName = sprintf('Frame %4.4d.jpg', k);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
imwrite(this_frame, outputFullFileName, 'jpg')
end
Although I got the correct number of images, the division was based on the frame (considering the video frame rate was 30FPS) so I ended up losing almost 80% percent of the video content.
I think the problem is in these lines
for k = 1:D
this_frame = readFrame(v);
any suggestion about what to change in the code above?

답변 (1개)

KSSV
KSSV 2017년 12월 8일
Try this:
vidObj = VideoReader('myvideopath');
numFrames = 0;
while hasFrame(vidObj)
F = readFrame(vidObj);
numFrames = numFrames + 1;
imagesc(F)
drawnow
end
numFrames
  댓글 수: 3
Saif Sayed
Saif Sayed 2020년 1월 30일
Undefined function 'hasFrame' for input arguments of type 'VideoReader'.
Error in VIDEO (line 3)
while hasFrame(vidObj)
can someone sort this error
KSSV
KSSV 2020년 1월 30일
hasFRame is introduced in 2014b.....what version you are using?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by