From d87c2e151f484b6b6a4a074f16c80d4b92398fb0 Mon Sep 17 00:00:00 2001
From: Shevek <shevek@shevek.co.uk>
Date: Tue, 26 Jul 2011 11:03:46 +0100
Subject: [PATCH] Add MP3 VBR Encoding Option

--mp3vbr=n

Adds an option to specify the AQ (VBR) setting when encoding to MP3. Options are 0 to 9 which map (roughly) to the LAME -V settings (http://wiki.hydrogenaudio.org/index.php?title=LAME#VBR_.28variable_bitrate.29_settings)

Signed-off-by: Shevek <shevek@shevek.co.uk>
---
 get_iplayer |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/get_iplayer b/get_iplayer
index daf47e4..5f7fc7c 100755
--- a/get_iplayer
+++ b/get_iplayer
@@ -140,6 +140,7 @@ my $opt_format = {
 	thumb		=> [ 1, "thumb|thumbnail!", 'Recording', '--thumb', "Download Thumbnail image if available"],
 	thumbonly	=> [ 1, "thumbonly|thumbnailonly|thumbnail-only|thumb-only!", 'Recording', '--thumbnail-only', "Only Download Thumbnail image if available, not the programme"],
 	aactomp3	=> [ 1, "aactomp3", 'Recording', '--aactomp3', "Transcode aac audio to mp3 with ffmpeg"],
+	mp3vbr		=> [ 1, "mp3vbr=n", 'Recording', '--mp3vbr', "Set LAME VBR mode to N (0 to 9). 0 = target bitrate 245 Kbit/s, 9 = target bitrate 65 Kbit/s"],
 
 	# Search
 	before		=> [ 1, "before=n", 'Search', '--before', "Limit search to programmes added to the cache before N hours ago"],
@@ -6860,6 +6861,9 @@ sub download {
 	# Override ext based on mkv option
 	$prog->{ext} = 'mkv' if ! $opt->{raw} && $opt->{mkv} && $prog->{type} eq 'tv';
 
+	# Get the VBR LAME Mode, set to -1 if not set
+	$prog->{mp3vbr} = $opt->{mp3vbr} || -1;
+
 	# Determine the correct filenames for this recording
 	if ( $prog->generate_filenames( $ua, $prog->file_prefix_format() ) ) {
 		return 'skip';
@@ -8092,15 +8096,25 @@ sub get {
 		);
 	# Convert flv to aac/mp4a/mp3
 	} elsif ( $mode =~ /flashaac/ ) {
-		# transcode to MP3 if directed
+		# transcode to MP3 if directed. If mp3vbr is not set then perform CBR.
 		if ( $opt->{aactomp3} ) {
-			@cmd = (
-				$bin->{ffmpeg},
-				'-i', $file_tmp,
-				'-vn',
-				'-acodec', 'libmp3lame', '-ac', '2', '-ab', '128k',
-				'-y', $prog->{filepart},
-			);
+			if ( $prog->{mp3vbr} == -1 ) {
+				@cmd = (
+					$bin->{ffmpeg},
+					'-i', $file_tmp,
+					'-vn',
+					'-acodec', 'libmp3lame', '-ac', '2', '-ab', '128k',
+					'-y', $prog->{filepart},
+				);
+			} else {
+				@cmd = (
+					$bin->{ffmpeg},
+					'-i', $file_tmp,
+					'-vn',
+					'-acodec', 'libmp3lame', '-ac', '2', '-aq', $prog->{mp3vbr},
+					'-y', $prog->{filepart},
+				);
+			}
 		} else {
 			@cmd = (
 				$bin->{ffmpeg},
-- 
1.7.3.1.msysgit.0

