how can i read all the frames/images from a .rec file?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nikolaos
am 13 Aug. 2014
Kommentiert: Geoff Hayes
am 26 Mär. 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
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 13 Aug. 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 Kommentare
Weitere Antworten (1)
Srimathy K SOC IT
am 26 Mär. 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 Kommentar
Geoff Hayes
am 26 Mär. 2019
Srimathy - please post this a new question rather than as an answer to this one.
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!