[Flac] FLAC to Vorbis
Aaron Whitehouse
lists at whitehouse.org.nz
Wed Aug 10 03:52:32 PDT 2005
Wow.
I am amazed and impressed by the speed and extent of the help from
everybody. Definitely exceeded my expectations for free support.
I will email you off the list, Dan, to ask you more about making sure
that I am running the script properly :).
Thanks again,
Aaron
Dax Kelson wrote:
> On Wed, 2005-08-10 at 14:07 +1200, Aaron Whitehouse wrote:
>
>>Hello everyone,
>>
>>I am running Ubuntu and have converted my CDs to FLACs (using all the
>>paranoia and fixing all the tags etc.). What is the best way for me to
>>convert all of those FLAC to ogg-Vorbis files, keeping all the tag
>>information and the same directory structure?
>
>
> The tagging part is easy with modern version of oggenc. Also, oggenc can
> read flac as an input file.
>
> So the following will work, and preserve the tags:
>
> oggenc -q 5 -o /tmp/cool-song.ogg /tmp/cool-song.flac
>
> Neat eh?
>
> About preserving the directory structure and allowing incremental runs
> that only encode new flacs (or re-encode modified flacs) I found a
> script on the net "flac2ogg.pl" that does what you want. It was written
> for a windows cygwin environment but I modified to work on a native
> UNIX/Linux system. Some of the perl is pretty ugly (like calling
> external programs to do what perl can do natively), but hey it works.
>
> Here it is:
>
> #!/usr/bin/perl
> #
> # Copyright (c) 2004 - Jason L. Buberel - jason at buberel.org
> # Licensed under the GNU GPL.
> #
> # Modified by Dax Kelson to run on a native UNIX/Linux box.
>
> use Getopt::Long;
> use File::stat;
>
> $sourceDirPrefix = "/export/media/music/flacs";
> $destDirPrefix = "/export/media/music/oggs";
> $quality = 5;
> GetOptions ( "source:s" => \$sourceDirPrefix,
> "dest:s" => \$destDirPrefix,
> "quality:i" => \$quality,
> "force" => \$force );
>
> # Commands
> $oggCommand = "oggenc";
> $flacCommand = "flac";
>
> @dirs = `cd "$sourceDirPrefix" && find . -type d -print`;
> @files = `cd "$sourceDirPrefix" && find . -type f -name "*.flac" -print`;
>
> # Check to see if our find command found anything to convert.
> if ( scalar @files == 0 ) {
> die "Found no .flac files to convert!";
> }
>
> # recreate the directory hierarchy
> foreach $dir (@dirs) {
> $dir =~ s/\n$//;
> $dir =~ s/^\.\///;
>
> # check to see if the destination dir already exists
> if ( !(stat ("$destDirPrefix/$dir")) ) {
> # stat failed so create the directory
> print "Creating output dir:\n $destDirPrefix/$dir\n";
> $dir =~ s/\`/\'/g;
> $result = `cd "$destDirPrefix" && mkdir -p "$dir"`;
> }
>
>
> }
>
> # now process the actual sound files.
> foreach $file (@files) {
> $file =~ s/\n$//;
> $file =~ s/^\.\///;
>
> # figure out what the destination file would be...
> $destinationFile = $file;
> $destinationFile =~ s/\.flac*/\.ogg/;
>
> # now stat the destinationFile, and see if it's date is more recent
> # than that of the original file. If so, we re-encode.
> # we also re-encode if the user supplied --force
> $srcInfo = stat ("$sourceDirPrefix/$file");
> $srcModTime = $srcInfo->mtime;
> $destInfo = stat ("$destDirPrefix/$destinationFile");
> if ( $destInfo ) {
> $destModTime = $destInfo->mtime;
> print "Skipping current file: $destDirPrefix/$destinationFile\n";
> }
> # if the destination file does not exist, or the user specified force,
> # or the srcfile is more recent then the dest file, we encode.
> if ( !$destInfo || $force || ( $srcModTime > $destModTime) ) {
> $file =~ s/\`/\'/g;
> $inFile = "$sourceDirPrefix/$file";
> $outFile = "$destDirPrefix/$destinationFile";
> $inFile =~ s/\0//g; $outFile =~ s/\0//g;
> $result = `$oggCommand -q $quality -o "$outFile" "$inFile"`;
> }
>
> }
>
>
More information about the Flac
mailing list