MATLAB Answers

Video to Binary data

38 views (last 30 days)
mayank jain
mayank jain on 3 Jan 2020
Commented: Walter Roberson on 7 Aug 2020
I want to convert video (including images and audio) to binary data for some processing can anyone suggest best method for the same.

  0 Comments

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 3 Jan 2020
filename = 'YourFile.avi';
[fid, msg] = fopen(filename, 'r'); %not 'rt' !
if fid < 0
error('Failed to open file "%s" because "%s"', filename, msg);
end
bytes = fread(fid, [1 inf], '*uint8');
fclose(fid);
bitstream = reshape(logical(dec2bin(bytes, 8) - '0').', 1, []);
bytes is now a vector of uint8 containing the file -- the entire file, including all audio and video and EXIF and so on.
bitstream is now a vector of false (0) and true (1) values, giving the bytes in MSB-first order.

  0 Comments

Sign in to comment.


Image Analyst
Image Analyst on 3 Jan 2020
I don't think MATLAB can extract or write out audio data to or from video files.

  5 Comments

Show 2 older comments
Image Analyst
Image Analyst on 6 Aug 2020
It looks like it requires Simulink? Does it? I don't have Simulink.

Sign in to comment.


AFIF GUERFI
AFIF GUERFI on 6 Aug 2020
file bitstream is not read?

  1 Comment

Walter Roberson
Walter Roberson on 6 Aug 2020
In the code I posted, the Avi file itself is converted to binary and the stream of bits is stored in the variable bitstream . The bitstream variable is the intended output of the section of code.
Note that the code I posted does not extract the frames or audio from the Avi as images or audio: it deals with the file as a whole, including whatever headers and metadata it might have. The code I posted does not care that the file is a valid Avi file, it only treats it as a chunk of bytes.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by