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

11 ビュー (過去 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