| author | plurSKI <black.gavin@gmail.com> | 2010-10-16 17:15:54 (GMT) |
|---|---|---|
| committer | plurSKI <black.gavin@gmail.com> | 2010-10-16 17:15:54 (GMT) |
| commit | 31b92d0b8b097e2037bfdfc520fa92c5a2c7e1dc (patch) | |
| tree | 29b67c4d6670a880e75d4aae3b3e2357e0fe768b | |
| download | mp3Split-master.zip mp3Split-master.tar.gz | |
Initial Commitmaster
| -rw-r--r-- | README | 9 | ||||
| -rw-r--r-- | mp3B.c | 66 | ||||
| -rw-r--r-- | mp3Split.pl | 55 |
3 files changed, 130 insertions, 0 deletions
@@ -0,0 +1,9 @@ +Dependencies: + perl -MCPAN -e 'install MP3::Info' + +Usage: + mp3Split.pl fileName partLength [length_mins] [length_secs] + + +mp3B.c: + Somewhat working C version, feel free to ignore it @@ -0,0 +1,66 @@ +#include<stdio.h> +#include<stdlib.h> +#include<string.h> + +/* Constants */ +#define WRITE_SIZE 1028 +#define KB_SIZE 1024 +#define MAGIC_NUM 76 +#define FRAME_CONST 144 + +int main(int argc, char** argv) +{ + int i; + int minutes=0; + int mpegType=0; + int kilobytes=0; + int rateIndex=0; + int frameSize=0; + int pass=1; + char buffer[WRITE_SIZE]; + char header[4]; + FILE* f=fopen(argv[1],"r"); + FILE* fOut; + char outFilename[strlen(argv[1]) + 3]; + size_t readSize; + /* Table of bitrate constants associated with mp3s */ + int bitrate[2][16] = { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0, + 0, 8, 16, 24, 32, 64, 80, 56, 64, 128, 160, 112, 128, 256, 320, 0 }; + + minutes = atoi(argv[2]); + printf("argc) %d argv) %s argv) %s\n", argc, argv[1], argv[2]); + fread(header, 3, 1, f); + if(header[1] != -5) mpegType=1; + + rateIndex = header[2] >> 4 & 0x0F; + + kilobytes=bitrate[mpegType][rateIndex]*6*minutes; + if(mpegType) frameSize=FRAME_CONST*bitrate[mpegType][rateIndex]*KB_SIZE/22050; + else frameSize=FRAME_CONST*bitrate[mpegType][rateIndex]*KB_SIZE/44100; + kilobytes = frameSize*(kilobytes*KB_SIZE/ (frameSize - MAGIC_NUM))/KB_SIZE; + if(argc > 5) + { + printf("%X(%u) %x(%u) %x(%u) %x(%u)\n", header[0], header[0], header[1],header[1], header[2],header[2], header[3], header[3]); + if(mpegType) printf("MPEG Type II\n"); + else printf("MPEG Type I\n"); + printf("%d -- %u\n", bitrate[mpegType][rateIndex], kilobytes*KB_SIZE); + printf("Base Kilobytes %d\n", kilobytes); + printf("frameSize=%d\n", frameSize); + printf("Extra kilos %d\n", kilobytes); + return 0; + } + + do{ + sprintf(outFilename,"%d_%s", pass++, argv[1]); + fOut = fopen(outFilename,"w"); + + for(i=0; i<kilobytes && readSize; i++) + { + readSize = fread(buffer, WRITE_SIZE, 1, f); + if(readSize) fwrite(buffer,WRITE_SIZE, 1, fOut); + } + fclose(fOut); + }while(readSize); + + fclose(f); +} diff --git a/mp3Split.pl b/mp3Split.pl new file mode 100644 index 0000000..a4bd638 --- a/dev/null +++ b/mp3Split.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl -w +use MP3::Info; + +# Find the number of arguments and spit out usage if needed +my $numArgs = $#ARGV + 1; +if ($numArgs < 2 || $numArgs > 4) +{ + printf "Usage: $0 filename part_length [length_mins] [length_secs]\n"; + exit 0; +} + +my $totalParts = 0; +my $fileNum = 1; +my $file = $ARGV[0]; +my $info = get_mp3info($file); + +printf "$file\n"; +printf "Length is %d:%d\n", $info->{MM}, $info->{SS}; +printf "Bitrate %d Frequency %d\n", $info->{BITRATE}, $info->{FREQUENCY}; +printf "Size %d Offset %d\n", $info->{SIZE}, $info->{OFFSET}; +my $part=int $info->{SIZE} * $ARGV[1] / ($info->{MM} + $info->{SS}/60); + +# If the user specified a time, use that instead in case MP3 Info is wrong +if ($numArgs == 3) +{ + $part=int $info->{SIZE} * $ARGV[1] / $ARGV[2]; +} +if ($numArgs == 4) +{ + $part=int $info->{SIZE} * $ARGV[1] / ($ARGV[2] + $ARGV[3]/60); +} +printf "Part Size: %d bytes\n", $part; +$totalParts = int $info->{SIZE} / $part + 1; +printf "Total Parts: %d\n", $totalParts; + +# Open up the original file and break it into parts +$buffer = ""; +open(FILE, "<$file"); +while ( read(FILE, $buffer, $part, 0) ){ + my $partFile; + if($fileNum < 10) + { + $partFile = "0$fileNum\_$file" + } else { + $partFile = "$fileNum\_$file" + } + printf "$partFile: $fileNum / $totalParts\n"; + open(FILEO, ">$partFile"); + print FILEO $buffer; + close(FILEO); + + $fileNum ++; +} + +printf "Done\n" |
