how can i read all the frames/images from a .rec file?

조회 수: 5 (최근 30일)
Nikolaos
Nikolaos 2014년 8월 13일
댓글: Geoff Hayes 2019년 3월 26일
Hello. I am trying to read all the images/frames from a video. I built up the following code:
fid = fopen('C:\HiSpecAutoSave\Autosave4.rec');
fseek(fid, 1310720, -1);%move file pointer to first frame of data
img=fread(fid, [1280, 256], 'uint8=>uint8');
fclose(fid);
img2 = fliplr(img);%we need to flip it left/right for some wierd reason
img3 = imrotate(img2, 90);%and rotate, unsure why it's stored this way
My problem is that this code reads only the first image/frame. What should i do to read all the images? Thanks in advance

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 8월 13일
Nikolaos - if we know the number of frames in the video and we assume that all frames follow each other (in the rec file) then we could do something like the following
% open the file for reading
fid = fopen('C:\HiSpecAutoSave\Autosave4.rec');
% if the file descriptor is valid
if fid>0
% assume 100 frames
numFrames = 100;
% pre-allocate memory for each frame
allFrames = uint8(zeros(256,1280,numFrames));
% move file pointer to first frame of data
fseek(fid, 1310720, -1);
% read each frame
for k=1:numFrames
% read the kth frame
img=fread(fid, [1280, 256], 'uint8=>uint8');
% flip it
img = fliplr(img);
% rotate it and save to array
allFrames(:,:,k) = imrotate(img, 90);
end
fclose(fid);
end
The above will read each frame into the allFrames array. Try it and see what happens!
  댓글 수: 4
Nikolaos
Nikolaos 2014년 8월 24일
편집: Nikolaos 2014년 8월 24일
Thank you very very much. Your advice helped me a lot. It made me look at the right direction. Below i send you the final code.
% open the file for reading
fid = fopen('C:\HiSpecAutoSave\Autosave4.rec');
% if the file descriptor is valid
if fid>0
% move file pointer to first frame of data
fseek(fid, 1310720, -1);
k = 0;
while ~feof(fid)
[img,ctr] = fread(fid,[1280,256],'uint8=>uint8');
if ctr < (1280*256)
break; %incomplete frame so exit
else
k = k + 1;
% flip it
img = fliplr(img);
% % rotate it and save to array
allFrames(:,:,k) = imrotate(img, 90);
end
end
end
Geoff Hayes
Geoff Hayes 2014년 8월 25일
Glad to have been able to help, Nikolaos!

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

추가 답변 (1개)

Srimathy K SOC IT
Srimathy K SOC IT 2019년 3월 26일
sir how to embed secret data in video????
i had used interframe motion prediction
function [motion,pred_err]=inter_cons(im_old,im_new,i,j,N)
for i=1:100
rows=i+N-1;cols=j+N-1;
SAD = 1.0e+10;
for u = -N:N
for v = -N:N
sad = im_new(rows+1:rows+N,cols+1:cols+N)-im_old(rows+u+1:rows+u+N,cols+v+1:cols+v+N); %difference
sad = sum(abs(sad(:)));
if sad < SAD
SAD=sad;
x= v; y = u;
end
end
end
motion=[x y];
pred_im(1:N,1:N)=im_old(rows+y+1:rows+y+N,cols+x+1:cols+x+N);
pred_err(1:N,1:N) = im_new(rows:rows+N-1,cols:cols+N-1)-pred_im(1:N,1:N);
end
end
but the code only giving result for first frame in 8*8 matrix
i need your help sir
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2019년 3월 26일
Srimathy - please post this a new question rather than as an answer to this one.

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

Community Treasure Hunt

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

Start Hunting!

Translated by