Saturday, August 9, 2008

Setting up Ogg Vorbis Coding for MP2 Audio Files

Today on Radio New Zealand National, Kim Hill interviewed Richard Stallman on the Saturday Morning programme. Prior to the interview Richard requested that the audio be made available in Ogg Vorbis format, in addition to whatever other formats we use.

At the moment our publishing system generates audio in Windows Media and MP3 formats, so I had two options: generate the Ogg files by hand on the day, or add an Ogg Vorbis module to do it automatically.

Since the publishing system is based on free software (Perl), it was a simple matter to add a new function to our existing custom transcoder module. It also avoided the task of manually coding and uploading each file. Here is the function:

sub VORBIS()
{
my( $self ) = shift;
my( $type ) = TR_256;

my $inputFile = $self->{'inputFile'};
my $basename = $self->{'basename'};
my $path = $self->{'outputPath'};
my $ext = '.ogg';

my $output_file = "$path\\$basename$ext";

my $lame_decoding_params = " --mp2input --decode $inputFile - ";
my $ogg_encoding_params = qq{ - --bitrate 128 --downmix --quality 2 --title="$self->{'title'}" --artist="Radio New Zealand" --output="$output_file" };

my $command = "lame $lame_decoding_params | oggenc2 $ogg_encoding_params";

print "$command \n" if ($self->{'debug'});
my $R = $rates{$type};
&RunJob( $self, $command, "m$rates{$type}" );

# we must return a code so the caller knows what to do
return 1;
}
All the Ogg parameters are hard-coded at this stage, and I'll add code to allow for different rates later, once I have done some tests to see what works best for our purposes.

Once this code was in place, the only other change was to update the master programme data file to switch on the new format.

After that, any audio published to the Saturday programme would automatically get the new file format, and this would also be uploaded to our servers.

The system was originally built with this in mind - add a new type, update the programme data, done - but this is the first time I have used it.

You can see the result on today's Saturday page.

2 comments:

Anonymous said...

Thanks Richard for making an open format available.

I'd prefer if those thanks weren't directed to Richard Stallman, if Radio NZ had made OGG available under its own initiative as one might have expected based on the material in the "Why are you using proprietary formats?" section of the audio help.

The irony that RNZ avails itself of open software, then justifies the use of proprietary formats as a "public broadcaster" is worth considering.

Anonymous said...

Steady on, Hamish!

Do you not think you are being a little churlish here? Clearly RNZ had all this stuff ready to go, and good on them (and Richard Hulse). So they chose to implement it during a visit from Stallman. What better time?

Let's those of us who support free software and open formats build people up when they do the right thing, not grouse about it. We will get more results that way, not to mention making the 'free world' a more pleasant place.

Colin