Safi Mustafa
Safi Mustafa

Reputation: 517

Read Hex bits from encoded file and show it as an image

I am using JM reference software for encoding and decoding of video. What I want to do is to encode a video and then read it as hex file into matlab. Afterwards I want to show each frame as an image.

I know that each frame starts with "00 00 00 01" So what I have done is that I have found all indexes where this "00 00 00 01" string is located and then I read from one index to another convert it into an matrix and show it as an Image but image is empty.

Here is my code:

hexFileName = 'C:\Users\Safi\Desktop\Encoded.txt';
videoHexArray = importdata(hexFileName);
strFrameIndex = strfind(videoHexArray, '00 00 00 01');
%disp(videoHexArray);
videoHexString = char(videoHexArray);
OneFrame=videoHexString(76:6821);
disp(OneFrame);
imshow(str2num(OneFrame));
figure;

Upvotes: 0

Views: 849

Answers (1)

NKN
NKN

Reputation: 6424

If your input data looks like below, you need to get rid of line numbers and the raw data. Obviously you are reading this from a debugger or hexit software.

enter image description here

You can do this in MATLAB. Open the data using import data gui and select the important vectors:

enter image description here

You also have to get rid of the first line.

Now if you have your data in the following form:

enter image description here

in a txt file, you can read the hex values using textread function and proceed as follows:

 M=textread('test3.txt','%2c');
A = zeros(847,16);
 kk = 1;
for ii = 1:847
    for jj = 1:16
        A(ii,jj) = hex2dec(M(kk:kk+1));
        kk = kk + 1;
    end
end

imshow(A)

Because the output decimal data is already in range [0,255] you do not need to normalize. However you need to now how the data is structured. In the other words what is the size of the frame. For now it is 874x16 which obviously is not the right frame-size. To convert to a correct frame-size, you might use reshape function on the matrix A.

Upvotes: 1

Related Questions