Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: MP3 repacker (Read 586523 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

MP3 repacker

What it does:
Attempts to save space by storing frame data in the smallest possible frame. Usually MP3s are already stored in the most efficient way possible. However, for high-bitrate CBR files (like --preset insane) there can be a lot of wasted space

psyllium has made a great Windows GUI for this program. The GUI thread is here. Many people will find it easier to use than the CLI, and it has a few more features too (recursive directory support, 2-pass CBR).

How to use:
Download this 7Z file (version 2.04) (mirror)
Extract to a directory that makes sense.
Type "mp3packer in.mp3 out.mp3" to repack the in.mp3 file
OR see mp3packer.html included in the package (or available here) for more options.
The source can be downloaded here (mirror).

Features:
* Can make --preset insane files up to 10% smaller LOSSLESSLY (depending on the LAME version used)
* Squeezes out all the padding it can from any MP3 (Will not produce a larger file, unless you use the -b switch or something goes wrong)
* Writes valid LAME/XING header for proper VBR seeking
* Many people also use this backwards, to losslessly turn VBR into larger CBR files to humor players which can't handle VBR
* Includes a brute-force compression optimization option as of 1.10 to further compress files
* Now supports Unicode file names and paths
* Support for encoding an entire directory of files
* Works on Windows, Linux, 64-bit Linux, Linux through WINE, and should work perfectly on any other platform with an OCaml port
* GPL, so anybody can tweak it as long as it stays GPL

A few caveats:
* The program will always output an MP3 that doesn't use CRCs, even if the input file uses CRC. This is primarily laziness on my part, but nobody really needs them, and it saves 600 bits per second... (it's a feature, not a bug!)
* The 32-bit version will not process files larger than 1GB. The 64-bit version has a much higher limitation (4EB) which is unlikely to be encountered.
* There seems to be an incompatibility with the multi-threaded repacking code and 32-bit Windows XP. If you run across an error, try adding "--workers 0" to the command line.

Changelog (click here!)
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

MP3 repacker

Reply #1
what about gapless playback? Will anything in the headers which is required for gapless playback be damaged?

- Lyx
I am arrogant and I can afford it because I deliver.

MP3 repacker

Reply #2
Quote
what about gapless playback? Will anything in the headers which is required for gapless playback be damaged?

- Lyx
[a href="index.php?act=findpost&pid=282291"][{POST_SNAPBACK}][/a]

Nope. Gapless settings are in the LAME tag, which is saved to the new file. The only LAME tag settings which I change are the ones that actually change (file length, etc.) Everything else is saved.
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

MP3 repacker

Reply #3
that's some pretty pimp stuff...does it handle files other than LAME as well?
--alt-presets are there for a reason! These other switches DO NOT work better than it, trust me on this.
LAME + Joint Stereo doesn't destroy 'Stereo'

MP3 repacker

Reply #4
Quote
that's some pretty pimp stuff...does it handle files other than LAME as well?
[a href="index.php?act=findpost&pid=282468"][{POST_SNAPBACK}][/a]

Yup. If it's an MP3, it's supported. LAME is just extra-supported as the program handles LAME/XING headers properly.

I just noticed that MPEG2 and 2.5 files are having some sort of problem. I'll see if I can fix it sometime today. [Edit: MPEG2 / 2.5 files are working correctly as of version 0.02.]
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

MP3 repacker

Reply #5
Sounds pretty cool. I wouldn't have thought there'd be that much to squeeze out (I don't know much about mp3's), but if it works as well as you say it does (I'm'a have to see for my self ) and it doesn't damage playability I'm betting this will become quite the popular little app.

Thank you for all your hard work .

MP3 repacker

Reply #6
So, basically this program turns a CBR file into a VBR file, correct? Pointing newbies who don't understand/trust VBR might be interested in reading this!

MP3 repacker

Reply #7
Seems to work fine.
I just tested it on some random MP3 files and it shaved of a few kb of everyone of them.

MP3 repacker

Reply #8
Quote
Sounds pretty cool. I wouldn't have thought there'd be that much to squeeze out (I don't know much about mp3's), but if it works as well as you say it does (I'm'a have to see for my self ) and it doesn't damage playability I'm betting this will become quite the popular little app.

Thank you for all your hard work .
[a href="index.php?act=findpost&pid=282493"][{POST_SNAPBACK}][/a]

Well, most of the time there isn't anything to squeeze out. But on some files, most notably high-bitrate CBR files, there can be quite a bit of dead space.

@solaris:
Do you know which encoder/settings were used for your test files?
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

MP3 repacker

Reply #9
Quote
So, basically this program turns a CBR file into a VBR file, correct? Pointing newbies who don't understand/trust VBR might be interested in reading this!
[a href="index.php?act=findpost&pid=282495"][{POST_SNAPBACK}][/a]

Yes, although it would be slightly more accurate to say that it turns any MP3 into a VBR file.

... actually, there's still a possibility that the resultant file is CBR, but that's extremely unlikely. It would indicate that the input file didn't use the bit reservoir, which is quite bad for an encoder to do.

Hmm... I guess the most accurate way to characterize the program is:
* At every frame, it picks the smallest frame size which can hold all the data
or perhaps simply:
* In the resultant file, dependancy on the bit reservoir is minimized

Although both of these definitions can be invalidated if you use some of the command line options. It looks like my little Perl script is pretty hard to define
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

MP3 repacker

Reply #10
Binary, anyone?
Infrasonic Quartet + Sennheiser HD650 + Microlab Solo 2 mk3. 

MP3 repacker

Reply #11
Quote
Binary, anyone?

Perl = script language = no binaries.

Someone who knows both perl and something like C can translate, but bla why bother. Here is the perl to get for windows. Install it, and then:
Run "perl mp3packer.pl in.mp3 out.mp3" to repack OR run "perl mp3packer.pl -h" to see other options

MP3 repacker

Reply #12
Quote
Quote
Binary, anyone?

Perl = script language = no binaries.

Someone who knows both perl and something like C can translate, but bla why bother. Here is the perl to get for windows. Install it, and then:
Run "perl mp3packer.pl in.mp3 out.mp3" to repack OR run "perl mp3packer.pl -h" to see other options
[a href="index.php?act=findpost&pid=282556"][{POST_SNAPBACK}][/a]


Well, you could use perlcc. Won't be as easy in this case because of the module that needs to be included. So you'd need to build the shared library first.
Code: [Select]
perlcc -o mp3packer.so mp3.pm

Then convert the mp3packer.pl to C
Code: [Select]
perlcc -c mp3packer.pl

Then you can use gcc to compile the C code and statically link the library into it.
Code: [Select]
gcc mp3packer.C -O2 -o mp3packer -static -lmp3packer.so

I think... I'm a bit rusty 

Not sure if this would even result in usable output either.

MP3 repacker

Reply #13
Quote
@solaris:
Do you know which encoder/settings were used for your test files?
[a href="index.php?act=findpost&pid=282513"][{POST_SNAPBACK}][/a]

They are lame --alt-preset standard. But there are some times since I encoded them, so I`m a bit unsure what lame version I used (probably 3.90.2/3 and/or 3.96.1).
I have no cbr files to test it on.

MP3 repacker

Reply #14
Code: [Select]
C:\Files\progs\Lame stuff\mp3packer>perl mp3packer.pl 1.mp3 2.mp3
Constant name 'HASH(0x1832adc)' has invalid characters at mp3.pm line 16
BEGIN failed--compilation aborted at mp3.pm line 19.
Compilation failed in require at mp3packer.pl line 25.

C:\Files\progs\Lame stuff\mp3packer>perl mp3packer.pl -h
Constant name 'HASH(0x1832ae0)' has invalid characters at mp3.pm line 16
BEGIN failed--compilation aborted at mp3.pm line 19.
Compilation failed in require at mp3packer.pl line 25.

C:\Files\progs\Lame stuff\mp3packer>

Wtf.
I'm using ActivePerl as recommended by Klyith, what am I doing wrong?
Infrasonic Quartet + Sennheiser HD650 + Microlab Solo 2 mk3. 

MP3 repacker

Reply #15
couldn't this funktion be put into lame ? some thing like -repack
Sven Bent - Denmark

MP3 repacker

Reply #16
just tried this. Saved a couple of bytes.
However the output is NOT the same

I used winamp diskwrite plugin.
Ran crc32 and md5 check on the files and they did not match,
also the size of the 2 decoded wavs where not identical either.

and id3v2 tags are removed from the file.
Sven Bent - Denmark

MP3 repacker

Reply #17
The way I'd describe the output of the songs I tried this with is almost constand 320k stream with the occasional flicker which is a 256k frame.  Still pretty fun to play around with.
Nero AAC 1.5.1.0: -q0.45

MP3 repacker

Reply #18
@Omion
Thanks for the great tool!


Quote
I used winamp diskwrite plugin.
Ran crc32 and md5 check on the files and they did not match,
also the size of the 2 decoded wavs where not identical either.

Is the wav from mp3packer shorter than the original? If so, it might be related to the last frame of the mp3 being truncated because of the removal of padding.
(just speculating, haven't tested mp3packer for myself, yet)

Omion, any idea?


Quote
and id3v2 tags are removed from the file.

Which saves another few bytes! Great feature for a packer, isn't it?

MP3 repacker

Reply #19
Quote
just tried this. Saved a couple of bytes.
However the output is NOT the same

I used winamp diskwrite plugin.
Ran crc32 and md5 check on the files and they did not match,
also the size of the 2 decoded wavs where not identical either.

and id3v2 tags are removed from the file.
[a href="index.php?act=findpost&pid=283214"][{POST_SNAPBACK}][/a]

If you were using LAME-encoded MP3s, did you use a gapless decoder?

MP3 repacker

Reply #20
Quote
@Omion
Thanks for the great tool!


Quote
I used winamp diskwrite plugin.
Ran crc32 and md5 check on the files and they did not match,
also the size of the 2 decoded wavs where not identical either.

Is the wav from mp3packer shorter than the original? If so, it might be related to the last frame of the mp3 being truncated because of the removal of padding.
(just speculating, haven't tested mp3packer for myself, yet)
Omion, any idea?
Quote
and id3v2 tags are removed from the file.

Which saves another few bytes! Great feature for a packer, isn't it?
[a href="index.php?act=findpost&pid=283218"][{POST_SNAPBACK}][/a]

The file should have the exact same number of frames, with the same data in them, and the same gapless settings. If they're not, either the program's wrong or the decoder's not producing identical output. This may be the case if the decoder is using dithering, which will add random (not reproducible) noise.

@ sven_Bent:
If you have Foobar, run the "bit-compare tracks" function on the two files. If you don't have Foobar, then could you run the SAME mp3 through the Winamp diskwriter plugin twice, and see if they match up. (If they don't, then your output is dithering)

About the ID3V2 tags, the repacker doesn't save anything before the first valid MP3 frame. It only saves the non-MP3 data after the end. This means that some versions of the ID3v2 tag will not be stored. (I think 2.4 is stored at the end... ID3 tags are a mess...  )
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

MP3 repacker

Reply #21
Quote
Code: [Select]
C:\Files\progs\Lame stuff\mp3packer>perl mp3packer.pl 1.mp3 2.mp3
Constant name 'HASH(0x1832adc)' has invalid characters at mp3.pm line 16
BEGIN failed--compilation aborted at mp3.pm line 19.
Compilation failed in require at mp3packer.pl line 25.

C:\Files\progs\Lame stuff\mp3packer>perl mp3packer.pl -h
Constant name 'HASH(0x1832ae0)' has invalid characters at mp3.pm line 16
BEGIN failed--compilation aborted at mp3.pm line 19.
Compilation failed in require at mp3packer.pl line 25.

C:\Files\progs\Lame stuff\mp3packer>

Wtf.
I'm using ActivePerl as recommended by Klyith, what am I doing wrong?
[a href="index.php?act=findpost&pid=283209"][{POST_SNAPBACK}][/a]

What version of Perl are you using? Run "perl -v" and it should say something like "This is perl, v5.8.5 built for MSWin32-x86-multi-thread"

Line 16 is where the first constant is defined.
Try saving and running the following:
Code: [Select]
use constant {
    FOO => 'something',
    BAR => 3,
    BAZ => [1,2,3],
};
print "FOO: ", FOO, "\nBAR: ", BAR, "\nBAZ: ", BAZ, "\n";


The result should be something like:
Code: [Select]
FOO: something
BAR: 3
BAZ: ARRAY(0x182bc58)
(The array might have a different value)

If that doesn't run, then it looks like your "constant" library is screwed up... If it does run, then I'll have to try it out with ActivePerl, and see why my it doesn't like mp3packer.

I'm going to my parent's house tomorrow for a week, so I might not be as responsive as I should be, but I'll work on this as soon as I get things set up there.
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

MP3 repacker

Reply #22
@ominion

i dont have fobar her
but i did two diskwrites of the same mp3 as before (the original and not the repackwd)
and they came out bit identical

MD5
b526274595bd1b40fa744673c8b25f08 *first.wav
b526274595bd1b40fa744673c8b25f08 *Second.wav

CRC32
first.wav 75FDC377
Second.wav 75FDC377

So it definatly seems like the repack stuff is NOT lossless to the decoded stream
Sven Bent - Denmark

MP3 repacker

Reply #23
edit: nevermind - i misunderstood something.
I am arrogant and I can afford it because I deliver.

MP3 repacker

Reply #24
Quote
Code: [Select]
C:\Files\progs\Lame stuff\mp3packer>perl mp3packer.pl 1.mp3 2.mp3
Constant name 'HASH(0x1832adc)' has invalid characters at mp3.pm line 16
BEGIN failed--compilation aborted at mp3.pm line 19.
Compilation failed in require at mp3packer.pl line 25.

C:\Files\progs\Lame stuff\mp3packer>perl mp3packer.pl -h
Constant name 'HASH(0x1832ae0)' has invalid characters at mp3.pm line 16
BEGIN failed--compilation aborted at mp3.pm line 19.
Compilation failed in require at mp3packer.pl line 25.

C:\Files\progs\Lame stuff\mp3packer>

Wtf.
I'm using ActivePerl as recommended by Klyith, what am I doing wrong?
[a href="index.php?act=findpost&pid=283209"][{POST_SNAPBACK}][/a]

I think I know the problem. Some versions of Perl don't allow multiple constants to be defined at the same time. It should be fairly easy to fix... I'll do it as soon as I can. [Edit: Should be fixed now. Download version 0.02 and try it out.]
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2