OSDN Git Service

CLI: Add support for naming audio tracks to the HandBrakeCLI, thanks to LePetomane...
authoreddyg <eddyg@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 10 Oct 2008 04:43:13 +0000 (04:43 +0000)
committereddyg <eddyg@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 10 Oct 2008 04:43:13 +0000 (04:43 +0000)
git-svn-id: svn://localhost/HandBrake/trunk@1825 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.c
libhb/common.h
libhb/muxmp4.c
libhb/work.c
test/test.c

index 073abb9..7cb6ec9 100644 (file)
@@ -739,6 +739,7 @@ void hb_audio_config_init(hb_audio_config_t * audiocfg)
     audiocfg->out.samplerate = 44100;
     audiocfg->out.mixdown = HB_AMIXDOWN_DOLBYPLII;
     audiocfg->out.dynamic_range_compression = 0;
+    audiocfg->out.name = NULL;
 }
 
 /**********************************************************************
index a5cfcf4..47f5503 100644 (file)
@@ -329,6 +329,7 @@ struct hb_audio_config_s
             int bitrate;    /* Output bitrate (kbps) */
             int mixdown;    /* The mixdown format to be used for this audio track (see HB_AMIXDOWN_*) */
             double dynamic_range_compression; /* Amount of DRC that gets applied to this track */
+            char * name;    /* Output track name */
     } out;
 
     /* Input */
index febeb01..807bc24 100644 (file)
@@ -309,18 +309,36 @@ static int MP4Init( hb_mux_object_t * m )
             mux_data->track = MP4AddAC3AudioTrack(
                 m->file,
                 m->samplerate, 1536, MP4_MPEG4_AUDIO_TYPE );
-            MP4SetTrackBytesProperty(
-                m->file, mux_data->track,
-                "udta.name.value",
-                (const u_int8_t*)"Surround", strlen("Surround"));
+            if (audio->config.out.name == NULL) {
+                MP4SetTrackBytesProperty(
+                    m->file, mux_data->track,
+                    "udta.name.value",
+                    (const u_int8_t*)"Surround", strlen("Surround"));
+            }
+            else {
+                MP4SetTrackBytesProperty(
+                    m->file, mux_data->track,
+                    "udta.name.value",
+                    (const u_int8_t*)(audio->config.out.name),
+                    strlen(audio->config.out.name));
+            }
         } else {
             mux_data->track = MP4AddAudioTrack(
                 m->file,
                 m->samplerate, 1024, MP4_MPEG4_AUDIO_TYPE );
-            MP4SetTrackBytesProperty(
-                m->file, mux_data->track,
-                "udta.name.value",
-                (const u_int8_t*)"Stereo", strlen("Stereo"));
+            if (audio->config.out.name == NULL) {
+                MP4SetTrackBytesProperty(
+                    m->file, mux_data->track,
+                    "udta.name.value",
+                    (const u_int8_t*)"Stereo", strlen("Stereo"));
+            }
+            else {
+                MP4SetTrackBytesProperty(
+                    m->file, mux_data->track,
+                    "udta.name.value",
+                    (const u_int8_t*)(audio->config.out.name),
+                    strlen(audio->config.out.name));
+            }
 
             MP4SetAudioProfileLevel( m->file, 0x0F );
             MP4SetTrackESConfiguration(
index 64b0617..91da97a 100644 (file)
@@ -285,7 +285,8 @@ hb_display_job_info( hb_job_t * job )
         {
             audio = hb_list_item( title->list_audio, i );
 
-            hb_log( " * audio track %d", audio->config.out.track );
+            hb_log( " * audio track %d (%s)", audio->config.out.track,
+                    audio->config.out.name ?  audio->config.out.name : "no-name" );
 
             hb_log( "   + decoder: %s (track %d, id %x)", audio->config.lang.description, audio->config.in.track, audio->id );
 
index 0357001..dc61c57 100644 (file)
@@ -55,6 +55,7 @@ static char * atracks     = NULL;
 static char * arates      = NULL;
 static char * abitrates   = NULL;
 static char * acodecs     = NULL;
+static char * anames      = NULL;
 static int    default_acodec = HB_ACODEC_FAAC;
 static int    default_arate = 48000;
 static int    default_abitrate = 160;
@@ -265,6 +266,10 @@ int main( int argc, char ** argv )
         while( ( audio = hb_list_item( audios, 0 ) ) )
         {
             hb_list_rem( audios, audio );
+            if( audio->out.name )
+            {
+                free( audio->out.name );
+            }
             free( audio );
         }
         hb_list_close( &audios );
@@ -275,6 +280,7 @@ int main( int argc, char ** argv )
     if( arates ) free( arates );
     if( abitrates ) free( abitrates );
     if( acodecs ) free( acodecs );
+    if( anames ) free( anames );
     if (native_language ) free (native_language );
        if( x264opts ) free (x264opts );
        if( x264opts2 ) free (x264opts2 );
@@ -977,6 +983,10 @@ static int HandleEvents( hb_handle_t * h )
                 }
                 hb_list_rem(audios, audio);
                 if( audio != NULL)
+                    if( audio->out.name )
+                    {
+                        free( audio->out.name);
+                    }
                     free( audio );
             }
 
@@ -1215,6 +1225,42 @@ static int HandleEvents( hb_handle_t * h )
             }
             /* Audio Mixdown */
 
+            /* Audio Track Names */
+            i = 0;
+            if ( anames )
+            {
+                char * token = strtok(anames, ",");
+                if (token == NULL)
+                    token = anames;
+                while ( token != NULL )
+                {
+                    audio = hb_list_audio_config_item(job->list_audio, i);
+                    if( audio != NULL )
+                    {
+                        audio->out.name = strdup(token);
+                        if( (++i) >= num_audio_tracks )
+                            break;  /* We have more names than audio tracks, oops */
+                    }
+                    else
+                    {
+                        fprintf(stderr, "Ignoring aname '%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
+                 * name for all tracks. */
+                for ( ; i < num_audio_tracks; i++)
+                {
+                    audio = hb_list_audio_config_item(job->list_audio, i);
+                    audio->out.name = strdup(anames);
+                }
+            }
+            /* Audio Track Names */
+
             if( size )
             {
                 job->vbitrate = hb_calc_bitrate( job, size );
@@ -1592,6 +1638,8 @@ static void ShowHelp()
     "                            making soft sounds louder. Range is 1.0 to 4.0\n"
     "                            (too loud), with 1.5 - 2.5 being a useful range.\n"
     "                            Seperated by commas for more than one audio track.\n"
+    "    -A, --aname <string>    Audio channel name(s),\n"
+    "                            Separated by commas for more than one audio track.\n"
 
 
        "\n"
@@ -1712,6 +1760,8 @@ static int ParseOptions( int argc, char ** argv )
             { "preset",      required_argument, NULL,    'Z' },
             { "preset-list", no_argument,       NULL,    'z' },
 
+            { "aname",       required_argument, NULL,    'A' },
+
             { 0, 0, 0, 0 }
           };
 
@@ -1719,7 +1769,7 @@ static int ParseOptions( int argc, char ** argv )
         int c;
 
                c = getopt_long( argc, argv,
-                                                "hv::uC:f:4i:Io:t:Lc:m::a:6:s:UFN:e:E:2dD:7895gpOP::w:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z",
+                                                "hv::uC:f:4i:Io:t:Lc:m::a:A:6:s:UFN:e:E:2dD:7895gpOP::w:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z",
                          long_options, &option_index );
         if( c < 0 )
         {
@@ -2050,6 +2100,12 @@ static int ParseOptions( int argc, char ** argv )
             case 'X':
                 maxWidth = atoi (optarg );
                 break;
+            case 'A':
+                if( optarg != NULL )
+                {
+                    anames = strdup( optarg );
+                }
+                break;
 
             default:
                 fprintf( stderr, "unknown option (%s)\n", argv[optind] );