-
- /* Video encoder */
- switch( job->vcodec )
- {
- case HB_VCODEC_FFMPEG:
- w = hb_get_work( WORK_ENCAVCODEC );
- break;
- case HB_VCODEC_XVID:
- w = hb_get_work( WORK_ENCXVID );
- break;
- case HB_VCODEC_X264:
- w = hb_get_work( WORK_ENCX264 );
- break;
- case HB_VCODEC_THEORA:
- w = hb_get_work( WORK_ENCTHEORA );
- break;
- }
- w->fifo_in = job->fifo_render;
- w->fifo_out = job->fifo_mpeg4;
- w->config = &job->config;
-
- hb_list_add( job->list_work, w );
- }
-
- if( job->select_subtitle && !job->indepth_scan )
- {
- /*
- * Must be second pass of a two pass with subtitle scan enabled, so
- * add the subtitle that we found on the first pass for use in this
- * pass.
- */
- if (*(job->select_subtitle))
- {
- hb_list_add( title->list_subtitle, *( job->select_subtitle ) );
- }
- }
-
- for( i=0; i < hb_list_count(title->list_subtitle); i++ )
- {
- subtitle = hb_list_item( title->list_subtitle, i );
-
- if( subtitle )
- {
- subtitle->fifo_in = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
- subtitle->fifo_raw = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
-
- /*
- * Disable forced subtitles if we didn't find any in the scan
- * so that we display normal subtitles instead.
- *
- * select_subtitle implies that we did a scan.
- */
- if( !job->indepth_scan && job->subtitle_force &&
- job->select_subtitle )
- {
- if( subtitle->forced_hits == 0 )
- {
- job->subtitle_force = 0;
- }
- }
-
- if (!job->indepth_scan || job->subtitle_force) {
- /*
- * Don't add threads for subtitles when we are scanning, unless
- * looking for forced subtitles.
- */
- w = hb_get_work( WORK_DECSUB );
- w->fifo_in = subtitle->fifo_in;
- w->fifo_out = subtitle->fifo_raw;
- hb_list_add( job->list_work, w );
- }
- }
- }
-
- if( !job->indepth_scan )
- {
- /* if we are doing passthru, and the input codec is not the same as the output
- * codec, then remove this audio from the job */
- /* otherwise, Bad Things will happen */
+ // if we are doing passthru, and the input codec is not the same as the output
+ // codec, then remove this audio from the job. If we're not doing passthru and
+ // the input codec is the 'internal' ffmpeg codec, make sure that only one
+ // audio references that audio stream since the codec context is specific to
+ // the audio id & multiple copies of the same stream will garble the audio
+ // or cause aborts.
+ uint8_t aud_id_uses[MAX_STREAMS];
+ memset( aud_id_uses, 0, sizeof(aud_id_uses) );