[mythtv] [PATCH] MP3 options for TV recording

David Zanetti dave2 at wetstring.net
Thu Dec 4 17:35:35 EST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Attached patch alters the options for software mp3 encoding on TV recoding
profiles. It's against the current CVS.

Changes:
 - Renames "MP3 Quality" to "Algorithm Quality", reflecting what the
control actually does. Help text updated to suit.
 - Adds CBR/ABR/VBR option
 - Adds bitrate option (for CBR/ABR)
 - Adds quality slider (for VBR)
 - Adds stereo mode (auto, joint stereo, stereo, mono downmix)
 - Removes hardwired compression ratio

Defaults are CBR 128k auto, which seems sane to me. 

- -- 
David Zanetti           |  (__)             
#include <geek/unix.h>  |  ( oo    Mooooooo 
http://hairy.geek.nz/   |  /(_O ./         
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Made with pgp4pine 1.75-6

iD8DBQE/z7a6T21+qRy4P+QRArEKAKCOp279o8pkhAj6g4fi5shLjyA3XQCfXIlj
KL8u7ijRVd2God+fH6wt0h8=
=VRgD
-----END PGP SIGNATURE-----

-------------- next part --------------
diff -ru mythtv-orig/libs/libmythtv/NuppelVideoRecorder.cpp mythtv/libs/libmythtv/NuppelVideoRecorder.cpp
--- mythtv-orig/libs/libmythtv/NuppelVideoRecorder.cpp	2003-12-05 11:05:51.000000000 +1300
+++ mythtv/libs/libmythtv/NuppelVideoRecorder.cpp	2003-12-05 11:02:00.000000000 +1300
@@ -65,6 +65,10 @@
     height_multiplier = 1.0;
 
     mp3quality = 3;
+    mp3bitrate = 128;
+    mp3vbrqual = 4;
+    mp3encodingtype = 0;
+    mp3stereomode = 0;
     gf = NULL;
     rtjc = NULL;
     strm = NULL;   
@@ -256,6 +260,14 @@
         compressaudio = value;
     else if (opt == "mp3quality")
         mp3quality = value;
+    else if (opt == "mp3bitrate")
+        mp3bitrate = value;
+    else if (opt == "mp3vbrqual")
+        mp3vbrqual = value;
+    else if (opt == "mp3stereomode")
+        mp3stereomode = value;
+    else if (opt == "mp3encodingtype")
+        mp3encodingtype = value;
     else if (opt == "samplerate")
         audio_samplerate = value;
     else if (opt == "audioframesize")
@@ -533,12 +545,45 @@
     if (compressaudio)
     {
         gf = lame_init();
-        lame_set_bWriteVbrTag(gf, 0);
-        lame_set_quality(gf, mp3quality);
-        lame_set_compression_ratio(gf, 11);
-        lame_set_mode(gf, audio_channels == 2 ? STEREO : MONO);
-        lame_set_num_channels(gf, audio_channels);
         lame_set_in_samplerate(gf, audio_samplerate);
+        lame_set_num_channels(gf, audio_channels);
+        lame_set_bWriteVbrTag(gf, 0);
+	lame_set_quality(gf, mp3quality);
+        if (audio_channels == 2) {
+               /* only bother setting this for stereo audio, since
+                * lame will automatically use mono when set to one
+                * channel */
+        	switch (mp3stereomode) {
+                  case 0: /* Auto */
+                         /* do nothing */
+                        break;
+                  case 1: /* Joint Stereo */
+                        lame_set_mode(gf,JOINT_STEREO);
+                        break;
+                  case 2: /* Stereo */
+                        lame_set_mode(gf,STEREO);
+                        break;
+                  case 3: /* Mono */
+                        lame_set_mode(gf,MONO);
+                        break;
+        	} 
+        } 
+        switch (mp3encodingtype) {
+          case 0: /* CBR */
+		lame_set_brate(gf,mp3bitrate);
+                lame_set_VBR(gf,vbr_off);
+                break;
+          case 1: /* VBR */
+                lame_set_VBR(gf,vbr_mtrh); /* "New" VBR code */
+                lame_set_VBR_q(gf,mp3vbrqual);
+                break;
+          case 2: /* ABR */
+                lame_set_brate(gf, mp3bitrate);
+                lame_set_VBR(gf,vbr_abr);
+                lame_set_VBR_mean_bitrate_kbps(gf, mp3bitrate);
+                break;
+        }
+
         if((tmp = lame_init_params(gf)) != 0)
         {
             cerr << "lame_init_params error " << tmp << "\n";
diff -ru mythtv-orig/libs/libmythtv/NuppelVideoRecorder.h mythtv/libs/libmythtv/NuppelVideoRecorder.h
--- mythtv-orig/libs/libmythtv/NuppelVideoRecorder.h	2003-12-05 11:05:51.000000000 +1300
+++ mythtv/libs/libmythtv/NuppelVideoRecorder.h	2003-12-05 11:02:25.000000000 +1300
@@ -142,6 +142,10 @@
     CommDetect *commDetect;
 
     int mp3quality;
+    int mp3bitrate;
+    int mp3vbrqual;
+    int mp3stereomode;
+    int mp3encodingtype;
     char *mp3buf;
     int mp3buf_size;
     lame_global_flags *gf;
diff -ru mythtv-orig/libs/libmythtv/recordingprofile.cpp mythtv/libs/libmythtv/recordingprofile.cpp
--- mythtv-orig/libs/libmythtv/recordingprofile.cpp	2003-12-05 11:05:52.000000000 +1300
+++ mythtv/libs/libmythtv/recordingprofile.cpp	2003-12-05 10:55:18.000000000 +1300
@@ -48,15 +48,75 @@
 public:
     MP3Quality(const RecordingProfile& parent):
         CodecParam(parent, "mp3quality"),
-        SliderSetting(1,9,1) {
-        setLabel(QObject::tr("MP3 Quality"));
+        SliderSetting(0,9,1) {
+        setLabel(QObject::tr("Algorithm Quality"));
         setValue(7);
-	setHelpText(QObject::tr("The higher the slider number, the lower the "
-                    "quality of the audio.  Better quality audio (lower "
-                    "numbers) requires more CPU."));
+	setHelpText(QObject::tr("True quality is determined by bitrate, but this will affect quality by selecting expensive or cheap algorithms. Lower numbers are more expensive. Useful range is 2-7. If unsure, select 7."));
     };
 };
 
+class MP3Bitrate: public CodecParam, public ComboBoxSetting {
+public:
+    MP3Bitrate(const RecordingProfile& parent):
+	CodecParam(parent, "mp3bitrate") {
+	setLabel(QObject::tr("Bitrate"));
+
+        addSelection("32 kbps", "32");
+        addSelection("64 kbps", "64");
+        addSelection("96 kbps", "96");
+        addSelection("128 kbps", "128");
+        addSelection("160 kbps", "160");
+        addSelection("192 kbps", "192");
+        addSelection("224 kbps", "224");
+        addSelection("256 kbps", "256");
+        addSelection("288 kbps", "288");
+        addSelection("320 kbps", "320");
+
+        setValue(3);
+        setHelpText("Higher bitrates result in better quality, but at the cost of larger files. In ABR mode, this is the target bitrate. In VBR mode, this is ignored. If unsure, select 128 kbps.");
+    };
+};
+
+class MP3EncodingType: public CodecParam, public ComboBoxSetting {
+public:
+     MP3EncodingType(const RecordingProfile& parent):
+	CodecParam(parent, "mp3encodingtype") {
+        setLabel(QObject::tr("Encoding Type"));
+        addSelection("CBR (Constant Bitrate)","0");
+        addSelection("VBR (Variable Bitrate)","1");
+        addSelection("ABR (Average Bitrate)","2");
+
+        setValue(0);
+        setHelpText("CBR produces fixed size audio at the bitrate given regardless of input. VBR and ABR float the bitrate used as needed based on the input audio, VBR chooses by desired quality, ABR chooses by desired bitrate. If unsure, select CBR.");
+     };
+};
+
+class MP3StereoMode: public CodecParam, public ComboBoxSetting {
+public:
+     MP3StereoMode(const RecordingProfile& parent):
+        CodecParam(parent, "mp3stereomode") {
+        setLabel(QObject::tr("Stereo mode"));
+        addSelection("Auto","0");
+        addSelection("Joint-Stereo","1");
+        addSelection("Stereo","2");
+        addSelection("Mono","3");
+ 
+        setValue(0);
+        setHelpText("Joint-Stereo may produce better quality audio in lower bitrates than Stereo, but Stereo will have more correct stereo seperation. Mono willdownmix audio to one channel. If unsure, select Auto.");
+     };
+};
+
+class MP3VBRQual: public CodecParam, public SliderSetting {
+public:
+     MP3VBRQual(const RecordingProfile& parent):
+	CodecParam(parent, "mp3vbrqual"),
+        SliderSetting(0,9,1) {
+        setLabel(QObject::tr("VBR Quality"));
+        setValue(4);
+        setHelpText("VBR quality desired. Lower numbers are higher quality. Ignored in CBR and ABR modes. If unsure, select 4.");
+     };
+};
+
 class SampleRate: public CodecParam, public ComboBoxSetting {
 public:
     SampleRate(const RecordingProfile& parent, bool analog = true):
@@ -199,6 +259,10 @@
         ConfigurationGroup* params = new VerticalConfigurationGroup(false);
         params->setLabel("MP3");
         params->addChild(new SampleRate(parent));
+        params->addChild(new MP3EncodingType(parent));
+        params->addChild(new MP3Bitrate(parent));
+        params->addChild(new MP3VBRQual(parent));
+        params->addChild(new MP3StereoMode(parent));
         params->addChild(new MP3Quality(parent));
         addTarget("MP3", params);
 
diff -ru mythtv-orig/libs/libmythtv/tv_rec.cpp mythtv/libs/libmythtv/tv_rec.cpp
--- mythtv-orig/libs/libmythtv/tv_rec.cpp	2003-12-05 11:05:54.000000000 +1300
+++ mythtv/libs/libmythtv/tv_rec.cpp	2003-12-05 10:56:26.000000000 +1300
@@ -622,6 +622,10 @@
     {
         nvr->SetOption("audiocompression", 1);
         SetOption(profile, "mp3quality");
+        SetOption(profile, "mp3vbrqual");
+        SetOption(profile, "mp3stereomode");
+        SetOption(profile, "mp3bitrate");
+        SetOption(profile, "mp3encodingtype");
         SetOption(profile, "samplerate");
     } 
     else if (setting == "Uncompressed") 


More information about the mythtv-dev mailing list