Video to Binary data

19 vues (au cours des 30 derniers jours)
mayank jain
mayank jain le 3 Jan 2020
Commenté : Walter Roberson le 17 Nov 2021
I want to convert video (including images and audio) to binary data for some processing can anyone suggest best method for the same.

Réponses (3)

Walter Roberson
Walter Roberson le 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.
  5 commentaires
Baghdadi Aya
Baghdadi Aya le 16 Nov 2021
And how can I display the video from this bytestream ?
bytestream = reshape(uint8(bin2dec(reshape(char(bitstream+'0'),8,[]).')),1,[]);
Walter Roberson
Walter Roberson le 17 Nov 2021
As I wrote above, you would have to write the stream of bytes to a file, and then read it from the file.
Note that this code is for sending over the entire file, including any audio, and any video and any copyright information, and Closed Captions For The Hearing Impaired, and everything in the file.
The code to send only video is different.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 3 Jan 2020
I don't think MATLAB can extract or write out audio data to or from video files.
  5 commentaires
Image Analyst
Image Analyst le 6 Août 2020
It looks like it requires Simulink? Does it? I don't have Simulink.
Walter Roberson
Walter Roberson le 7 Août 2020
No, those are just Computer Vision toolbox being used in MATLAB. The Simulink blocks are

Connectez-vous pour commenter.


AFIF GUERFI
AFIF GUERFI le 6 Août 2020
file bitstream is not read?
  1 commentaire
Walter Roberson
Walter Roberson le 6 Août 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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by