+ audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
+ audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
+ audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
+ audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
+ audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
+ audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
+
+ hb_audio_add( job, audio );
+ free(audio);
+
+ }
+
+ if ([fAudLang3PopUp indexOfSelectedItem] > 0)
+ {
+ audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
+ hb_audio_config_init(audio);
+ audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
+ /* We go ahead and assign values to our audio->out.<properties> */
+ audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
+ audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
+ audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
+ audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
+ audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
+ audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
+
+ hb_audio_add( job, audio );
+ free(audio);
+
+ }
+
+ if ([fAudLang4PopUp indexOfSelectedItem] > 0)
+ {
+ audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
+ hb_audio_config_init(audio);
+ audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
+ /* We go ahead and assign values to our audio->out.<properties> */
+ audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
+ audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
+ audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
+ audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
+ audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
+ audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
+
+ hb_audio_add( job, audio );
+ free(audio);
+
+ }
+
+
+
+ /* Filters */
+
+ /* Though Grayscale is not really a filter, per se
+ * we put it here since its in the filters panel
+ */
+
+ if ([fPictureController grayscale])
+ {
+ job->grayscale = 1;
+ }
+ else
+ {
+ job->grayscale = 0;
+ }
+
+ /* Initialize the filters list */
+ job->filters = hb_list_init();
+
+ /* Now lets call the filters if applicable.
+ * The order of the filters is critical
+ */
+
+ /* Detelecine */
+ if ([fPictureController detelecine] == 1)
+ {
+ hb_list_add( job->filters, &hb_filter_detelecine );
+ }
+ if ([fPictureController detelecine] == 2)
+ {
+ /* use a custom detelecine string */
+ hb_filter_detelecine.settings = (char *) [[fPictureController detelecineCustomString] UTF8String];
+ hb_list_add( job->filters, &hb_filter_detelecine );
+ }
+ if ([fPictureController useDecomb] == 1)
+ {
+ /* Decomb */
+ if ([fPictureController decomb] == 1)
+ {
+ /* Run old deinterlacer fd by default */
+ //hb_filter_decomb.settings = (char *) [[fPicSettingDecomb stringValue] UTF8String];
+ hb_list_add( job->filters, &hb_filter_decomb );
+ }
+ /* we add the custom string if present */
+ if ([fPictureController decomb] == 2)
+ {
+ /* use a custom decomb string */
+ hb_filter_decomb.settings = (char *) [[fPictureController decombCustomString] UTF8String];
+ hb_list_add( job->filters, &hb_filter_decomb );
+ }
+ }
+ else
+ {
+
+ /* Deinterlace */
+ if ([fPictureController deinterlace] == 1)
+ {
+ /* Run old deinterlacer fd by default */
+ hb_filter_deinterlace.settings = "-1";
+ hb_list_add( job->filters, &hb_filter_deinterlace );
+ }
+ else if ([fPictureController deinterlace] == 2)
+ {
+ /* Yadif mode 0 (without spatial deinterlacing.) */
+ hb_filter_deinterlace.settings = "2";
+ hb_list_add( job->filters, &hb_filter_deinterlace );
+ }
+ else if ([fPictureController deinterlace] == 3)
+ {
+ /* Yadif (with spatial deinterlacing) */
+ hb_filter_deinterlace.settings = "0";
+ hb_list_add( job->filters, &hb_filter_deinterlace );
+ }
+ else if ([fPictureController deinterlace] == 4)
+ {
+ /* we add the custom string if present */
+ hb_filter_deinterlace.settings = (char *) [[fPictureController deinterlaceCustomString] UTF8String];
+ hb_list_add( job->filters, &hb_filter_deinterlace );
+ }
+ }
+
+ /* Denoise */
+ if ([fPictureController denoise] == 1) // Weak in popup
+ {
+ hb_filter_denoise.settings = "2:1:2:3";
+ hb_list_add( job->filters, &hb_filter_denoise );
+ }
+ else if ([fPictureController denoise] == 2) // Medium in popup
+ {
+ hb_filter_denoise.settings = "3:2:2:3";
+ hb_list_add( job->filters, &hb_filter_denoise );
+ }
+ else if ([fPictureController denoise] == 3) // Strong in popup
+ {
+ hb_filter_denoise.settings = "7:7:5:5";
+ hb_list_add( job->filters, &hb_filter_denoise );
+ }
+ else if ([fPictureController denoise] == 4) // custom in popup
+ {
+ /* we add the custom string if present */
+ hb_filter_denoise.settings = (char *) [[fPictureController denoiseCustomString] UTF8String];
+ hb_list_add( job->filters, &hb_filter_denoise );
+ }
+
+ /* Deblock (uses pp7 default) */
+ /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
+ * the macgui's purposes a value of 0 actually means to not even use the filter
+ * current hb_filter_deblock.settings valid ranges are from 5 - 15
+ */
+ if ([fPictureController deblock] != 0)
+ {
+ NSString *deblockStringValue = [NSString stringWithFormat: @"%d",[fPictureController deblock]];
+ hb_filter_deblock.settings = (char *) [deblockStringValue UTF8String];
+ hb_list_add( job->filters, &hb_filter_deblock );
+ }
+
+}
+
+
+#pragma mark -
+#pragma mark Job Handling
+
+
+- (void) prepareJob
+{
+
+ NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
+ hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
+ hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
+ hb_job_t * job = title->job;
+ hb_audio_config_t * audio;
+ /* Title Angle for dvdnav */
+ job->angle = [[queueToApply objectForKey:@"TitleAngle"] intValue];
+ /* Chapter selection */
+ job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
+ job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
+
+ /* Format (Muxer) and Video Encoder */
+ job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
+ job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
+
+
+ /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
+ if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
+ {
+ job->largeFileSize = 1;
+ }
+ else
+ {
+ job->largeFileSize = 0;
+ }
+ /* We set http optimized mp4 here */
+ if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
+ {
+ job->mp4_optimize = 1;
+ }
+ else
+ {
+ job->mp4_optimize = 0;
+ }
+
+
+ /* We set the chapter marker extraction here based on the format being
+ mpeg4 or mkv and the checkbox being checked */
+ if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
+ {
+ job->chapter_markers = 1;
+
+ /* now lets get our saved chapter names out the array in the queue file
+ * and insert them back into the title chapter list. We have it here,
+ * because unless we are inserting chapter markers there is no need to
+ * spend the overhead of iterating through the chapter names array imo
+ * Also, note that if for some reason we don't apply chapter names, the
+ * chapters just come out 001, 002, etc. etc.
+ */
+
+ NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
+ int i = 0;
+ NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
+ id tempObject;
+ while (tempObject = [enumerator nextObject])
+ {
+ hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
+ if( chapter != NULL )
+ {
+ strncpy( chapter->title, [tempObject UTF8String], 1023);
+ chapter->title[1023] = '\0';
+ }
+ i++;
+ }
+ }
+ else
+ {
+ job->chapter_markers = 0;
+ }
+
+ if( job->vcodec & HB_VCODEC_X264 )
+ {
+ if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
+ {
+ job->ipod_atom = 1;
+ }
+ else
+ {
+ job->ipod_atom = 0;
+ }
+
+ /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
+ Currently only used with Constant Quality setting*/
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
+ {
+ job->crf = 1;
+ }
+ /* Below Sends x264 options to the core library if x264 is selected*/
+ /* Lets use this as per Nyx, Thanks Nyx!*/
+ job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
+ /* Turbo first pass if two pass and Turbo First pass is selected */
+ if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
+ {
+ /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
+ NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
+ /* append the "Turbo" string variable to the existing opts string.
+ Note: the "Turbo" string must be appended, not prepended to work properly*/
+ NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
+ strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
+ }
+ else
+ {
+ strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
+ }
+
+ }
+
+
+ /* Picture Size Settings */
+ job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
+ job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
+
+ job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
+ job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
+ if ([[queueToApply objectForKey:@"PicturePAR"] intValue] == 3)
+ {
+ /* insert our custom values here for capuj */
+ job->width = [[queueToApply objectForKey:@"PicturePARStorageWidth"] intValue];
+ job->height = [[queueToApply objectForKey:@"PicturePARStorageHeight"] intValue];
+
+ job->anamorphic.par_width = [[queueToApply objectForKey:@"PicturePARPixelWidth"] intValue];
+ job->anamorphic.par_height = [[queueToApply objectForKey:@"PicturePARPixelHeight"] intValue];
+
+ job->anamorphic.dar_width = [[queueToApply objectForKey:@"PicturePARDisplayWidth"] floatValue];
+ job->anamorphic.dar_height = [[queueToApply objectForKey:@"PicturePARDisplayHeight"] floatValue];
+ }
+
+ /* Here we use the crop values saved at the time the preset was saved */
+ job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
+ job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
+ job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
+ job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
+
+ /* Video settings */
+ /* Framerate */
+
+ /* Set vfr to 0 as it's only on if using same as source in the framerate popup
+ * and detelecine is on, so we handle that in the logic below
+ */
+ job->vfr = 0;
+ if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
+ {
+ /* a specific framerate has been chosen */
+ job->vrate = 27000000;
+ job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
+ /* We are not same as source so we set job->cfr to 1
+ * to enable constant frame rate since user has specified
+ * a specific framerate*/
+ job->cfr = 1;
+ }
+ else
+ {
+ /* We are same as source (variable) */
+ job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
+ job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
+ /* We are same as source so we set job->cfr to 0
+ * to enable true same as source framerate */
+ job->cfr = 0;
+ /* If we are same as source and we have detelecine on, we need to turn on
+ * job->vfr
+ */
+ if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
+ {
+ job->vfr = 1;
+ }
+ }
+
+ if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] != 2 )
+ {
+ /* Target size.
+ Bitrate should already have been calculated and displayed
+ in fVidBitrateField, so let's just use it same as abr*/
+ job->vquality = -1.0;
+ job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
+ }
+ if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
+ {
+ job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
+ job->vbitrate = 0;
+
+ }
+
+ job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
+
+
+
+#pragma mark -
+#pragma mark Process Subtitles to libhb
+
+/* Map the settings in the dictionaries for the SubtitleList array to match title->list_subtitle
+ * which means that we need to account for the offset of non source language settings in from
+ * the NSPopUpCell menu. For all of the objects in the SubtitleList array this means 0 is "None"
+ * from the popup menu, additionally the first track has "Foreign Audio Search" at 1. So we use
+ * an int to offset the index number for the objectForKey:@"subtitleSourceTrackNum" to map that
+ * to the source tracks position in title->list_subtitle.
+ */
+
+int subtitle = nil;
+int force;
+int burned;
+int def;
+bool one_burned = FALSE;
+
+ int i = 0;
+ NSEnumerator *enumerator = [[queueToApply objectForKey:@"SubtitleList"] objectEnumerator];
+ id tempObject;
+ while (tempObject = [enumerator nextObject])
+ {
+
+ subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
+ force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
+ burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
+ def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
+
+ /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
+ * we want to ignore it for display as well as encoding.
+ */
+ if (subtitle > 0)
+ {
+ /* if i is 0, then we are in the first item of the subtitles which we need to
+ * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
+ * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
+ */
+
+ /* if we are on the first track and using "Foreign Audio Search" */
+ if (i == 0 && subtitle == 1)
+ {
+ [self writeToActivityLog: "Foreign Language Search: %d", 1];
+
+ job->indepth_scan = 1;
+ if (burned == 1 || job->mux != HB_MUX_MP4)
+ {
+ if (burned != 1 && job->mux == HB_MUX_MKV)
+ {
+ job->select_subtitle_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
+ }
+ else
+ {
+ job->select_subtitle_config.dest = hb_subtitle_config_s::RENDERSUB;
+ }
+
+ job->select_subtitle_config.force = force;
+ job->select_subtitle_config.default_track = def;
+ }
+
+
+ }
+ else
+ {
+
+ /* for the actual source tracks, we must subtract the non source entries so
+ * that the menu index matches the source subtitle_list index for convenience */
+ if (i == 0)
+ {
+ /* for the first track, the source tracks start at menu index 2 ( None is 0,
+ * Foreign Language Search is 1) so subtract 2 */
+ subtitle = subtitle - 2;
+ }
+ else
+ {
+ /* for all other tracks, the source tracks start at menu index 1 (None is 0)
+ * so subtract 1. */
+
+ subtitle = subtitle - 1;
+ }
+
+ /* We are setting a source subtitle so access the source subtitle info */
+ hb_subtitle_t * subt;
+
+ subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
+
+ /* if we are getting the subtitles from an external srt file */
+ if ([[tempObject objectForKey:@"subtitleSourceTrackType"] isEqualToString:@"SRT"])
+ {
+ hb_subtitle_config_t sub_config;
+
+ sub_config.offset = [[tempObject objectForKey:@"subtitleTrackSrtOffset"] intValue];
+
+ /* we need to srncpy file name and codeset */
+ //sub_config.src_filename = [[tempObject objectForKey:@"subtitleSourceSrtFilePath"] UTF8String];
+ strncpy(sub_config.src_filename, [[tempObject objectForKey:@"subtitleSourceSrtFilePath"] UTF8String], 128);
+ //sub_config.src_codeset = [[tempObject objectForKey:@"subtitleTrackSrtCharCode"] UTF8String];
+ strncpy(sub_config.src_codeset, [[tempObject objectForKey:@"subtitleTrackSrtCharCode"] UTF8String], 40);
+
+ sub_config.force = 0;
+ sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
+ sub_config.default_track = def;
+
+ hb_srt_add( job, &sub_config, [[tempObject objectForKey:@"subtitleTrackSrtLanguageIso3"] UTF8String]);
+ }
+
+
+ if (subt != NULL)
+ {
+ [self writeToActivityLog: "Setting Subtitle: %s", subt];
+
+ hb_subtitle_config_t sub_config = subt->config;
+
+ if (!burned && job->mux == HB_MUX_MKV &&
+ subt->format == hb_subtitle_s::PICTURESUB)
+ {
+ sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
+ }
+ else if (!burned && job->mux == HB_MUX_MP4 &&
+ subt->format == hb_subtitle_s::PICTURESUB)
+ {
+ // Skip any non-burned vobsubs when output is mp4
+ continue;
+ }
+ else if ( burned && subt->format == hb_subtitle_s::PICTURESUB )
+ {
+ // Only allow one subtitle to be burned into the video
+ if (one_burned)
+ continue;
+ one_burned = TRUE;
+ }
+ sub_config.force = force;
+ sub_config.default_track = def;
+ hb_subtitle_add( job, &sub_config, subtitle );
+ }
+
+ }
+ }
+ i++;
+ }
+
+#pragma mark -
+
+
+ /* Audio tracks and mixdowns */
+ /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
+ int audiotrack_count = hb_list_count(job->list_audio);
+ for( int i = 0; i < audiotrack_count;i++)
+ {
+ hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
+ hb_list_rem(job->list_audio, temp_audio);
+ }
+ /* Now lets add our new tracks to the audio list here */
+ if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
+ {
+ audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
+ hb_audio_config_init(audio);
+ audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
+ /* We go ahead and assign values to our audio->out.<properties> */
+ audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
+ audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
+ audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
+ audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
+ audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
+ audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
+
+ hb_audio_add( job, audio );
+ free(audio);
+ }
+ if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
+ {
+
+ audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
+ hb_audio_config_init(audio);
+ audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
+ [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
+ /* We go ahead and assign values to our audio->out.<properties> */
+ audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
+ audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
+ audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
+ audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
+ audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
+ audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];