+
+ /* Audio Codecs */
+ i = 0;
+ if( acodecs )
+ {
+ char * token = strtok(acodecs, ",");
+ if( token == NULL )
+ token = acodecs;
+ while ( token != NULL )
+ {
+ if ((acodec = get_acodec_for_string(token)) == -1)
+ {
+ fprintf(stderr, "Invalid codec %s, using default for container.\n", token);
+ acodec = default_acodec;
+ }
+ if( i < num_audio_tracks )
+ {
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ audio->out.codec = acodec;
+ }
+ else
+ {
+ hb_audio_config_t * last_audio = hb_list_audio_config_item( job->list_audio, i - 1 );
+ hb_audio_config_t audio;
+
+ if( last_audio )
+ {
+ fprintf(stderr, "More audio codecs than audio tracks, copying track %i and using encoder %s\n",
+ i, token);
+ hb_audio_config_init(&audio);
+ audio.in.track = last_audio->in.track;
+ audio.out.track = num_audio_tracks++;
+ audio.out.codec = acodec;
+ hb_audio_add(job, &audio);
+ }
+ else
+ {
+ fprintf(stderr, "Audio codecs and no valid audio tracks, skipping codec %s\n", token);
+ }
+ }
+ token = strtok(NULL, ",");
+ i++;
+ }
+ }
+ if( i < num_audio_tracks )
+ {
+ /* We have fewer inputs than audio tracks, use the default codec for
+ * this container for the remaining tracks. Unless we only have one input
+ * then use that codec instead.
+ */
+ if (i != 1)
+ acodec = default_acodec;
+ for ( ; i < num_audio_tracks; i++)
+ {
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ audio->out.codec = acodec;
+ }
+ }
+ /* Audio Codecs */
+
+ /* Sample Rate */
+ i = 0;
+ if( arates )
+ {
+ char * token = strtok(arates, ",");
+ if (token == NULL)
+ token = arates;
+ while ( token != NULL )
+ {
+ arate = atoi(token);
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ int j;
+
+ for( j = 0; j < hb_audio_rates_count; j++ )
+ {
+ if( !strcmp( token, hb_audio_rates[j].string ) )
+ {
+ arate = hb_audio_rates[j].rate;
+ break;
+ }
+ }
+
+ if( audio != NULL )
+ {
+ if (!is_sample_rate_valid(arate))
+ {
+ fprintf(stderr, "Invalid sample rate %d, using input rate %d\n", arate, audio->in.samplerate);
+ arate = audio->in.samplerate;
+ }
+
+ audio->out.samplerate = arate;
+ if( (++i) >= num_audio_tracks )
+ break; /* We have more inputs than audio tracks, oops */
+ }
+ else
+ {
+ fprintf(stderr, "Ignoring sample rate %d, no audio tracks\n", arate);
+ }
+ token = strtok(NULL, ",");
+ }
+ }
+ if (i < num_audio_tracks)
+ {
+ /* We have fewer inputs than audio tracks, use default sample rate.
+ * Unless we only have one input, then use that for all tracks.
+ */
+ if (i != 1)
+ arate = audio->in.samplerate;
+ for ( ; i < num_audio_tracks; i++)
+ {
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ audio->out.samplerate = arate;
+ }
+ }
+ /* Sample Rate */
+
+ /* Audio Bitrate */
+ i = 0;
+ if( abitrates )
+ {
+ char * token = strtok(abitrates, ",");
+ if (token == NULL)
+ token = abitrates;
+ while ( token != NULL )
+ {
+ abitrate = atoi(token);
+ audio = hb_list_audio_config_item(job->list_audio, i);
+
+ if( audio != NULL )
+ {
+ audio->out.bitrate = abitrate;
+ if( (++i) >= num_audio_tracks )
+ break; /* We have more inputs than audio tracks, oops */
+ }
+ else
+ {
+ fprintf(stderr, "Ignoring bitrate %d, no audio tracks\n", abitrate);
+ }
+ token = strtok(NULL, ",");
+ }
+ }
+ if (i < num_audio_tracks)
+ {
+ /* We have fewer inputs than audio tracks, use the default bitrate
+ * for the remaining tracks. Unless we only have one input, then use
+ * that for all tracks.
+ */
+ if (i != 1)
+ abitrate = default_abitrate;
+ for (; i < num_audio_tracks; i++)
+ {
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ audio->out.bitrate = abitrate;
+ }