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;

Answers


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.

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

You also have to get rid of the first line.

Now if you have your data in the following form:

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.


Need Your Help

Downloading Ruby Error

ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

I typed this into the terminal: rvm install 1.9.3 and I got this error in return:

Android Word-Wrap EditText text

android xml word wrap android-edittext

I have been trying to get my EditText box to word wrap, but can't seem to do it.