changeset 8517:bcf1b010bf14

Presets are an easy way, to use hard to access lame options and to give you optimum quality at average bitrate. This patch adds presets to mencoder for libmp3lame >= 3.92. More info in the sourcecode & at http://www.mp3dev.org/mp3/doc/html/presets.html patch by eviv bulgroz <ebulgroz@yahoo.com>
author arpi
date Sat, 21 Dec 2002 22:16:49 +0000
parents 71e2ba5d6cdc
children 01b41e00f40e
files DOCS/mplayer.1 cfg-mencoder.h configure mencoder.c
diffstat 4 files changed, 288 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/mplayer.1	Sat Dec 21 22:11:48 2002 +0000
+++ b/DOCS/mplayer.1	Sat Dec 21 22:16:49 2002 +0000
@@ -2075,7 +2075,9 @@
 .IPs abr\ \ 
 average bitrate
 .IPs cbr\ \ 
-constant bitrate
+constant bitrate.
+.br
+Forces also CBR mode encoding on subsequent ABR presets modes
 .IPs br=<0\-1024>
 specify bitrate in kBit (CBR and ABR only)
 .IPs q=<0\-9>
@@ -2105,7 +2107,39 @@
 .br
 2: adjust
 .REss
+.IPs fast
+switch on faster encoding on subsequent VBR presets modes, slightly lower quality and higher bitrates.
+.IPs preset
+provide the highest possible quality settings.
+.RSss
+medium: VBR encoding, good quality, 150\-180 kbps bitrate range.
+.br
+standard: VBR encoding, high quality, 170\-210 kbps bitrate range.
+.br
+extreme: VBR encoding, very high quality, 200\-240 kbps bitrate range.
+.br
+insane: CBR encoding, highest preset quality, 320 kbps bitrate.
+.br
+<8-320>: ABR encoding at average given kbps bitrate.
+.br
+.REss
 .RE
+
+.I EXAMPLE:
+.PD 0
+.RSs
+.IPs "\-lameopts fast:preset=standard"
+for most people on most music and already quite high in quality.
+.IPs "\-lameopts  cbr:preset=192"
+encode with ABR presets at a 192 kbps forced constant bitrate.
+.IPs "\-lameopts      preset=172"
+encode with ABR presets at a 172 kbps average bitrate.
+.IPs "\-lameopts      preset=extreme"
+for people with extremely good hearing and similar equipment.
+.IPs "\-lameopts preset=help"
+print additional options and informations on presets settings.
+.RE
+.PD 1
 .
 .TP
 .B \-lavcopts <option1:option2:...>
--- a/cfg-mencoder.h	Sat Dec 21 22:11:48 2002 +0000
+++ b/cfg-mencoder.h	Sat Dec 21 22:16:49 2002 +0000
@@ -31,6 +31,10 @@
 	{"br", &lame_param_br, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
 	{"ratio", &lame_param_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
 	{"vol", &lame_param_scale, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10, NULL},
+#if HAVE_MP3LAME >= 392
+	{"fast", &lame_param_fast, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"preset", &lame_param_preset, CONF_TYPE_STRING, 0, 0, 0, NULL},
+#endif
 	{"help", "TODO: lameopts help!\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
 	{NULL, NULL, 0, 0, 0, 0, NULL}
 };
--- a/configure	Sat Dec 21 22:11:48 2002 +0000
+++ b/configure	Sat Dec 21 22:16:49 2002 +0000
@@ -4127,12 +4127,12 @@
   _mp3lame=no
   cat > $TMPC <<EOF
 #include <lame/lame.h>
-int main(void) { (void) lame_init(); return 0; }
+int main(void) { lame_version_t lv; (void) lame_init(); get_lame_version_numerical(&lv);  printf("%d%d\n",lv.major,lv.minor); return 0; }
 EOF
   # Note: libmp3lame usually depends on vorbis
   cc_check -lmp3lame $_ld_vorbis -lm && _mp3lame=yes
   if test "$_mp3lame" = yes ; then
-    _def_mp3lame='#define HAVE_MP3LAME 1'
+    _def_mp3lame="#define HAVE_MP3LAME `$TMPO`"
     _ld_mp3lame="-lmp3lame $_ld_vorbis"
   else
     _def_mp3lame='#undef HAVE_MP3LAME'
--- a/mencoder.c	Sat Dec 21 22:11:48 2002 +0000
+++ b/mencoder.c	Sat Dec 21 22:16:49 2002 +0000
@@ -196,6 +196,12 @@
 int lame_param_br=-1; // unset
 int lame_param_ratio=-1; // unset
 float lame_param_scale=-1; // unset
+#if HAVE_MP3LAME >= 392
+int lame_param_fast=0; // unset
+static char* lame_param_preset=NULL; // unset
+static int  lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name );
+static void  lame_presets_longinfo_dm ( FILE* msgfp );
+#endif
 #endif
 
 //static int vo_w=0, vo_h=0;
@@ -832,6 +838,12 @@
     printf("Setting audio input gain to %f\n", lame_param_scale);
     lame_set_scale(lame,lame_param_scale);
 }
+#if HAVE_MP3LAME >= 392
+if(lame_param_preset != NULL){
+  printf ("\npreset=%s\n\n",lame_param_preset);
+  lame_presets_set(lame,lame_param_fast, (lame_param_vbr==0), lame_param_preset);
+}
+#endif
 lame_init_params(lame);
 if(verbose>0){
     lame_print_config(lame);
@@ -1344,3 +1356,238 @@
     return dst;
 }
 #endif
+
+#if HAVE_MP3LAME >= 392
+/* lame_presets_set 
+   taken out of presets_set in lame-3.93.1/frontend/parse.c and modified */
+static int  lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name )
+{
+    int mono = 0;
+
+    if (strcmp(preset_name, "help") == 0) {
+        fprintf(stdout, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
+        lame_presets_longinfo_dm( stdout );
+        return -1;
+    }
+
+
+
+    //aliases for compatibility with old presets
+
+    if (strcmp(preset_name, "phone") == 0) {
+        preset_name = "16";
+        mono = 1;
+    }
+    if ( (strcmp(preset_name, "phon+") == 0) ||
+         (strcmp(preset_name, "lw") == 0) ||
+         (strcmp(preset_name, "mw-eu") == 0) ||
+         (strcmp(preset_name, "sw") == 0)) {
+        preset_name = "24";
+        mono = 1;
+    }
+    if (strcmp(preset_name, "mw-us") == 0) {
+        preset_name = "40";
+        mono = 1;
+    }
+    if (strcmp(preset_name, "voice") == 0) {
+        preset_name = "56";
+        mono = 1;
+    }
+    if (strcmp(preset_name, "fm") == 0) {
+        preset_name = "112";
+    }
+    if ( (strcmp(preset_name, "radio") == 0) ||
+         (strcmp(preset_name, "tape") == 0)) {
+        preset_name = "112";
+    }
+    if (strcmp(preset_name, "hifi") == 0) {
+        preset_name = "160";
+    }
+    if (strcmp(preset_name, "cd") == 0) {
+        preset_name = "192";
+    }
+    if (strcmp(preset_name, "studio") == 0) {
+        preset_name = "256";
+    }
+
+#if HAVE_MP3LAME >= 393
+    if (strcmp(preset_name, "medium") == 0) {
+
+        if (fast > 0)
+           lame_set_preset(gfp, MEDIUM_FAST);
+        else
+           lame_set_preset(gfp, MEDIUM);
+
+        return 0;
+    }
+#endif
+    
+    if (strcmp(preset_name, "standard") == 0) {
+
+        if (fast > 0)
+           lame_set_preset(gfp, STANDARD_FAST);
+        else
+           lame_set_preset(gfp, STANDARD);
+
+        return 0;
+    }
+    
+    else if (strcmp(preset_name, "extreme") == 0){
+
+        if (fast > 0)
+           lame_set_preset(gfp, EXTREME_FAST);
+        else
+           lame_set_preset(gfp, EXTREME);
+
+        return 0;
+    }
+    					
+    else if (((strcmp(preset_name, "insane") == 0) || 
+              (strcmp(preset_name, "320"   ) == 0))   && (fast < 1)) {
+
+        lame_set_preset(gfp, INSANE);
+ 
+        return 0;
+    }
+
+    // Generic ABR Preset
+    if (((atoi(preset_name)) > 0) &&  (fast < 1)) {
+        if ((atoi(preset_name)) >= 8 && (atoi(preset_name)) <= 320){
+            lame_set_preset(gfp, atoi(preset_name));
+
+            if (cbr == 1 )
+                lame_set_VBR(gfp, vbr_off);
+
+            if (mono == 1 ) {
+                lame_set_mode(gfp, MONO);
+            }
+
+            return 0;
+
+        }
+        else {
+            fprintf(stderr, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
+            fprintf(stderr,"Error: The bitrate specified is out of the valid range for this preset\n"
+                           "\n"
+                           "When using this mode you must enter a value between \"8\" and \"320\"\n"
+                           "\n"
+                           "For further information try: \"-lameopts preset=help\"\n"                  
+                   );
+            return -1;
+        }
+    }
+
+
+
+    fprintf(stderr, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
+    fprintf(stderr,"Error: You did not enter a valid profile and/or options with preset\n"
+                   "\n"
+                   "Available profiles are:\n"
+                   "\n"
+                   "   <fast>        standard\n"
+                   "   <fast>        extreme\n"
+                   "                 insane\n"
+                   "   <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"
+                   "                      simply specify a bitrate. For example:\n"
+                   "                      \"preset=185\" activates this\n"
+                   "                      preset and uses 185 as an average kbps.\n" 
+                   "\n"
+                   "    Some examples:\n"
+                   "\n"
+   		   "    \"-lameopts fast:preset=standard  \"\n"
+   		   " or \"-lameopts  cbr:preset=192       \"\n"
+   		   " or \"-lameopts      preset=172       \"\n"
+   		   " or \"-lameopts      preset=extreme   \"\n"
+                   "\n"
+                   "For further information try: \"-lameopts preset=help\"\n"                  
+           );
+    mencoder_exit(1, "error parsing cmdline");
+}
+#endif
+
+#if HAVE_MP3LAME >= 392
+/* lame_presets_longinfo_dm
+   taken out of presets_longinfo_dm in lame-3.93.1/frontend/parse.c and modified */
+static void  lame_presets_longinfo_dm ( FILE* msgfp )
+{
+        fprintf ( msgfp,
+        "\n" 
+        "The preset switches are designed to provide the highest possible quality.\n"
+        "\n"
+        "They have for the most part been subject to and tuned via rigorous double blind\n"
+        "listening tests to verify and achieve this objective.\n"
+        "\n"
+        "These are continually updated to coincide with the latest developments that\n"
+        "occur and as a result should provide you with nearly the best quality\n"
+        "currently possible from LAME.\n"
+        "\n"
+        "To activate these presets:\n"
+        "\n"
+        "   For VBR modes (generally highest quality):\n"
+        "\n"
+        "     \"preset=standard\" This preset should generally be transparent\n"
+        "                             to most people on most music and is already\n"
+        "                             quite high in quality.\n"
+        "\n"
+        "     \"preset=extreme\" If you have extremely good hearing and similar\n"
+        "                             equipment, this preset will generally provide\n"
+        "                             slightly higher quality than the \"standard\"\n"
+        "                             mode.\n"
+        "\n"
+        "   For CBR 320kbps (highest quality possible from the preset switches):\n"
+        "\n"
+        "     \"preset=insane\"  This preset will usually be overkill for most\n"
+        "                             people and most situations, but if you must\n"
+        "                             have the absolute highest quality with no\n"
+        "                             regard to filesize, this is the way to go.\n"
+        "\n"
+        "   For ABR modes (high quality per given bitrate but not as high as VBR):\n"
+        "\n"
+        "     \"preset=<kbps>\"  Using this preset will usually give you good\n"
+        "                             quality at a specified bitrate. Depending on the\n"
+        "                             bitrate entered, this preset will determine the\n"
+        "                             optimal settings for that particular situation.\n"
+        "                             While this approach works, it is not nearly as\n"
+        "                             flexible as VBR, and usually will not attain the\n"
+        "                             same level of quality as VBR at higher bitrates.\n"  
+        "\n"
+        "The following options are also available for the corresponding profiles:\n"
+        "\n"
+        "   <fast>        standard\n"
+        "   <fast>        extreme\n"
+        "                 insane\n"
+        "   <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"
+        "                      simply specify a bitrate. For example:\n"
+        "                      \"preset=185\" activates this\n"
+        "                      preset and uses 185 as an average kbps.\n" 
+        "\n"
+        "   \"fast\" - Enables the new fast VBR for a particular profile. The\n"
+        "            disadvantage to the speed switch is that often times the\n"
+        "            bitrate will be slightly higher than with the normal mode\n"
+        "            and quality may be slightly lower also.\n"
+	"   Warning: with the current version fast presets might result in too\n"
+	"            high bitrate compared to regular presets.\n"
+        "\n"
+        "   \"cbr\"  - If you use the ABR mode (read above) with a significant\n"
+        "            bitrate such as 80, 96, 112, 128, 160, 192, 224, 256, 320,\n"
+        "            you can use the \"cbr\" option to force CBR mode encoding\n"
+        "            instead of the standard abr mode. ABR does provide higher\n"
+        "            quality but CBR may be useful in situations such as when\n"
+        "            streaming an mp3 over the internet may be important.\n"
+        "\n"
+        "    For example:\n"
+        "\n"
+        "    \"-lameopts fast:preset=standard  \"\n"
+        " or \"-lameopts  cbr:preset=192       \"\n"
+        " or \"-lameopts      preset=172       \"\n"
+        " or \"-lameopts      preset=extreme   \"\n"
+        "\n"
+        "\n"
+        "A few aliases are available for ABR mode:\n"
+        "phone => 16kbps/mono        phon+/lw/mw-eu/sw => 24kbps/mono\n"
+        "mw-us => 40kbps/mono        voice => 56kbps/mono\n"
+        "fm/radio/tape => 112kbps    hifi => 160kbps\n"
+        "cd => 192kbps               studio => 256kbps");
+	mencoder_exit(0, NULL);
+}
+#endif