+ /* 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;
+ }
+ }
+ /* Audio Bitrate */
+
+ /* Audio DRC */
+ i = 0;
+ if ( dynamic_range_compression )
+ {
+ char * token = strtok(dynamic_range_compression, ",");
+ if (token == NULL)
+ token = dynamic_range_compression;
+ while ( token != NULL )
+ {
+ d_r_c = atof(token);
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ if( audio != NULL )
+ {
+ audio->out.dynamic_range_compression = d_r_c;
+ if( (++i) >= num_audio_tracks )
+ break; /* We have more inputs than audio tracks, oops */
+ }
+ else
+ {
+ fprintf(stderr, "Ignoring drc, no audio tracks\n");
+ }
+ token = strtok(NULL, ",");
+ }
+ }
+ if (i < num_audio_tracks)
+ {
+ /* We have fewer inputs than audio tracks, use no DRC for the remaining
+ * tracks. Unless we only have one input, then use the same DRC for all
+ * tracks.
+ */
+ if (i != 1)
+ d_r_c = 0;
+ for (; i < num_audio_tracks; i++)
+ {
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ audio->out.dynamic_range_compression = d_r_c;
+ }
+ }
+ /* Audio DRC */
+
+ /* Audio Mixdown */
+ i = 0;
+ if ( mixdowns )
+ {
+ char * token = strtok(mixdowns, ",");
+ if (token == NULL)
+ token = mixdowns;
+ while ( token != NULL )
+ {
+ mixdown = hb_mixdown_get_mixdown_from_short_name(token);
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ if( audio != NULL )
+ {
+ audio->out.mixdown = mixdown;
+ if( (++i) >= num_audio_tracks )
+ break; /* We have more inputs than audio tracks, oops */
+ }
+ else
+ {
+ fprintf(stderr, "Ignoring mixdown, no audio tracks\n");
+ }
+ token = strtok(NULL, ",");
+ }
+ }
+ if (i < num_audio_tracks)
+ {
+ /* We have fewer inputs than audio tracks, use DPLII for the rest. Unless
+ * we only have one input, then use that.
+ */
+ if (i != 1)
+ mixdown = HB_AMIXDOWN_DOLBYPLII;
+ for (; i < num_audio_tracks; i++)
+ {
+ audio = hb_list_audio_config_item(job->list_audio, i);
+ audio->out.mixdown = mixdown;
+ }
+ }
+ /* 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 */