[PATCH] Set audio track language

Archive of historical development discussions
Discussions / Development has moved to GitHub
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.

*******************************
Post Reply
dirtymatt
Posts: 11
Joined: Wed Feb 13, 2008 4:40 pm

[PATCH] Set audio track language

Post by dirtymatt »

Here is a quick patch I wrote to set the audio track language for non-DVD sources:

Code: Select all

Index: test/test.c
===================================================================
--- test/test.c	(revision 2048)
+++ test/test.c	(working copy)
@@ -56,6 +56,7 @@
 static char * abitrates   = NULL;
 static char * acodecs     = NULL;
 static char * anames      = NULL;
+static char * alangs      = NULL;
 static int    default_acodec = HB_ACODEC_FAAC;
 static int    default_arate = 48000;
 static int    default_abitrate = 160;
@@ -285,6 +286,7 @@
     if( abitrates ) free( abitrates );
     if( acodecs ) free( acodecs );
     if( anames ) free( anames );
+	if( alangs ) free( alangs );
     if (native_language ) free (native_language );
 	if( x264opts ) free (x264opts );
 	if( x264opts2 ) free (x264opts2 );
@@ -1591,6 +1593,29 @@
                     token = strtok(NULL, ",");
                 }
             }
+			i = 0;
+			if ( alangs )
+			{
+				char *token = strtok(alangs, ",");
+				if (token == NULL)
+					token = alangs;
+				while ( token != NULL )
+				{
+					audio = hb_list_audio_config_item(job->list_audio, i);
+					if (audio != NULL )
+					{
+						snprintf(audio->lang.iso639_2, 
+								sizeof(audio->lang.iso639_2), "%s", token);
+						if( (++i) >= num_audio_tracks )
+							break; /* We have more languages than audio tracks, oops */
+					}
+					else
+					{
+						fprintf(stderr, "Ignoring alang '%s', no audio track\n", token);
+					}
+					token = strtok(NULL, ",");
+				}
+			}
             if( i < num_audio_tracks && i == 1 )
             {
                 /* We have exactly one name and more than one audio track. Use the same
@@ -1951,6 +1976,8 @@
     "                            Separated by commas for more than one audio track.\n"
     "    -A, --aname <string>    Audio track name(s),\n"
     "                            Separated by commas for more than one audio track.\n"
+    "    -G, --alang <string>    Audio track language(s),\n"
+    "                            Separated by commas for more than one audio track.\n"
     "\n"
 
     "### Picture Settings---------------------------------------------------------\n\n"
@@ -2140,6 +2167,7 @@
             { "preset-list", no_argument,       NULL,    'z' },
 
             { "aname",       required_argument, NULL,    'A' },
+			{ "alang",       required_argument, NULL,    'G' },
             { "color-matrix",required_argument, NULL,    'M' },
             { "previews",    required_argument, NULL,    PREVIEWS },
 
@@ -2487,6 +2515,12 @@
                     anames = strdup( optarg );
                 }
                 break;
+			case 'G':
+				if( optarg != NULL )
+				{
+					alangs = strdup( optarg );
+				}
+				break;
             case PREVIEWS:
                 sscanf( optarg, "%i:%i", &preview_count, &store_previews );
                 break;
cvk_b
Veteran User
Posts: 527
Joined: Sun Mar 18, 2007 2:11 am

Re: [PATCH] Set audio track language

Post by cvk_b »

Confirm patch applies. I vote this goes in for sure.

aname + alang allows nano/classic to do alternate audio commentary. Just change the second english language to any other language.

Thanks for this.
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Re: [PATCH] Set audio track language

Post by eddyg »

Looks good to me.
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Re: [PATCH] Set audio track language

Post by jbrjake »

Well I'd prefer if it didn't use a short option name in the CLI. Those should be conserved for major things.
cvk_b
Veteran User
Posts: 527
Joined: Sun Mar 18, 2007 2:11 am

Re: [PATCH] Set audio track language

Post by cvk_b »

jbrjake wrote:Well I'd prefer if it didn't use a short option name in the CLI. Those should be conserved for major things.

Code: Select all

    -A, --aname <string>    Audio track name(s),
                            Separated by commas for more than one audio track.
    -G, --alang <string>    Audio track language(s),
                            Separated by commas for more than one audio track.
Audio track name has a short option. Look, they're twins. :mrgreen:
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Re: [PATCH] Set audio track language

Post by jbrjake »

cvk_b, I didn't really want to turn this patch thread into a discussion of CLI conventions but okay....

My plan is to get rid of all pointless short option names that only obfuscate functionality and replace them with an enum of long option names. I stopped using short option names in my own CLI modifications already. I'm just trying to save myself the trouble of having to go and modify this patch's code later on.

I don't think "-G" is an intuitive way to represent "audio language" any more than "-5" makes any sense for decomb or "-U" for subtitle scan or "-6" does for mixdown (it did when it was added originally and all it did was six-channel aac) or "-Z" does for presets. They should all go.
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Re: [PATCH] Set audio track language

Post by eddyg »

I also would like to see the end of short options
dirtymatt
Posts: 11
Joined: Wed Feb 13, 2008 4:40 pm

Re: [PATCH] Set audio track language

Post by dirtymatt »

jbrjake wrote:I don't think "-G" is an intuitive way to represent "audio language" any more than "-5" makes any sense for decomb or "-U" for subtitle scan or "-6" does for mixdown (it did when it was added originally and all it did was six-channel aac) or "-Z" does for presets. They should all go.
I agree completely, I just used -G because everything else seemed to have a short option and I assumed it was a requirement. Here's a new patch against the latest SVN using a #define instead:

Code: Select all

Index: test/test.c
===================================================================
--- test/test.c	(revision 2079)
+++ test/test.c	(working copy)
@@ -57,6 +57,7 @@
 static char * abitrates   = NULL;
 static char * acodecs     = NULL;
 static char * anames      = NULL;
+static char * alangs      = NULL;
 static int    default_acodec = HB_ACODEC_FAAC;
 static int    default_arate = 48000;
 static int    default_abitrate = 160;
@@ -288,6 +289,7 @@
     if( abitrates ) free( abitrates );
     if( acodecs ) free( acodecs );
     if( anames ) free( anames );
+    if( alangs ) free( alangs );
     if (native_language ) free (native_language );
 	if( x264opts ) free (x264opts );
 	if( x264opts2 ) free (x264opts2 );
@@ -1594,6 +1596,29 @@
                     token = strtok(NULL, ",");
                 }
             }
+			i = 0;
+			if ( alangs )
+			{
+				char *token = strtok(alangs, ",");
+				if (token == NULL)
+					token = alangs;
+				while ( token != NULL )
+				{
+					audio = hb_list_audio_config_item(job->list_audio, i);
+					if (audio != NULL )
+					{
+						snprintf(audio->lang.iso639_2, 
+								sizeof(audio->lang.iso639_2), "%s", token);
+						if( (++i) >= num_audio_tracks )
+							break; /* We have more languages than audio tracks, oops */
+					}
+					else
+					{
+						fprintf(stderr, "Ignoring alang '%s', no audio track\n", token);
+					}
+					token = strtok(NULL, ",");
+				}
+			}
             if( i < num_audio_tracks && i == 1 )
             {
                 /* We have exactly one name and more than one audio track. Use the same
@@ -1970,6 +1995,8 @@
     "                            Separated by commas for more than one audio track.\n"
     "    -A, --aname <string>    Audio track name(s),\n"
     "                            Separated by commas for more than one audio track.\n"
+    "    --alang <string>        Audio track language(s),\n"
+    "                            Separated by commas for more than one audio track.\n"
     "\n"
 
     "### Picture Settings---------------------------------------------------------\n\n"
@@ -2103,6 +2130,7 @@
     #define START_AT_PREVIEW 258
     #define STOP_AT_PTS 259
     #define STOP_AT_DURATION 260
+    #define AUDIO_LANGUAGE 261
     
     for( ;; )
     {
@@ -2162,6 +2190,7 @@
             { "preset-list", no_argument,       NULL,    'z' },
 
             { "aname",       required_argument, NULL,    'A' },
+            { "alang",       required_argument, NULL,    AUDIO_LANGUAGE },
             { "color-matrix",required_argument, NULL,    'M' },
             { "previews",    required_argument, NULL,    PREVIEWS },
             { "start-at-preview", required_argument, NULL, START_AT_PREVIEW },
@@ -2512,6 +2541,12 @@
                     anames = strdup( optarg );
                 }
                 break;
+            case AUDIO_LANGUAGE:
+               if( optarg != NULL )
+               {
+                   alangs = strdup( optarg );
+               }
+               break;
             case PREVIEWS:
                 sscanf( optarg, "%i:%i", &preview_count, &store_previews );
                 break;
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Re: [PATCH] Set audio track language

Post by jbrjake »

Here's an updated patch:
http://handbrake.fr/pastebin/pastebin.php?show=519

It's not going in yet because when I went to commit it I noticed there's a minor issue with it...you're directly setting a private variable in the libhb audio config struct from an interface. Saintdev wants there to be a helper function for the lib to allow interfaces to access that kind of stuff....
dirtymatt
Posts: 11
Joined: Wed Feb 13, 2008 4:40 pm

Re: [PATCH] Set audio track language

Post by dirtymatt »

jbrjake wrote:Here's an updated patch:
http://handbrake.fr/pastebin/pastebin.php?show=519

It's not going in yet because when I went to commit it I noticed there's a minor issue with it...you're directly setting a private variable in the libhb audio config struct from an interface. Saintdev wants there to be a helper function for the lib to allow interfaces to access that kind of stuff....
I couldn't find any way to modify the language other than writing direct to the struct. If there's a helper function coming, I agree that is a much better way to go about things. Thanks for the updated patch also.
cvk_b
Veteran User
Posts: 527
Joined: Sun Mar 18, 2007 2:11 am

Re: [PATCH] Set audio track language

Post by cvk_b »

dirtymatt wrote:Thanks for the updated patch
  • +1
Post Reply