How to convert an mp3 file into binary and its reverse

20 views (last 30 days)
How to convert an mp3 file into binary and its reverse
  2 Comments
ola lawson
ola lawson on 16 Apr 2017
Would it be possible to explain the reverse method, finding it difficult to convert it back into mp3 file
Walter Roberson
Walter Roberson on 16 Apr 2017
fid = fopen('OutputFile.mp3', 'w');
fwrite(fid, TheVectorOfUint8);
fclose(fid);

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 15 Mar 2016
mp3_content = uint8( fileread('YourFile.mp3') );
The exact contents of the file are now a series of 8 bit unsigned integers, which you can process as usual, such as with dec2bin().
In the reverse side, once you have a vector of 8 bit unsigned integers,
fid = fopen('OutputFile.mp3', 'w');
fwrite(fid, TheVectorOfUint8);
fclose(fid);
and now OutputFile.mp3 will be the same contents as the original .mp3 file.
  2 Comments
P Harika
P Harika on 26 Jan 2017
But the file "OutputFile.mp3" is different from the Original File
Walter Roberson
Walter Roberson on 26 Jan 2017
fid = fopen('YourFile.mp3', 'r');
mp3_content = fread(fid, [1 inf], '*uint8');
fclose(fid);
fid = fopen('OutputFile.mp3', 'w');
fwrite(fid, TheVectorOfUint8);
fclose(fid);
The two files should be the same.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!