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

4 visualizaciones (últimos 30 días)
Nikolaos
Nikolaos el 13 de Ag. de 2014
Comentada: Geoff Hayes el 26 de Mzo. de 2019
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

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 13 de Ag. de 2014
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 comentarios
Nikolaos
Nikolaos el 24 de Ag. de 2014
Editada: Nikolaos el 24 de Ag. de 2014
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 el 25 de Ag. de 2014
Glad to have been able to help, Nikolaos!

Iniciar sesión para comentar.

Más respuestas (1)

Srimathy K SOC IT
Srimathy K SOC IT el 26 de Mzo. de 2019
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 comentario
Geoff Hayes
Geoff Hayes el 26 de Mzo. de 2019
Srimathy - please post this a new question rather than as an answer to this one.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by