Video to Binary data
이전 댓글 표시
I want to convert video (including images and audio) to binary data for some processing can anyone suggest best method for the same.
답변 (3개)
Walter Roberson
2020년 1월 3일
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
Mostafa Taleb
2021년 8월 2일
Sir how can I return the the video to it original shape, and play it ?
Mostafa Taleb
2021년 8월 2일
편집: Mostafa Taleb
2021년 8월 2일
I mean the vice versa for your code above , thanks in advance, your comments really help .
Walter Roberson
2021년 8월 2일
bytestream = reshape(uint8(bin2dec(reshape(char(bitstream+'0'),8,[]).')),1,[]);
bytestream is now uint8 and should have the same contents as the bytes variables did.
You cannot play this directly, as it represents a file. You need to write it to a new file on the other end and play the file.
This is really only suitable for the case where you have to transmit the entire file to a remote system. It is not what you would use to do transformations such as doing filtering on the audio or doing object detection in the video.
Baghdadi Aya
2021년 11월 16일
And how can I display the video from this bytestream ?
bytestream = reshape(uint8(bin2dec(reshape(char(bitstream+'0'),8,[]).')),1,[]);
Walter Roberson
2021년 11월 17일
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.
Image Analyst
2020년 1월 3일
0 개 추천
I don't think MATLAB can extract or write out audio data to or from video files.
댓글 수: 5
Walter Roberson
2020년 1월 3일
Computer Vision Toolbox can read and write audio in video files.
Image Analyst
2020년 8월 6일
What functions are those that do that?
Image Analyst
2020년 8월 6일
It looks like it requires Simulink? Does it? I don't have Simulink.
Walter Roberson
2020년 8월 7일
No, those are just Computer Vision toolbox being used in MATLAB. The Simulink blocks are
AFIF GUERFI
2020년 8월 6일
0 개 추천
file bitstream is not read?
댓글 수: 1
Walter Roberson
2020년 8월 6일
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.
카테고리
도움말 센터 및 File Exchange에서 Video Formats and Interfaces에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!