1 /* $Id: Controller.mm,v 1.79 2005/11/04 19:41:32 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
7 #include "Controller.h"
8 #include "a52dec/a52.h"
9 #import "HBOutputPanelController.h"
10 #import "HBPreferencesController.h"
11 /* Added to integrate scanning into HBController */
12 #include <IOKit/IOKitLib.h>
13 #include <IOKit/storage/IOMedia.h>
14 #include <IOKit/storage/IODVDMedia.h>
15 #include "HBDVDDetector.h"
16 #include "dvdread/dvd_reader.h"
18 #define _(a) NSLocalizedString(a,NULL)
20 static int FormatSettings[4][10] =
21 { { HB_MUX_MP4 | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
22 HB_MUX_MP4 | HB_VCODEC_X264 | HB_ACODEC_FAAC,
25 { HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
26 HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
27 HB_MUX_AVI | HB_VCODEC_X264 | HB_ACODEC_LAME,
28 HB_MUX_AVI | HB_VCODEC_X264 | HB_ACODEC_AC3},
29 { HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
30 HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
33 { HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
34 HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
35 HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
36 HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
37 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_FAAC,
38 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_AC3,
39 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_LAME,
40 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_VORBIS,
45 /* We setup the toolbar values here */
46 static NSString * ToggleDrawerIdentifier = @"Toggle Drawer Item Identifier";
47 static NSString * StartEncodingIdentifier = @"Start Encoding Item Identifier";
48 static NSString * PauseEncodingIdentifier = @"Pause Encoding Item Identifier";
49 static NSString * ShowQueueIdentifier = @"Show Queue Item Identifier";
50 static NSString * AddToQueueIdentifier = @"Add to Queue Item Identifier";
51 static NSString * ShowActivityIdentifier = @"Debug Output Item Identifier";
52 static NSString * ChooseSourceIdentifier = @"Choose Source Item Identifier";
55 * Returns the number of jobs groups in the queue.
56 * @param h Handle to hb_handle_t.
57 * @return Number of job groups.
59 static int hb_group_count(hb_handle_t * h)
64 while( ( job = hb_job( h, index++ ) ) )
66 if (job->sequence_id == 0)
72 /*******************************
73 * HBController implementation *
74 *******************************/
75 @implementation HBController
80 [HBPreferencesController registerUserDefaults];
82 outputPanel = [[HBOutputPanelController alloc] init];
83 fPictureController = [[PictureController alloc] initWithDelegate:self];
84 fQueueController = [[HBQueueController alloc] init];
85 fAdvancedOptions = [[HBAdvancedController alloc] init];
89 - (void) applicationDidFinishLaunching: (NSNotification *) notification
95 int debugLevel = [[NSUserDefaults standardUserDefaults] boolForKey:@"ShowVerboseOutput"] ? HB_DEBUG_ALL : HB_DEBUG_NONE;
96 fHandle = hb_init(debugLevel, [[NSUserDefaults standardUserDefaults] boolForKey:@"CheckForUpdates"]);
98 // Set the Growl Delegate
99 [GrowlApplicationBridge setGrowlDelegate: self];
100 /* Init others controllers */
101 [fPictureController SetHandle: fHandle];
102 [fQueueController setHandle: fHandle];
104 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
105 [fChapterTable setDataSource:fChapterTitlesDelegate];
107 /* Call UpdateUI every 1/2 sec */
108 [[NSRunLoop currentRunLoop] addTimer: [NSTimer
109 scheduledTimerWithTimeInterval: 0.5 target: self
110 selector: @selector( updateUI: ) userInfo: NULL repeats: YES]
111 forMode: NSEventTrackingRunLoopMode];
113 if( ( build = hb_check_update( fHandle, &version ) ) > -1 )
115 /* Update available - tell the user */
117 NSBeginInformationalAlertSheet( _( @"Update is available" ),
118 _( @"Go get it!" ), _( @"Discard" ), NULL, fWindow, self,
119 @selector( updateAlertDone:returnCode:contextInfo: ),
120 NULL, NULL, [NSString stringWithFormat:
121 _( @"HandBrake %s (build %d) is now available for download." ),
127 // Open debug output window now if it was visible when HB was closed
128 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
129 [self showDebugOutputPanel:nil];
131 // Open queue window now if it was visible when HB was closed
132 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
133 [self showQueueWindow:nil];
135 [self openMainWindow:nil];
137 /* Show scan panel ASAP */
138 [self performSelectorOnMainThread: @selector(showScanPanel:)
139 withObject: NULL waitUntilDone: NO];
142 - (NSApplicationTerminateReply) applicationShouldTerminate:
143 (NSApplication *) app
146 hb_get_state2( fHandle, &s );
147 if ( s.state == HB_STATE_WORKING )
150 return NSTerminateCancel;
152 return NSTerminateNow;
155 - (void)applicationWillTerminate:(NSNotification *)aNotification
157 [outputPanel release];
158 [fQueueController release];
163 - (void) awakeFromNib
166 [fWindow setExcludedFromWindowsMenu:YES];
167 [fAdvancedOptions setView:fAdvancedView];
169 /* Initialize currentScanCount so HB can use it to
170 evaluate successive scans */
171 currentScanCount = 0;
173 /* Init UserPresets .plist */
176 fRipIndicatorShown = NO; // initially out of view in the nib
178 /* Show/Dont Show Presets drawer upon launch based
179 on user preference DefaultPresetsDrawerShow*/
180 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
182 [fPresetDrawer open];
187 [fDstFormatPopUp removeAllItems];
188 [fDstFormatPopUp addItemWithTitle: _( @"MP4 file" )];
189 [fDstFormatPopUp addItemWithTitle: _( @"AVI file" )];
190 [fDstFormatPopUp addItemWithTitle: _( @"OGM file" )];
191 [fDstFormatPopUp addItemWithTitle: _( @"MKV file" )];
192 [fDstFormatPopUp selectItemAtIndex: 0];
194 [self formatPopUpChanged: NULL];
196 /* We enable the create chapters checkbox here since we are .mp4 */
197 [fCreateChapterMarkers setEnabled: YES];
198 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
200 [fCreateChapterMarkers setState: NSOnState];
206 [fDstFile2Field setStringValue: [NSString stringWithFormat:
207 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
210 [fVidEncoderPopUp removeAllItems];
211 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
212 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
217 [fVidTargetSizeField setIntValue: 700];
218 [fVidBitrateField setIntValue: 1000];
220 [fVidQualityMatrix selectCell: fVidBitrateCell];
221 [self videoMatrixChanged: NULL];
223 /* Video framerate */
224 [fVidRatePopUp removeAllItems];
225 [fVidRatePopUp addItemWithTitle: _( @"Same as source" )];
226 for( int i = 0; i < hb_video_rates_count; i++ )
228 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
230 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
231 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
233 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
235 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
236 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
238 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
240 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
241 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
245 [fVidRatePopUp addItemWithTitle:
246 [NSString stringWithCString: hb_video_rates[i].string]];
249 [fVidRatePopUp selectItemAtIndex: 0];
251 /* Picture Settings */
252 [fPicLabelPAROutputX setStringValue: @""];
253 [fPicSettingPARWidth setStringValue: @""];
254 [fPicSettingPARHeight setStringValue: @""];
256 /* Set Auto Crop to On at launch */
257 [fPictureController setAutoCrop:YES];
260 [fAudBitratePopUp removeAllItems];
261 for( int i = 0; i < hb_audio_bitrates_count; i++ )
263 [fAudBitratePopUp addItemWithTitle:
264 [NSString stringWithCString: hb_audio_bitrates[i].string]];
267 [fAudBitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
269 /* Audio samplerate */
270 [fAudRatePopUp removeAllItems];
271 for( int i = 0; i < hb_audio_rates_count; i++ )
273 [fAudRatePopUp addItemWithTitle:
274 [NSString stringWithCString: hb_audio_rates[i].string]];
276 [fAudRatePopUp selectItemAtIndex: hb_audio_rates_default];
279 [fStatusField setStringValue: @""];
284 [fPresetsActionButton setMenu:fPresetsActionMenu];
286 /* We disable the Turbo 1st pass checkbox since we are not x264 */
287 [fVidTurboPassCheck setEnabled: NO];
288 [fVidTurboPassCheck setState: NSOffState];
291 /* lets get our default prefs here */
292 [self getDefaultPresets: NULL];
293 /* lets initialize the current successful scancount here to 0 */
294 currentSuccessfulScanCount = 0;
298 - (void) loadPresets {
299 /* We declare the default NSFileManager into fileManager */
300 NSFileManager * fileManager = [NSFileManager defaultManager];
301 /* we set the files and support paths here */
302 AppSupportDirectory = @"~/Library/Application Support/HandBrake";
303 AppSupportDirectory = [AppSupportDirectory stringByExpandingTildeInPath];
304 //UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
305 //UserPresetsFile = [UserPresetsFile stringByExpandingTildeInPath];
306 /* We check for the app support directory for handbrake */
307 if ([fileManager fileExistsAtPath:AppSupportDirectory] == 0)
309 // If it doesnt exist yet, we create it here
310 [fileManager createDirectoryAtPath:AppSupportDirectory attributes:nil];
312 /* We check for the presets.plist here */
313 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
315 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
317 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
318 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
320 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
321 if (nil == UserPresets)
323 UserPresets = [[NSMutableArray alloc] init];
324 [self addFactoryPresets:NULL];
329 // ============================================================
330 // NSToolbar Related Methods
331 // ============================================================
333 - (void) setupToolbar {
334 toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
336 [toolbar setAllowsUserCustomization: YES];
337 [toolbar setAutosavesConfiguration: YES];
338 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
340 [toolbar setDelegate: self];
342 [fWindow setToolbar: toolbar];
345 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
346 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
347 NSToolbarItem * item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
349 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
351 [item setLabel: @"Toggle Presets"];
352 [item setPaletteLabel: @"Toggler Presets"];
353 [item setToolTip: @"Open/Close Preset Drawer"];
354 [item setImage: [NSImage imageNamed: @"Drawer-List2"]];
355 [item setTarget: self];
356 [item setAction: @selector(toggleDrawer:)];
357 [item setAutovalidates: NO];
359 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
361 [item setLabel: @"Start"];
362 [item setPaletteLabel: @"Start Encoding"];
363 [item setToolTip: @"Start Encoding"];
364 [item setImage: [NSImage imageNamed: @"Play"]];
365 [item setTarget: self];
366 [item setAction: @selector(Rip:)];
368 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
370 [item setLabel: @"Show Queue"];
371 [item setPaletteLabel: @"Show Queue"];
372 [item setToolTip: @"Show Queue"];
373 [item setImage: [NSImage imageNamed: @"Brushed Window"]];
374 [item setTarget: self];
375 [item setAction: @selector(showQueueWindow:)];
376 [item setAutovalidates: NO];
378 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
380 [item setLabel: @"Add to Queue"];
381 [item setPaletteLabel: @"Add to Queue"];
382 [item setToolTip: @"Add to Queue"];
383 [item setImage: [NSImage imageNamed: @"Add"]];
384 [item setTarget: self];
385 [item setAction: @selector(addToQueue:)];
387 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
389 [item setLabel: @"Pause"];
390 [item setPaletteLabel: @"Pause Encoding"];
391 [item setToolTip: @"Pause Encoding"];
392 [item setImage: [NSImage imageNamed: @"Pause"]];
393 [item setTarget: self];
394 [item setAction: @selector(Pause:)];
396 else if ([itemIdent isEqualToString: ShowActivityIdentifier]) {
397 [item setLabel: @"Activity Window"];
398 [item setPaletteLabel: @"Show Activity Window"];
399 [item setToolTip: @"Show Activity Window"];
400 [item setImage: [NSImage imageNamed: @"Terminal"]];
401 [item setTarget: self];
402 [item setAction: @selector(showDebugOutputPanel:)];
403 [item setAutovalidates: NO];
405 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
407 [item setLabel: @"Source"];
408 [item setPaletteLabel: @"Source"];
409 [item setToolTip: @"Choose Video Source"];
410 [item setImage: [NSImage imageNamed: @"Disc"]];
411 [item setTarget: self];
412 [item setAction: @selector(showScanPanel:)];
413 [item setAutovalidates: NO];
424 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
426 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
427 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
428 NSToolbarSpaceItemIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
431 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
433 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
434 ChooseSourceIdentifier, ShowQueueIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
435 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSpaceItemIdentifier,
436 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
439 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
441 NSString * ident = [toolbarItem itemIdentifier];
446 hb_get_state2( fHandle, &s );
448 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
450 if ([ident isEqualToString: StartEncodingIdentifier])
452 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
453 [toolbarItem setLabel: @"Cancel"];
454 [toolbarItem setPaletteLabel: @"Cancel"];
455 [toolbarItem setToolTip: @"Cancel Encoding"];
458 if ([ident isEqualToString: PauseEncodingIdentifier])
460 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
461 [toolbarItem setLabel: @"Pause"];
462 [toolbarItem setPaletteLabel: @"Pause Encoding"];
463 [toolbarItem setToolTip: @"Pause Encoding"];
467 if ([ident isEqualToString: AddToQueueIdentifier])
470 else if (s.state == HB_STATE_PAUSED)
472 if ([ident isEqualToString: PauseEncodingIdentifier])
474 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
475 [toolbarItem setLabel: @"Resume"];
476 [toolbarItem setPaletteLabel: @"Resume Encoding"];
477 [toolbarItem setToolTip: @"Resume Encoding"];
480 if ([ident isEqualToString: StartEncodingIdentifier])
482 if ([ident isEqualToString: AddToQueueIdentifier])
485 else if (s.state == HB_STATE_SCANNING)
487 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
489 if ([ident isEqualToString: StartEncodingIdentifier])
491 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
492 [toolbarItem setLabel: @"Start"];
493 [toolbarItem setPaletteLabel: @"Start Encoding"];
494 [toolbarItem setToolTip: @"Start Encoding"];
497 if ([ident isEqualToString: AddToQueueIdentifier])
503 if ([ident isEqualToString: ShowQueueIdentifier])
505 if ([ident isEqualToString: ToggleDrawerIdentifier])
507 if ([ident isEqualToString: ChooseSourceIdentifier])
509 if ([ident isEqualToString: ShowActivityIdentifier])
515 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
517 SEL action = [menuItem action];
520 hb_get_state2( fHandle, &s );
524 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
525 return SuccessfulScan && [fWindow attachedSheet] == nil;
527 if (action == @selector(showScanPanel:))
529 if (s.state == HB_STATE_SCANNING)
532 return [fWindow attachedSheet] == nil;
534 if (action == @selector(selectDefaultPreset:))
535 return [tableView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
536 if (action == @selector(Pause:))
538 if (s.state == HB_STATE_WORKING)
540 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
541 [menuItem setTitle:@"Pause Encoding"];
544 else if (s.state == HB_STATE_PAUSED)
546 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
547 [menuItem setTitle:@"Resume Encoding"];
553 if (action == @selector(Rip:))
554 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
556 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
557 [menuItem setTitle:@"Stop Encoding"];
560 else if (SuccessfulScan)
562 if(![[menuItem title] isEqualToString:@"Start Encoding"])
563 [menuItem setTitle:@"Start Encoding"];
564 return [fWindow attachedSheet] == nil;
574 // register a test notification and make
575 // it enabled by default
576 #define SERVICE_NAME @"Encode Done"
577 - (NSDictionary *)registrationDictionaryForGrowl
579 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
580 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
581 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
584 return registrationDictionary;
587 - (void) TranslateStrings
589 [fSrcTitleField setStringValue: _( @"Title:" )];
590 [fSrcChapterField setStringValue: _( @"Chapters:" )];
591 [fSrcChapterToField setStringValue: _( @"to" )];
592 [fSrcDuration1Field setStringValue: _( @"Duration:" )];
594 [fDstFormatField setStringValue: _( @"Format:" )];
595 [fDstCodecsField setStringValue: _( @"Codecs:" )];
596 [fDstFile1Field setStringValue: _( @"File:" )];
597 [fDstBrowseButton setTitle: _( @"Browse" )];
599 [fVidRateField setStringValue: _( @"Framerate (fps):" )];
600 [fVidEncoderField setStringValue: _( @"Encoder:" )];
601 [fVidQualityField setStringValue: _( @"Quality:" )];
604 /***********************************************************************
606 ***********************************************************************
607 * Shows a progression bar on the dock icon, filled according to
608 * 'progress' (0.0 <= progress <= 1.0).
609 * Called with progress < 0.0 or progress > 1.0, restores the original
611 **********************************************************************/
612 - (void) UpdateDockIcon: (float) progress
616 NSBitmapImageRep * bmp;
618 uint32_t black = htonl( 0x000000FF );
619 uint32_t red = htonl( 0xFF0000FF );
620 uint32_t white = htonl( 0xFFFFFFFF );
621 int row_start, row_end;
624 /* Get application original icon */
625 icon = [NSImage imageNamed: @"NSApplicationIcon"];
627 if( progress < 0.0 || progress > 1.0 )
629 [NSApp setApplicationIconImage: icon];
633 /* Get it in a raw bitmap form */
634 tiff = [icon TIFFRepresentationUsingCompression:
635 NSTIFFCompressionNone factor: 1.0];
636 bmp = [NSBitmapImageRep imageRepWithData: tiff];
638 /* Draw the progression bar */
639 /* It's pretty simple (ugly?) now, but I'm no designer */
641 row_start = 3 * (int) [bmp size].height / 4;
642 row_end = 7 * (int) [bmp size].height / 8;
644 for( i = row_start; i < row_start + 2; i++ )
646 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
647 for( j = 0; j < (int) [bmp size].width; j++ )
652 for( i = row_start + 2; i < row_end - 2; i++ )
654 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
657 for( j = 2; j < (int) [bmp size].width - 2; j++ )
659 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
671 for( i = row_end - 2; i < row_end; i++ )
673 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
674 for( j = 0; j < (int) [bmp size].width; j++ )
680 /* Now update the dock icon */
681 tiff = [bmp TIFFRepresentationUsingCompression:
682 NSTIFFCompressionNone factor: 1.0];
683 icon = [[NSImage alloc] initWithData: tiff];
684 [NSApp setApplicationIconImage: icon];
688 - (void) updateUI: (NSTimer *) timer
692 list = hb_get_titles( fHandle );
693 /* check to see if there has been a new scan done
694 this bypasses the constraints of HB_STATE_WORKING
695 not allowing setting a newly scanned source */
696 int checkScanCount = hb_get_scancount( fHandle );
697 if (checkScanCount > currentScanCount)
700 currentScanCount = checkScanCount;
701 //[fScanController Cancel: NULL];
702 [fScanIndicator setIndeterminate: NO];
703 [fScanIndicator setDoubleValue: 0.0];
704 [fScanIndicator setHidden: YES];
706 [self showNewScan: NULL];
709 BOOL jobGroups = [[NSUserDefaults standardUserDefaults] boolForKey:@"QueueShowsJobsAsGroups"];
712 hb_get_state( fHandle, &s );
719 #define p s.param.scanning
720 case HB_STATE_SCANNING:
722 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
723 _( @"Scanning title %d of %d..." ),
724 p.title_cur, p.title_count]];
725 [fScanIndicator setIndeterminate: NO];
726 [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) /
732 #define p s.param.scandone
733 case HB_STATE_SCANDONE:
736 [fScanIndicator setIndeterminate: NO];
737 [fScanIndicator setDoubleValue: 0.0];
738 [fScanIndicator setHidden: YES];
739 [self showNewScan: NULL];
740 [toolbar validateVisibleItems];
745 #define p s.param.working
746 case HB_STATE_WORKING:
748 float progress_total;
749 NSMutableString * string;
750 /* Currently, p.job_cur and p.job_count get screwed up when adding
751 jobs during encoding, if they cannot be fixed in libhb, will implement a
752 nasty but working cocoa solution */
753 /* Update text field */
754 string = [NSMutableString stringWithFormat: _( @"Encoding: task %d of %d, %.2f %%" ), p.job_cur, p.job_count, 100.0 * p.progress];
758 [string appendFormat:
759 _( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)" ),
760 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
762 [fStatusField setStringValue: string];
765 progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
766 [fRipIndicator setIndeterminate: NO];
767 [fRipIndicator setDoubleValue: 100.0 * progress_total];
769 // If progress bar hasn't been revealed at the bottom of the window, do
770 // that now. This code used to be in _Rip. I moved it to here to handle
771 // the case where hb_start is called by HBQueueController and not from
773 if (!fRipIndicatorShown)
775 NSRect frame = [fWindow frame];
776 if (frame.size.width <= 591)
777 frame.size.width = 591;
778 frame.size.height += 36;
779 frame.origin.y -= 36;
780 [fWindow setFrame:frame display:YES animate:YES];
781 fRipIndicatorShown = YES;
784 /* Update dock icon */
785 [self UpdateDockIcon: progress_total];
787 // Has current job changed? That means the queue has probably changed as
789 if (fLastKnownCurrentJob != hb_current_job(fHandle))
791 fLastKnownCurrentJob = hb_current_job(fHandle);
792 [fQueueController updateQueueUI];
794 [fQueueController updateCurrentJobUI];
800 #define p s.param.muxing
801 case HB_STATE_MUXING:
803 NSMutableString * string;
805 /* Update text field */
806 string = [NSMutableString stringWithFormat:
808 [fStatusField setStringValue: string];
811 [fRipIndicator setIndeterminate: YES];
812 [fRipIndicator startAnimation: nil];
814 /* Update dock icon */
815 [self UpdateDockIcon: 1.0];
817 // Pass along the info to HBQueueController
818 [fQueueController updateCurrentJobUI];
824 case HB_STATE_PAUSED:
825 [fStatusField setStringValue: _( @"Paused" )];
827 // Pass along the info to HBQueueController
828 [fQueueController updateCurrentJobUI];
832 case HB_STATE_WORKDONE:
834 [fStatusField setStringValue: _( @"Done." )];
835 [fRipIndicator setIndeterminate: NO];
836 [fRipIndicator setDoubleValue: 0.0];
837 [toolbar validateVisibleItems];
839 /* Restore dock icon */
840 [self UpdateDockIcon: -1.0];
844 // Delete all remaining scans of this job
846 while( ( job = hb_job( fHandle, 0 ) ) && (job->sequence_id != 0) )
847 hb_rem( fHandle, job );
850 // Start processing back up if jobs still left in queue
851 if (hb_count(fHandle) > 0)
857 if (fRipIndicatorShown)
859 NSRect frame = [fWindow frame];
860 if (frame.size.width <= 591)
861 frame.size.width = 591;
862 frame.size.height += -36;
863 frame.origin.y -= -36;
864 [fWindow setFrame:frame display:YES animate:YES];
865 fRipIndicatorShown = NO;
868 // Queue has been modified so update the UI
869 fLastKnownCurrentJob = nil;
870 [fQueueController updateQueueUI];
871 [fQueueController updateCurrentJobUI];
873 /* Check to see if the encode state has not been cancelled
874 to determine if we should check for encode done notifications */
875 if (fEncodeState != 2) {
876 /* If Growl Notification or Window and Growl has been selected */
877 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
878 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
880 /*Growl Notification*/
881 [self showGrowlDoneNotification: NULL];
883 /* If Alert Window or Window and Growl has been selected */
884 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
885 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
887 /*On Screen Notification*/
890 status = NSRunAlertPanel(@"Put down that cocktail...",@"your HandBrake encode is done!", @"OK", nil, nil);
891 [NSApp requestUserAttention:NSCriticalRequest];
892 if ( status == NSAlertDefaultReturn )
894 [self enableUI: YES];
899 [self enableUI: YES];
901 /* If sleep has been selected */
902 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
905 NSDictionary* errorDict;
906 NSAppleEventDescriptor* returnDescriptor = NULL;
907 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
908 @"tell application \"Finder\" to sleep"];
909 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
910 [scriptObject release];
911 [self enableUI: YES];
913 /* If Shutdown has been selected */
914 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
917 NSDictionary* errorDict;
918 NSAppleEventDescriptor* returnDescriptor = NULL;
919 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
920 @"tell application \"Finder\" to shut down"];
921 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
922 [scriptObject release];
923 [self enableUI: YES];
926 // MetaX insertion via AppleScript
927 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
929 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", [fDstFile2Field stringValue], @"\")"]];
930 [myScript executeAndReturnError: nil];
938 [self enableUI: YES];
944 /* Lets show the queue status here in the main window */
945 int queue_count = jobGroups ? hb_group_count( fHandle ) : hb_count( fHandle );
948 [fQueueStatus setStringValue: [NSString stringWithFormat:
949 @"%d task%s in the queue",
950 queue_count, ( queue_count > 1 ) ? "s" : ""]];
954 [fQueueStatus setStringValue: @""];
958 - (IBAction) showNewScan:(id)sender
962 int indxpri=0; // Used to search the longuest title (default in combobox)
963 int longuestpri=0; // Used to search the longuest title (default in combobox)
965 list = hb_get_titles( fHandle );
967 if( !hb_list_count( list ) )
969 /* We display a message if a valid dvd source was not chosen */
970 [fSrcDVD2Field setStringValue: @"No Valid Title Found"];
975 /* We increment the successful scancount here by one,
976 which we use at the end of this function to tell the gui
977 if this is the first successful scan since launch and whether
978 or not we should set all settings to the defaults */
981 currentSuccessfulScanCount++;
983 [self enableUI: YES];
985 [toolbar validateVisibleItems];
987 [fSrcTitlePopUp removeAllItems];
988 for( int i = 0; i < hb_list_count( list ); i++ )
990 title = (hb_title_t *) hb_list_item( list, i );
991 /*Set DVD Name at top of window*/
992 [fSrcDVD2Field setStringValue:[NSString stringWithUTF8String: title->name]];
994 currentSource = [NSString stringWithUTF8String: title->dvd];
997 /* Use the dvd name in the default output field here
998 May want to add code to remove blank spaces for some dvd names*/
999 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1000 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1002 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1003 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[NSString
1004 stringWithUTF8String: title->name]]];
1008 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1009 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[NSString
1010 stringWithUTF8String: title->name]]];
1014 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1016 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1021 int format = [fDstFormatPopUp indexOfSelectedItem];
1027 /*Get Default MP4 File Extension for mpeg4 (.mp4 or .m4v) from prefs*/
1028 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1049 NSString * string = [fDstFile2Field stringValue];
1050 /* Add/replace File Output name to the correct extension*/
1051 if( [string characterAtIndex: [string length] - 4] == '.' )
1053 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1054 @"%@.%s", [string substringToIndex: [string length] - 4],
1059 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1060 @"%@.%s", string, ext]];
1064 [fSrcTitlePopUp addItemWithTitle: [NSString
1065 stringWithFormat: @"%d - %02dh%02dm%02ds",
1066 title->index, title->hours, title->minutes,
1070 // Select the longuest title
1071 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1072 [self titlePopUpChanged: NULL];
1076 [self enableUI: YES];
1078 /* we record the current source name here in case the next scan is unsuccessful,
1079 then we can replace the scan progress with the old name if necessary */
1080 sourceDisplayName = [NSString stringWithFormat:[fSrcDVD2Field stringValue]];
1082 /* if its the initial successful scan after awakeFromNib */
1083 if (currentSuccessfulScanCount == 1)
1085 [self selectDefaultPreset: NULL];
1086 /* if Deinterlace upon launch is specified in the prefs, then set to 1 for "Fast",
1087 if not, then set to 0 for none */
1088 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1089 [fPictureController setDeinterlace:1];
1091 [fPictureController setDeinterlace:0];
1097 -(IBAction)showGrowlDoneNotification:(id)sender
1099 [GrowlApplicationBridge
1100 notifyWithTitle:@"Put down that cocktail..."
1101 description:@"your HandBrake encode is done!"
1102 notificationName:SERVICE_NAME
1109 - (void) enableUI: (bool) b
1111 NSControl * controls[] =
1112 { fSrcTitleField, fSrcTitlePopUp,
1113 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
1114 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
1115 fDstFormatField, fDstFormatPopUp, fDstCodecsField,
1116 fDstCodecsPopUp, fDstFile1Field, fDstFile2Field,
1117 fDstBrowseButton, fVidRateField, fVidRatePopUp,
1118 fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
1119 fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
1120 fAudLang1Field, fAudLang1PopUp, fAudLang2Field, fAudLang2PopUp,
1121 fAudTrack1MixLabel, fAudTrack1MixPopUp, fAudTrack2MixLabel, fAudTrack2MixPopUp,
1122 fAudRateField, fAudRatePopUp, fAudBitrateField,
1123 fAudBitratePopUp, fPictureButton,fQueueStatus,
1124 fPicSrcWidth,fPicSrcHeight,fPicSettingWidth,fPicSettingHeight,fPicSettingARkeep,
1125 fPicSettingDeinterlace,fPicLabelSettings,fPicLabelSrc,fPicLabelOutp,
1126 fPicLabelAr,fPicLabelDeinterlace,fPicLabelSrcX,fPicLabelOutputX,
1127 fPicLabelPAROutputX,fPicSettingPARWidth,fPicSettingPARHeight,
1128 fPicSettingPAR,fPicLabelAnamorphic,tableView,fPresetsAdd,fPresetsDelete,
1129 fCreateChapterMarkers,fVidTurboPassCheck,fDstMpgLargeFileCheck,fPicLabelAutoCrop,
1130 fPicSettingAutoCrop,fPicSettingDetelecine,fPicLabelDetelecine,fPicLabelDenoise,fPicSettingDenoise,fSubForcedCheck,};
1132 for( unsigned i = 0;
1133 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
1135 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
1137 NSTextField * tf = (NSTextField *) controls[i];
1138 if( ![tf isBezeled] )
1140 [tf setTextColor: b ? [NSColor controlTextColor] :
1141 [NSColor disabledControlTextColor]];
1145 [controls[i] setEnabled: b];
1151 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
1152 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
1153 [self setEnabledStateOfAudioMixdownControls: NULL];
1157 [tableView setEnabled: NO];
1161 [self videoMatrixChanged: NULL];
1162 [fAdvancedOptions enableUI:b];
1165 - (IBAction) showScanPanel: (id) sender
1167 [self enableUI: NO];
1169 [self browseSources:NULL];
1172 - (void) browseSources: (id) sender
1174 NSOpenPanel * panel;
1176 panel = [NSOpenPanel openPanel];
1177 [panel setAllowsMultipleSelection: NO];
1178 [panel setCanChooseFiles: YES];
1179 [panel setCanChooseDirectories: YES ];
1180 NSString * sourceDirectory;
1181 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1183 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1187 sourceDirectory = @"~/Desktop";
1188 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1190 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1191 modalForWindow: fWindow modalDelegate: self
1192 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1196 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1197 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1199 /* User selected a file to open */
1200 if( returnCode == NSOKButton )
1202 [fSrcDVD2Field setStringValue: _( @"Opening a new source ..." )];
1203 [fScanIndicator setHidden: NO];
1204 [fScanIndicator setIndeterminate: YES];
1205 [fScanIndicator startAnimation: nil];
1207 /* we set the last source directory in the prefs here */
1208 NSString *sourceDirectory = [[[sheet filenames] objectAtIndex: 0] stringByDeletingLastPathComponent];
1209 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1211 NSString *path = [[sheet filenames] objectAtIndex: 0];
1212 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1213 if( [detector isVideoDVD] )
1215 // The chosen path was actually on a DVD, so use the raw block
1216 // device path instead.
1217 path = [detector devicePath];
1220 hb_scan( fHandle, [path UTF8String], 0 );
1222 else // User clicked Cancel in browse window
1224 /* if we have a title loaded up */
1225 if ([[fSrcDVD2Field stringValue] length] > 0)
1227 [self enableUI: YES];
1232 - (IBAction) openMainWindow: (id) sender
1234 [fWindow makeKeyAndOrderFront:nil];
1235 [fWindow setReleasedWhenClosed: YES];
1238 - (BOOL) windowShouldClose: (id) sender
1240 [fWindow setReleasedWhenClosed: NO];
1244 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1247 [fWindow makeKeyAndOrderFront:nil];
1248 [fWindow setReleasedWhenClosed: YES];
1256 - (IBAction) videoMatrixChanged: (id) sender;
1258 bool target, bitrate, quality;
1260 target = bitrate = quality = false;
1261 if( [fVidQualityMatrix isEnabled] )
1263 switch( [fVidQualityMatrix selectedRow] )
1276 [fVidTargetSizeField setEnabled: target];
1277 [fVidBitrateField setEnabled: bitrate];
1278 [fVidQualitySlider setEnabled: quality];
1279 [fVidTwoPassCheck setEnabled: !quality &&
1280 [fVidQualityMatrix isEnabled]];
1283 [fVidTwoPassCheck setState: NSOffState];
1284 [fVidTurboPassCheck setHidden: YES];
1285 [fVidTurboPassCheck setState: NSOffState];
1288 [self qualitySliderChanged: sender];
1289 [self calculateBitrate: sender];
1290 [self customSettingUsed: sender];
1293 - (IBAction) qualitySliderChanged: (id) sender
1295 [fVidConstantCell setTitle: [NSString stringWithFormat:
1296 _( @"Constant quality: %.0f %%" ), 100.0 *
1297 [fVidQualitySlider floatValue]]];
1298 [self customSettingUsed: sender];
1301 - (IBAction) browseFile: (id) sender
1303 /* Open a panel to let the user choose and update the text field */
1304 NSSavePanel * panel = [NSSavePanel savePanel];
1305 /* We get the current file name and path from the destination field here */
1306 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1307 modalForWindow: fWindow modalDelegate: self
1308 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1312 - (void) browseFileDone: (NSSavePanel *) sheet
1313 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1315 if( returnCode == NSOKButton )
1317 [fDstFile2Field setStringValue: [sheet filename]];
1321 - (IBAction) showPicturePanel: (id) sender
1323 hb_list_t * list = hb_get_titles( fHandle );
1324 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1325 [fSrcTitlePopUp indexOfSelectedItem] );
1326 [fPictureController showPanelInWindow:fWindow forTitle:title];
1329 - (void)pictureSettingsDidChange {
1330 [self calculatePictureSizing: NULL];
1335 hb_list_t * list = hb_get_titles( fHandle );
1336 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1337 [fSrcTitlePopUp indexOfSelectedItem] );
1338 hb_job_t * job = title->job;
1341 /* Chapter selection */
1342 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
1343 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
1345 /* Format and codecs */
1346 int format = [fDstFormatPopUp indexOfSelectedItem];
1347 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1348 job->mux = FormatSettings[format][codecs] & HB_MUX_MASK;
1349 job->vcodec = FormatSettings[format][codecs] & HB_VCODEC_MASK;
1350 job->acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
1351 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
1352 if ([fDstFormatPopUp indexOfSelectedItem] == 0)
1354 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
1355 mpeg4 and the checkbox being checked
1356 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
1357 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0 && [fDstMpgLargeFileCheck state] == NSOnState)
1359 job->largeFileSize = 1;
1363 job->largeFileSize = 0;
1366 if ([fDstFormatPopUp indexOfSelectedItem] == 0 || [fDstFormatPopUp indexOfSelectedItem] == 3)
1368 /* We set the chapter marker extraction here based on the format being
1369 mpeg4 or mkv and the checkbox being checked */
1370 if ([fCreateChapterMarkers state] == NSOnState)
1372 job->chapter_markers = 1;
1376 job->chapter_markers = 0;
1379 if( ( job->vcodec & HB_VCODEC_FFMPEG ) &&
1380 [fVidEncoderPopUp indexOfSelectedItem] > 0 )
1382 job->vcodec = HB_VCODEC_XVID;
1384 if( job->vcodec & HB_VCODEC_X264 )
1386 if ([fVidEncoderPopUp indexOfSelectedItem] > 0 )
1388 /* Just use new Baseline Level 3.0
1389 Lets Deprecate Baseline Level 1.3h264_level*/
1390 job->h264_level = 30;
1391 job->mux = HB_MUX_IPOD;
1392 /* move sanity check for iPod Encoding here */
1393 job->pixel_ratio = 0 ;
1397 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
1398 Currently only used with Constant Quality setting*/
1399 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
1404 /* Below Sends x264 options to the core library if x264 is selected*/
1405 /* Lets use this as per Nyx, Thanks Nyx!*/
1406 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1407 /* Turbo first pass if two pass and Turbo First pass is selected */
1408 if( [fVidTwoPassCheck state] == NSOnState && [fVidTurboPassCheck state] == NSOnState )
1410 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
1411 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0";
1412 /* append the "Turbo" string variable to the existing opts string.
1413 Note: the "Turbo" string must be appended, not prepended to work properly*/
1414 NSString *firstPassOptStringCombined = [[fAdvancedOptions optionsString] stringByAppendingString:firstPassOptStringTurbo];
1415 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
1419 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
1422 job->h264_13 = [fVidEncoderPopUp indexOfSelectedItem];
1425 /* Video settings */
1426 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
1428 job->vrate = 27000000;
1429 job->vrate_base = hb_video_rates[[fVidRatePopUp
1430 indexOfSelectedItem]-1].rate;
1434 job->vrate = title->rate;
1435 job->vrate_base = title->rate_base;
1438 switch( [fVidQualityMatrix selectedRow] )
1442 Bitrate should already have been calculated and displayed
1443 in fVidBitrateField, so let's just use it */
1445 job->vquality = -1.0;
1446 job->vbitrate = [fVidBitrateField intValue];
1449 job->vquality = [fVidQualitySlider floatValue];
1454 job->grayscale = ( [fVidGrayscaleCheck state] == NSOnState );
1456 /* Subtitle settings */
1457 job->subtitle = [fSubPopUp indexOfSelectedItem] - 2;
1459 /* Audio tracks and mixdowns */
1460 /* check for the condition where track 2 has an audio selected, but track 1 does not */
1461 /* we will use track 2 as track 1 in this scenario */
1462 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1464 job->audios[0] = [fAudLang1PopUp indexOfSelectedItem] - 1;
1465 job->audios[1] = [fAudLang2PopUp indexOfSelectedItem] - 1; /* will be -1 if "none" is selected */
1466 job->audios[2] = -1;
1467 job->audio_mixdowns[0] = [[fAudTrack1MixPopUp selectedItem] tag];
1468 job->audio_mixdowns[1] = [[fAudTrack2MixPopUp selectedItem] tag];
1470 else if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1472 job->audios[0] = [fAudLang2PopUp indexOfSelectedItem] - 1;
1473 job->audio_mixdowns[0] = [[fAudTrack2MixPopUp selectedItem] tag];
1474 job->audios[1] = -1;
1478 job->audios[0] = -1;
1481 /* Audio settings */
1482 job->arate = hb_audio_rates[[fAudRatePopUp
1483 indexOfSelectedItem]].rate;
1484 job->abitrate = [[fAudBitratePopUp selectedItem] tag];
1486 job->filters = hb_list_init();
1489 if ([fPictureController detelecine])
1491 hb_list_add( job->filters, &hb_filter_detelecine );
1495 if ([fPictureController deinterlace] == 1)
1497 /* Run old deinterlacer by default */
1498 hb_filter_deinterlace.settings = "-1";
1499 hb_list_add( job->filters, &hb_filter_deinterlace );
1501 else if ([fPictureController deinterlace] == 2)
1503 /* Yadif mode 0 (1-pass with spatial deinterlacing.) */
1504 hb_filter_deinterlace.settings = "0";
1505 hb_list_add( job->filters, &hb_filter_deinterlace );
1507 else if ([fPictureController deinterlace] == 3)
1509 /* Yadif (1-pass w/o spatial deinterlacing) and Mcdeint */
1510 hb_filter_deinterlace.settings = "2:-1:1";
1511 hb_list_add( job->filters, &hb_filter_deinterlace );
1513 else if ([fPictureController deinterlace] == 4)
1515 /* Yadif (2-pass w/ spatial deinterlacing) and Mcdeint*/
1516 hb_filter_deinterlace.settings = "1:-1:1";
1517 hb_list_add( job->filters, &hb_filter_deinterlace );
1522 if ([fPictureController denoise] == 1) // Weak in popup
1524 hb_filter_denoise.settings = "2:1:2:3";
1525 hb_list_add( job->filters, &hb_filter_denoise );
1527 else if ([fPictureController denoise] == 2) // Medium in popup
1529 hb_filter_denoise.settings = "3:2:2:3";
1530 hb_list_add( job->filters, &hb_filter_denoise );
1532 else if ([fPictureController denoise] == 3) // Strong in popup
1534 hb_filter_denoise.settings = "7:7:5:5";
1535 hb_list_add( job->filters, &hb_filter_denoise );
1542 - (IBAction) addToQueue: (id) sender
1544 /* We get the destination directory from the destingation field here */
1545 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1546 /* We check for a valid destination here */
1547 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
1549 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1554 hb_list_t * list = hb_get_titles( fHandle );
1555 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1556 [fSrcTitlePopUp indexOfSelectedItem] );
1557 hb_job_t * job = title->job;
1559 // Assign a sequence number, starting at zero, to each job added so they can
1560 // be lumped together in the UI.
1561 job->sequence_id = -1;
1565 /* Destination file */
1566 job->file = [[fDstFile2Field stringValue] UTF8String];
1568 if( [fSubForcedCheck state] == NSOnState )
1570 job->subtitle_force = 1;
1572 job->subtitle_force = 0;
1576 * subtitle of -1 is a scan
1578 if( job->subtitle == -1 )
1583 * When subtitle scan is enabled do a fast pre-scan job
1584 * which will determine which subtitles to enable, if any.
1587 x264opts_tmp = job->x264opts;
1590 job->x264opts = NULL;
1592 job->subtitle_scan = 1;
1594 job->select_subtitle = (hb_subtitle_t**)malloc(sizeof(hb_subtitle_t*));
1595 *(job->select_subtitle) = NULL;
1598 * Add the pre-scan job
1600 job->sequence_id++; // for job grouping
1601 hb_add( fHandle, job );
1603 job->x264opts = x264opts_tmp;
1605 job->select_subtitle = NULL;
1608 /* No subtitle were selected, so reset the subtitle to -1 (which before
1609 * this point meant we were scanning
1611 if( job->subtitle == -2 )
1616 if( [fVidTwoPassCheck state] == NSOnState )
1618 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
1619 job->select_subtitle = NULL;
1620 job->subtitle_scan = 0;
1623 job->sequence_id++; // for job grouping
1624 hb_add( fHandle, job );
1627 job->sequence_id++; // for job grouping
1629 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1630 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
1632 job->select_subtitle = subtitle_tmp;
1634 hb_add( fHandle, job );
1638 job->subtitle_scan = 0;
1640 job->sequence_id++; // for job grouping
1641 hb_add( fHandle, job );
1644 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1645 /* Lets try to update stuff, taken from remove in the queue controller */
1646 [fQueueController performSelectorOnMainThread: @selector( updateQueueUI )
1647 withObject: NULL waitUntilDone: NO];
1651 - (IBAction) Rip: (id) sender
1653 /* Rip or Cancel ? */
1655 hb_get_state2( fHandle, &s );
1657 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
1659 [self Cancel: sender];
1662 /* if there is no job in the queue, then add it to the queue and rip
1663 otherwise, there are already jobs in queue, so just rip the queue */
1664 int count = hb_count( fHandle );
1667 [self addToQueue: sender];
1670 /* We check for duplicate name here */
1671 if( [[NSFileManager defaultManager] fileExistsAtPath:
1672 [fDstFile2Field stringValue]] )
1674 NSBeginCriticalAlertSheet( _( @"File already exists" ),
1675 _( @"Cancel" ), _( @"Overwrite" ), NULL, fWindow, self,
1676 @selector( overWriteAlertDone:returnCode:contextInfo: ),
1677 NULL, NULL, [NSString stringWithFormat:
1678 _( @"Do you want to overwrite %@?" ),
1679 [fDstFile2Field stringValue]] );
1682 /* We get the destination directory from the destination field here */
1683 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1684 /* We check for a valid destination here */
1685 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
1687 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1691 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1699 - (void) overWriteAlertDone: (NSWindow *) sheet
1700 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1702 if( returnCode == NSAlertAlternateReturn )
1708 - (void) updateAlertDone: (NSWindow *) sheet
1709 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1711 if( returnCode == NSAlertAlternateReturn )
1713 /* Show scan panel */
1714 [self performSelectorOnMainThread: @selector(showScanPanel:)
1715 withObject: NULL waitUntilDone: NO];
1719 /* Go to HandBrake homepage and exit */
1720 [self openHomepage: NULL];
1721 [NSApp terminate: self];
1726 /* Let libhb do the job */
1727 hb_start( fHandle );
1728 /*set the fEncodeState State */
1732 - (IBAction) Cancel: (id) sender
1734 NSBeginCriticalAlertSheet( _( @"Cancel - Are you sure?" ),
1735 _( @"Keep working" ), _( @"Cancel encoding" ), NULL, fWindow, self,
1736 @selector( _Cancel:returnCode:contextInfo: ), NULL, NULL,
1737 _( @"Encoding won't be recoverable." ) );
1740 - (void) _Cancel: (NSWindow *) sheet
1741 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1743 if( returnCode == NSAlertAlternateReturn )
1746 /*set the fEncodeState State */
1751 - (IBAction) Pause: (id) sender
1754 hb_get_state2( fHandle, &s );
1756 if( s.state == HB_STATE_PAUSED )
1758 hb_resume( fHandle );
1762 hb_pause( fHandle );
1766 - (IBAction) titlePopUpChanged: (id) sender
1768 hb_list_t * list = hb_get_titles( fHandle );
1769 hb_title_t * title = (hb_title_t*)
1770 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1773 /* If Auto Naming is on. We create an output filename of dvd name - title number */
1774 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0)
1776 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1777 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
1778 [NSString stringWithUTF8String: title->name],
1780 [[fDstFile2Field stringValue] pathExtension]]];
1783 /* Update chapter popups */
1784 [fSrcChapterStartPopUp removeAllItems];
1785 [fSrcChapterEndPopUp removeAllItems];
1786 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
1788 [fSrcChapterStartPopUp addItemWithTitle: [NSString
1789 stringWithFormat: @"%d", i + 1]];
1790 [fSrcChapterEndPopUp addItemWithTitle: [NSString
1791 stringWithFormat: @"%d", i + 1]];
1793 [fSrcChapterStartPopUp selectItemAtIndex: 0];
1794 [fSrcChapterEndPopUp selectItemAtIndex:
1795 hb_list_count( title->list_chapter ) - 1];
1796 [self chapterPopUpChanged: NULL];
1798 /* Start Get and set the initial pic size for display */
1799 hb_job_t * job = title->job;
1801 /* Turn Deinterlace on/off depending on the preference */
1802 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1804 [fPictureController setDeinterlace:1];
1808 [fPictureController setDeinterlace:0];
1811 /* Pixel Ratio Setting */
1812 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PixelRatio"])
1814 job->pixel_ratio = 1 ;
1818 job->pixel_ratio = 0 ;
1820 /*Set Source Size Fields Here */
1821 [fPicSrcWidth setStringValue: [NSString stringWithFormat:
1822 @"%d", fTitle->width]];
1823 [fPicSrcHeight setStringValue: [NSString stringWithFormat:
1824 @"%d", fTitle->height]];
1826 /* Set Auto Crop to on upon selecting a new title */
1827 [fPictureController setAutoCrop:YES];
1829 /* We get the originial output picture width and height and put them
1830 in variables for use with some presets later on */
1831 PicOrigOutputWidth = job->width;
1832 PicOrigOutputHeight = job->height;
1833 AutoCropTop = job->crop[0];
1834 AutoCropBottom = job->crop[1];
1835 AutoCropLeft = job->crop[2];
1836 AutoCropRight = job->crop[3];
1837 /* we test getting the max output value for pic sizing here to be used later*/
1838 [fPicSettingWidth setStringValue: [NSString stringWithFormat:
1839 @"%d", PicOrigOutputWidth]];
1840 [fPicSettingHeight setStringValue: [NSString stringWithFormat:
1841 @"%d", PicOrigOutputHeight]];
1842 /* we run the picture size values through
1843 calculatePictureSizing to get all picture size
1845 [self calculatePictureSizing: NULL];
1846 /* Run Through encoderPopUpChanged to see if there
1847 needs to be any pic value modifications based on encoder settings */
1848 //[self encoderPopUpChanged: NULL];
1849 /* END Get and set the initial pic size for display */
1851 /* Update subtitle popups */
1852 hb_subtitle_t * subtitle;
1853 [fSubPopUp removeAllItems];
1854 [fSubPopUp addItemWithTitle: @"None"];
1855 [fSubPopUp addItemWithTitle: @"Autoselect"];
1856 for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
1858 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
1860 /* We cannot use NSPopUpButton's addItemWithTitle because
1861 it checks for duplicate entries */
1862 [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
1863 subtitle->lang] action: NULL keyEquivalent: @""];
1865 [fSubPopUp selectItemAtIndex: 0];
1867 [self subtitleSelectionChanged: NULL];
1869 /* Update chapter table */
1870 [fChapterTitlesDelegate resetWithTitle:title];
1871 [fChapterTable reloadData];
1873 /* Update audio popups */
1874 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
1875 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
1876 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
1877 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
1878 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
1879 [self selectAudioTrackInPopUp: fAudLang2PopUp searchPrefixString: NULL selectIndexIfNotFound: 0];
1881 /* changing the title may have changed the audio channels on offer, */
1882 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1883 [self audioTrackPopUpChanged: fAudLang1PopUp];
1884 [self audioTrackPopUpChanged: fAudLang2PopUp];
1885 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
1886 [self tableViewSelected:NULL];
1889 - (IBAction) chapterPopUpChanged: (id) sender
1892 /* If start chapter popup is greater than end chapter popup,
1893 we set the end chapter popup to the same as start chapter popup */
1894 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
1896 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
1900 hb_list_t * list = hb_get_titles( fHandle );
1901 hb_title_t * title = (hb_title_t *)
1902 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1904 hb_chapter_t * chapter;
1905 int64_t duration = 0;
1906 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
1907 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
1909 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
1910 duration += chapter->duration;
1913 duration /= 90000; /* pts -> seconds */
1914 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
1915 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
1918 [self calculateBitrate: sender];
1921 - (IBAction) formatPopUpChanged: (id) sender
1923 NSString * string = [fDstFile2Field stringValue];
1924 int format = [fDstFormatPopUp indexOfSelectedItem];
1926 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
1927 [fDstMpgLargeFileCheck setHidden: YES];
1928 /* Update the codecs popup */
1929 [fDstCodecsPopUp removeAllItems];
1933 /*Get Default MP4 File Extension*/
1934 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1942 [fDstCodecsPopUp addItemWithTitle:
1943 _( @"MPEG-4 Video / AAC Audio" )];
1944 [fDstCodecsPopUp addItemWithTitle:
1945 _( @"AVC/H.264 Video / AAC Audio" )];
1946 /* We enable the create chapters checkbox here since we are .mp4*/
1947 [fCreateChapterMarkers setEnabled: YES];
1948 /* We show the Large File (64 bit formatting) checkbox since we are .mp4
1949 if we have enabled the option in the global preferences*/
1950 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0)
1952 [fDstMpgLargeFileCheck setHidden: NO];
1956 /* if not enable in global preferences, we additionaly sanity check that the
1957 hidden checkbox is set to off. */
1958 [fDstMpgLargeFileCheck setState: NSOffState];
1963 [fDstCodecsPopUp addItemWithTitle:
1964 _( @"MPEG-4 Video / MP3 Audio" )];
1965 [fDstCodecsPopUp addItemWithTitle:
1966 _( @"MPEG-4 Video / AC-3 Audio" )];
1967 [fDstCodecsPopUp addItemWithTitle:
1968 _( @"AVC/H.264 Video / MP3 Audio" )];
1969 [fDstCodecsPopUp addItemWithTitle:
1970 _( @"AVC/H.264 Video / AC-3 Audio" )];
1971 /* We disable the create chapters checkbox here since we are NOT .mp4
1972 and make sure it is unchecked*/
1973 [fCreateChapterMarkers setEnabled: NO];
1974 [fCreateChapterMarkers setState: NSOffState];
1978 [fDstCodecsPopUp addItemWithTitle:
1979 _( @"MPEG-4 Video / Vorbis Audio" )];
1980 [fDstCodecsPopUp addItemWithTitle:
1981 _( @"MPEG-4 Video / MP3 Audio" )];
1982 /* We disable the create chapters checkbox here since we are NOT .mp4
1983 and make sure it is unchecked*/
1984 [fCreateChapterMarkers setEnabled: NO];
1985 [fCreateChapterMarkers setState: NSOffState];
1989 [fDstCodecsPopUp addItemWithTitle:
1990 _( @"MPEG-4 Video / AAC Audio" )];
1991 [fDstCodecsPopUp addItemWithTitle:
1992 _( @"MPEG-4 Video / AC-3 Audio" )];
1993 [fDstCodecsPopUp addItemWithTitle:
1994 _( @"MPEG-4 Video / MP3 Audio" )];
1995 [fDstCodecsPopUp addItemWithTitle:
1996 _( @"MPEG-4 Video / Vorbis Audio" )];
1998 [fDstCodecsPopUp addItemWithTitle:
1999 _( @"AVC/H.264 Video / AAC Audio" )];
2000 [fDstCodecsPopUp addItemWithTitle:
2001 _( @"AVC/H.264 Video / AC-3 Audio" )];
2002 [fDstCodecsPopUp addItemWithTitle:
2003 _( @"AVC/H.264 Video / MP3 Audio" )];
2004 [fDstCodecsPopUp addItemWithTitle:
2005 _( @"AVC/H.264 Video / Vorbis Audio" )];
2006 /* We disable the create chapters checkbox here since we are NOT .mp4
2007 and make sure it is unchecked*/
2008 [fCreateChapterMarkers setEnabled: YES];
2011 [self codecsPopUpChanged: NULL];
2013 /* Add/replace to the correct extension */
2014 if( [string characterAtIndex: [string length] - 4] == '.' )
2016 [fDstFile2Field setStringValue: [NSString stringWithFormat:
2017 @"%@.%s", [string substringToIndex: [string length] - 4],
2022 [fDstFile2Field setStringValue: [NSString stringWithFormat:
2023 @"%@.%s", string, ext]];
2026 /* changing the format may mean that we can / can't offer mono or 6ch, */
2027 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
2028 [self audioTrackPopUpChanged: fAudLang1PopUp];
2029 [self audioTrackPopUpChanged: fAudLang2PopUp];
2030 /* We call the method to properly enable/disable turbo 2 pass */
2031 [self twoPassCheckboxChanged: sender];
2032 /* We call method method to change UI to reflect whether a preset is used or not*/
2033 [self customSettingUsed: sender];
2037 - (IBAction) codecsPopUpChanged: (id) sender
2039 int format = [fDstFormatPopUp indexOfSelectedItem];
2040 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2042 [fAdvancedOptions setHidden:YES];
2044 /* Update the encoder popup*/
2045 if( ( FormatSettings[format][codecs] & HB_VCODEC_X264 ) )
2047 /* MPEG-4 -> H.264 */
2048 [fVidEncoderPopUp removeAllItems];
2049 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 Main)"];
2050 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 iPod)"];
2051 [fVidEncoderPopUp selectItemAtIndex: 0];
2052 [fAdvancedOptions setHidden:NO];
2055 else if( ( FormatSettings[format][codecs] & HB_VCODEC_FFMPEG ) )
2057 /* H.264 -> MPEG-4 */
2058 [fVidEncoderPopUp removeAllItems];
2059 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
2060 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
2061 [fVidEncoderPopUp selectItemAtIndex: 0];
2065 if( FormatSettings[format][codecs] & HB_ACODEC_AC3 )
2067 /* AC-3 pass-through: disable samplerate and bitrate */
2068 [fAudRatePopUp setEnabled: NO];
2069 [fAudBitratePopUp setEnabled: NO];
2073 [fAudRatePopUp setEnabled: YES];
2074 [fAudBitratePopUp setEnabled: YES];
2076 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
2077 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
2078 [self audioTrackPopUpChanged: fAudLang1PopUp];
2079 [self audioTrackPopUpChanged: fAudLang2PopUp];
2081 [self calculateBitrate: sender];
2082 [self twoPassCheckboxChanged: sender];
2085 - (IBAction) encoderPopUpChanged: (id) sender
2088 /* Check to see if we need to modify the job pic values based on x264 (iPod) encoder selection */
2089 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [fDstCodecsPopUp indexOfSelectedItem] == 1 && [fVidEncoderPopUp indexOfSelectedItem] == 1)
2091 hb_job_t * job = fTitle->job;
2092 job->pixel_ratio = 0 ;
2094 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPicSizeAutoiPod"] > 0)
2097 if (job->width > 640)
2101 job->keep_ratio = 1;
2102 hb_fix_aspect( job, HB_KEEP_WIDTH );
2105 /* Make sure the 64bit formatting checkbox is off */
2106 [fDstMpgLargeFileCheck setState: NSOffState];
2109 [self calculatePictureSizing: sender];
2110 [self twoPassCheckboxChanged: sender];
2113 - (IBAction) twoPassCheckboxChanged: (id) sender
2115 /* check to see if x264 is chosen */
2116 int format = [fDstFormatPopUp indexOfSelectedItem];
2117 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2118 if( ( FormatSettings[format][codecs] & HB_VCODEC_X264 ) )
2120 if( [fVidTwoPassCheck state] == NSOnState)
2122 [fVidTurboPassCheck setHidden: NO];
2126 [fVidTurboPassCheck setHidden: YES];
2127 [fVidTurboPassCheck setState: NSOffState];
2129 /* Make sure Two Pass is checked if Turbo is checked */
2130 if( [fVidTurboPassCheck state] == NSOnState)
2132 [fVidTwoPassCheck setState: NSOnState];
2137 [fVidTurboPassCheck setHidden: YES];
2138 [fVidTurboPassCheck setState: NSOffState];
2141 /* We call method method to change UI to reflect whether a preset is used or not*/
2142 [self customSettingUsed: sender];
2145 - (IBAction ) videoFrameRateChanged: (id) sender
2147 /* We call method method to calculatePictureSizing to error check detelecine*/
2148 [self calculatePictureSizing: sender];
2150 /* We call method method to change UI to reflect whether a preset is used or not*/
2151 [self customSettingUsed: sender];
2154 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
2157 /* enable/disable the mixdown text and popupbutton for audio track 1 */
2158 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
2159 [fAudTrack1MixLabel setTextColor: ([fAudLang1PopUp indexOfSelectedItem] == 0) ?
2160 [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
2162 /* enable/disable the mixdown text and popupbutton for audio track 2 */
2163 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
2164 [fAudTrack2MixLabel setTextColor: ([fAudLang2PopUp indexOfSelectedItem] == 0) ?
2165 [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
2169 - (IBAction) addAllAudioTracksToPopUp: (id) sender
2172 hb_list_t * list = hb_get_titles( fHandle );
2173 hb_title_t * title = (hb_title_t*)
2174 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
2178 [sender removeAllItems];
2179 [sender addItemWithTitle: _( @"None" )];
2180 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
2182 audio = (hb_audio_t *) hb_list_item( title->list_audio, i );
2183 [[sender menu] addItemWithTitle:
2184 [NSString stringWithCString: audio->lang]
2185 action: NULL keyEquivalent: @""];
2187 [sender selectItemAtIndex: 0];
2191 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
2194 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
2195 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
2196 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
2197 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
2199 if (searchPrefixString != NULL)
2202 for( int i = 0; i < [sender numberOfItems]; i++ )
2204 /* Try to find the desired search string */
2205 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
2207 [sender selectItemAtIndex: i];
2211 /* couldn't find the string, so select the requested "search string not found" item */
2212 /* index of 0 means select the "none" item */
2213 /* index of 1 means select the first audio track */
2214 [sender selectItemAtIndex: selectIndexIfNotFound];
2218 /* if no search string is provided, then select the selectIndexIfNotFound item */
2219 [sender selectItemAtIndex: selectIndexIfNotFound];
2224 - (IBAction) audioTrackPopUpChanged: (id) sender
2226 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
2227 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
2230 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
2233 /* make sure we have a selected title before continuing */
2234 if (fTitle == NULL) return;
2236 /* find out if audio track 1 or 2 was changed - this is passed to us in the tag of the sender */
2237 /* the sender will have been either fAudLang1PopUp (tag = 0) or fAudLang2PopUp (tag = 1) */
2238 int thisAudio = [sender tag];
2240 /* get the index of the selected audio */
2241 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
2243 /* Handbrake can't currently cope with ripping the same source track twice */
2244 /* So, if this audio is also selected in the other audio track popup, set that popup's selection to "none" */
2245 /* get a reference to the two audio track popups */
2246 NSPopUpButton * thisAudioPopUp = (thisAudio == 1 ? fAudLang2PopUp : fAudLang1PopUp);
2247 NSPopUpButton * otherAudioPopUp = (thisAudio == 1 ? fAudLang1PopUp : fAudLang2PopUp);
2248 /* if the same track is selected in the other audio popup, then select "none" in that popup */
2249 /* unless, of course, both are selected as "none!" */
2250 if ([thisAudioPopUp indexOfSelectedItem] != 0 && [thisAudioPopUp indexOfSelectedItem] == [otherAudioPopUp indexOfSelectedItem]) {
2251 [otherAudioPopUp selectItemAtIndex: 0];
2252 [self audioTrackPopUpChanged: otherAudioPopUp];
2255 /* pointer for the hb_audio_s struct we will use later on */
2258 /* find out what the currently-selected output audio codec is */
2259 int format = [fDstFormatPopUp indexOfSelectedItem];
2260 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2261 int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
2263 /* pointer to this track's mixdown NSPopUpButton */
2264 NSTextField * mixdownTextField;
2265 NSPopUpButton * mixdownPopUp;
2267 /* find our mixdown NSTextField and NSPopUpButton */
2270 mixdownTextField = fAudTrack1MixLabel;
2271 mixdownPopUp = fAudTrack1MixPopUp;
2275 mixdownTextField = fAudTrack2MixLabel;
2276 mixdownPopUp = fAudTrack2MixPopUp;
2279 /* delete the previous audio mixdown options */
2280 [mixdownPopUp removeAllItems];
2282 /* check if the audio mixdown controls need their enabled state changing */
2283 [self setEnabledStateOfAudioMixdownControls: NULL];
2285 if (thisAudioIndex != -1)
2289 audio = (hb_audio_t *) hb_list_item( fTitle->list_audio, thisAudioIndex );
2293 /* find out if our selected output audio codec supports mono and / or 6ch */
2294 /* we also check for an input codec of AC3 or DCA,
2295 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
2296 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
2297 but this may change in the future, so they are separated for flexibility */
2298 int audioCodecsSupportMono = ((audio->codec == HB_ACODEC_AC3 ||
2299 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2300 int audioCodecsSupport6Ch = ((audio->codec == HB_ACODEC_AC3 ||
2301 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2303 /* check for AC-3 passthru */
2304 if (audio->codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
2306 [[mixdownPopUp menu] addItemWithTitle:
2307 [NSString stringWithCString: "AC3 Passthru"]
2308 action: NULL keyEquivalent: @""];
2313 /* add the appropriate audio mixdown menuitems to the popupbutton */
2314 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
2315 so that we can reference the mixdown later */
2317 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
2318 int minMixdownUsed = 0;
2319 int maxMixdownUsed = 0;
2321 /* get the input channel layout without any lfe channels */
2322 int layout = audio->input_channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2324 /* do we want to add a mono option? */
2325 if (audioCodecsSupportMono == 1) {
2326 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2327 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
2328 action: NULL keyEquivalent: @""];
2329 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
2330 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
2331 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
2334 /* do we want to add a stereo option? */
2335 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
2336 /* also offer stereo if we have a stereo-or-better source */
2337 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO) {
2338 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2339 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
2340 action: NULL keyEquivalent: @""];
2341 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
2342 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
2343 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
2346 /* do we want to add a dolby surround (DPL1) option? */
2347 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY) {
2348 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2349 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
2350 action: NULL keyEquivalent: @""];
2351 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
2352 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
2353 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
2356 /* do we want to add a dolby pro logic 2 (DPL2) option? */
2357 if (layout == HB_INPUT_CH_LAYOUT_3F2R) {
2358 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2359 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
2360 action: NULL keyEquivalent: @""];
2361 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
2362 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
2363 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
2366 /* do we want to add a 6-channel discrete option? */
2367 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->input_channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE)) {
2368 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2369 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
2370 action: NULL keyEquivalent: @""];
2371 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
2372 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
2373 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
2376 /* auto-select the best mixdown based on our saved mixdown preference */
2378 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
2379 /* ultimately this should be a prefs option */
2382 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
2383 if (mixdownToUse > 0)
2385 useMixdown = mixdownToUse;
2389 useMixdown = HB_AMIXDOWN_DOLBYPLII;
2392 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
2393 if (useMixdown > maxMixdownUsed) useMixdown = maxMixdownUsed;
2395 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
2396 if (useMixdown < minMixdownUsed) useMixdown = minMixdownUsed;
2398 /* select the (possibly-amended) preferred mixdown */
2399 [mixdownPopUp selectItemWithTag: useMixdown];
2401 /* lets call the audioTrackMixdownChanged method here to determine appropriate bitrates, etc. */
2402 [self audioTrackMixdownChanged: NULL];
2409 /* see if the new audio track choice will change the bitrate we need */
2410 [self calculateBitrate: sender];
2413 - (IBAction) audioTrackMixdownChanged: (id) sender
2416 /* find out what the currently-selected output audio codec is */
2417 int format = [fDstFormatPopUp indexOfSelectedItem];
2418 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2419 int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
2421 /* storage variable for the min and max bitrate allowed for this codec */
2427 case HB_ACODEC_FAAC:
2428 /* check if we have a 6ch discrete conversion in either audio track */
2429 if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2431 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
2433 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
2439 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
2441 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
2442 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
2447 case HB_ACODEC_LAME:
2448 /* Lame is happy using our min bitrate of 32 kbps */
2450 /* Lame won't encode if the bitrate is higher than 320 kbps */
2454 case HB_ACODEC_VORBIS:
2455 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
2457 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
2462 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
2468 [fAudBitratePopUp removeAllItems];
2470 for( int i = 0; i < hb_audio_bitrates_count; i++ )
2472 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
2474 /* add a new menuitem for this bitrate */
2475 id<NSMenuItem> menuItem = [[fAudBitratePopUp menu] addItemWithTitle:
2476 [NSString stringWithCString: hb_audio_bitrates[i].string]
2477 action: NULL keyEquivalent: @""];
2478 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
2479 [menuItem setTag: hb_audio_bitrates[i].rate];
2483 /* select the default bitrate (but use 384 for 6-ch AAC) */
2484 if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2486 [fAudBitratePopUp selectItemWithTag: 384];
2490 [fAudBitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
2495 - (IBAction) subtitleSelectionChanged: (id) sender
2497 if ([fSubPopUp indexOfSelectedItem] == 0)
2499 [fSubForcedCheck setState: NSOffState];
2500 [fSubForcedCheck setEnabled: NO];
2504 [fSubForcedCheck setEnabled: YES];
2509 /* lets set the picture size back to the max from right after title scan
2510 Lets use an IBAction here as down the road we could always use a checkbox
2511 in the gui to easily take the user back to max. Remember, the compiler
2512 resolves IBActions down to -(void) during compile anyway */
2513 - (IBAction) revertPictureSizeToMax: (id) sender
2515 hb_job_t * job = fTitle->job;
2516 /* We use the output picture width and height
2517 as calculated from libhb right after title is set
2518 in TitlePopUpChanged */
2519 job->width = PicOrigOutputWidth;
2520 job->height = PicOrigOutputHeight;
2521 [fPictureController setAutoCrop:YES];
2522 /* Here we use the auto crop values determined right after scan */
2523 job->crop[0] = AutoCropTop;
2524 job->crop[1] = AutoCropBottom;
2525 job->crop[2] = AutoCropLeft;
2526 job->crop[3] = AutoCropRight;
2529 [self calculatePictureSizing: sender];
2530 /* We call method method to change UI to reflect whether a preset is used or not*/
2531 [self customSettingUsed: sender];
2535 /* Get and Display Current Pic Settings in main window */
2536 - (IBAction) calculatePictureSizing: (id) sender
2538 [fPicSettingWidth setStringValue: [NSString stringWithFormat:@"%d", fTitle->job->width]];
2539 [fPicSettingHeight setStringValue: [NSString stringWithFormat:@"%d", fTitle->job->height]];
2541 if (fTitle->job->pixel_ratio == 1)
2543 int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
2544 int arpwidth = fTitle->job->pixel_aspect_width;
2545 int arpheight = fTitle->job->pixel_aspect_height;
2546 int displayparwidth = titlewidth * arpwidth / arpheight;
2547 int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
2549 [fPicSettingWidth setStringValue: [NSString stringWithFormat:@"%d", titlewidth]];
2550 [fPicSettingHeight setStringValue: [NSString stringWithFormat:@"%d", displayparheight]];
2551 [fPicLabelPAROutputX setStringValue: @"x"];
2552 [fPicSettingPARWidth setStringValue: [NSString stringWithFormat:@"%d", displayparwidth]];
2553 [fPicSettingPARHeight setStringValue: [NSString stringWithFormat:@"%d", displayparheight]];
2555 fTitle->job->keep_ratio = 0;
2559 [fPicLabelPAROutputX setStringValue: @""];
2560 [fPicSettingPARWidth setStringValue: @""];
2561 [fPicSettingPARHeight setStringValue: @""];
2564 /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */
2565 if (fTitle->job->keep_ratio > 0)
2567 [fPicSettingARkeep setStringValue: @"On"];
2571 [fPicSettingARkeep setStringValue: @"Off"];
2574 if ([fPictureController detelecine]) {
2575 [fPicSettingDetelecine setStringValue: @"Yes"];
2578 [fPicSettingDetelecine setStringValue: @"No"];
2582 if ([fPictureController deinterlace] == 0)
2584 [fPicSettingDeinterlace setStringValue: @"Off"];
2586 else if ([fPictureController deinterlace] == 1)
2588 [fPicSettingDeinterlace setStringValue: @"Fast"];
2590 else if ([fPictureController deinterlace] == 2)
2592 [fPicSettingDeinterlace setStringValue: @"Slow"];
2594 else if ([fPictureController deinterlace] == 3)
2596 [fPicSettingDeinterlace setStringValue: @"Slower"];
2598 else if ([fPictureController deinterlace] ==4)
2600 [fPicSettingDeinterlace setStringValue: @"Slowest"];
2603 if ([fPictureController denoise] == 0)
2605 [fPicSettingDenoise setStringValue: @"Off"];
2607 else if ([fPictureController denoise] == 1)
2609 [fPicSettingDenoise setStringValue: @"Weak"];
2611 else if ([fPictureController denoise] == 2)
2613 [fPicSettingDenoise setStringValue: @"Medium"];
2615 else if ([fPictureController denoise] == 3)
2617 [fPicSettingDenoise setStringValue: @"Strong"];
2620 if (fTitle->job->pixel_ratio > 0)
2622 [fPicSettingPAR setStringValue: @""];
2626 [fPicSettingPAR setStringValue: @"Off"];
2628 /* Set the display field for crop as per boolean */
2629 if (![fPictureController autoCrop])
2631 [fPicSettingAutoCrop setStringValue: @"Custom"];
2635 [fPicSettingAutoCrop setStringValue: @"Auto"];
2637 /* check video framerate and turn off detelecine if necessary */
2638 if (fTitle->rate_base == 1126125 || [[fVidRatePopUp titleOfSelectedItem] isEqualToString: @"23.976 (NTSC Film)"])
2640 [fPictureController setDetelecine:0];
2645 /* below will trigger the preset, if selected, to be
2646 changed to "Custom". Lets comment out for now until
2647 we figure out a way to determine if the picture values
2648 changed modify the preset values */
2649 //[self customSettingUsed: sender];
2652 - (IBAction) calculateBitrate: (id) sender
2654 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 )
2659 hb_list_t * list = hb_get_titles( fHandle );
2660 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2661 [fSrcTitlePopUp indexOfSelectedItem] );
2662 hb_job_t * job = title->job;
2666 [fVidBitrateField setIntValue: hb_calc_bitrate( job,
2667 [fVidTargetSizeField intValue] )];
2669 [self customSettingUsed:sender];
2672 /* Method to determine if we should change the UI
2673 To reflect whether or not a Preset is being used or if
2674 the user is using "Custom" settings by determining the sender*/
2675 - (IBAction) customSettingUsed: (id) sender
2677 if ([sender stringValue] != NULL)
2679 /* Deselect the currently selected Preset if there is one*/
2680 [tableView deselectRow:[tableView selectedRow]];
2681 [[fPresetsActionMenu itemAtIndex:0] setEnabled: NO];
2682 /* Change UI to show "Custom" settings are being used */
2683 [fPresetSelectedDisplay setStringValue: @"Custom"];
2685 curUserPresetChosenNum = nil;
2690 /* We use this method to recreate new, updated factory
2692 - (IBAction)addFactoryPresets:(id)sender
2694 /* First, we delete any existing built in presets */
2695 [self deleteFactoryPresets: sender];
2696 /* Then, we re-create new built in presets programmatically CreateIpodOnlyPreset*/
2697 [UserPresets addObject:[self createNormalPreset]];
2698 [UserPresets addObject:[self createClassicPreset]];
2699 [UserPresets addObject:[self createQuickTimePreset]];
2700 [UserPresets addObject:[self createIpodLowPreset]];
2701 [UserPresets addObject:[self createIpodHighPreset]];
2702 [UserPresets addObject:[self createAppleTVPreset]];
2703 [UserPresets addObject:[self createiPhonePreset]];
2704 [UserPresets addObject:[self createPSThreePreset]];
2705 [UserPresets addObject:[self createPSPPreset]];
2706 [UserPresets addObject:[self createFilmPreset]];
2707 [UserPresets addObject:[self createTelevisionPreset]];
2708 [UserPresets addObject:[self createAnimationPreset]];
2709 [UserPresets addObject:[self createBedlamPreset]];
2710 [UserPresets addObject:[self createDeuxSixQuatrePreset]];
2711 [UserPresets addObject:[self createBrokePreset]];
2712 [UserPresets addObject:[self createBlindPreset]];
2713 [UserPresets addObject:[self createCRFPreset]];
2717 - (IBAction)deleteFactoryPresets:(id)sender
2720 NSEnumerator *enumerator = [UserPresets objectEnumerator];
2724 NSMutableArray *tempArray;
2727 tempArray = [NSMutableArray array];
2728 /* we look here to see if the preset is we move on to the next one */
2729 while ( tempObject = [enumerator nextObject] )
2731 /* if the preset is "Factory" then we put it in the array of
2732 presets to delete */
2733 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
2735 [tempArray addObject:tempObject];
2739 [UserPresets removeObjectsInArray:tempArray];
2740 [tableView reloadData];
2745 - (IBAction) showAddPresetPanel: (id) sender
2747 /* Deselect the currently selected Preset if there is one*/
2748 [tableView deselectRow:[tableView selectedRow]];
2750 /* Populate the preset picture settings popup here */
2751 [fPresetNewPicSettingsPopUp removeAllItems];
2752 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
2753 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
2754 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
2755 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
2757 /* Erase info from the input fields fPresetNewDesc*/
2758 [fPresetNewName setStringValue: @""];
2759 [fPresetNewDesc setStringValue: @""];
2760 /* Show the panel */
2761 [NSApp beginSheet: fAddPresetPanel modalForWindow: fWindow modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
2764 - (IBAction) closeAddPresetPanel: (id) sender
2766 [NSApp endSheet: fAddPresetPanel];
2767 [fAddPresetPanel orderOut: self];
2770 - (IBAction)addUserPreset:(id)sender
2772 if (![[fPresetNewName stringValue] length])
2773 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
2776 /* Here we create a custom user preset */
2777 [UserPresets addObject:[self createPreset]];
2780 [self closeAddPresetPanel:NULL];
2787 /* We Sort the Presets By Factory or Custom */
2788 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
2789 ascending:YES] autorelease];
2790 /* We Sort the Presets Alphabetically by name */
2791 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
2792 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
2793 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
2794 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
2795 [UserPresets setArray:sortedArray];
2798 /* We Reload the New Table data for presets */
2799 [tableView reloadData];
2800 /* We save all of the preset data here */
2804 - (IBAction)insertPreset:(id)sender
2806 int index = [tableView selectedRow];
2807 [UserPresets insertObject:[self createPreset] atIndex:index];
2808 [tableView reloadData];
2812 - (NSDictionary *)createPreset
2814 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2815 /* Get the New Preset Name from the field in the AddPresetPanel */
2816 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
2817 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2818 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
2819 /*Set whether or not this is default, at creation set to 0*/
2820 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2821 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2822 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
2823 /* Get New Preset Description from the field in the AddPresetPanel*/
2824 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
2826 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
2827 /* Chapter Markers fCreateChapterMarkers*/
2828 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
2829 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2830 [preset setObject:[NSNumber numberWithInt:[fDstMpgLargeFileCheck state]] forKey:@"Mp4LargeFile"];
2832 [preset setObject:[fDstCodecsPopUp titleOfSelectedItem] forKey:@"FileCodecs"];
2834 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
2835 /* x264 Option String */
2836 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
2838 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
2839 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2840 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
2841 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2843 /* Video framerate */
2844 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
2846 [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
2847 /* 2 Pass Encoding */
2848 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
2849 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
2850 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
2851 /*Picture Settings*/
2852 hb_job_t * job = fTitle->job;
2853 /* Basic Picture Settings */
2854 /* Use Max Picture settings for whatever the dvd is.*/
2855 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2856 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2857 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2858 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2859 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
2860 [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
2861 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
2862 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
2863 /* Set crop settings here */
2864 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
2865 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2867 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2868 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2869 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2870 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2873 /* Audio Sample Rate*/
2874 [preset setObject:[fAudRatePopUp titleOfSelectedItem] forKey:@"AudioSampleRate"];
2875 /* Audio Bitrate Rate*/
2876 [preset setObject:[fAudBitratePopUp titleOfSelectedItem] forKey:@"AudioBitRate"];
2878 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
2881 [preset autorelease];
2886 - (NSDictionary *)createIpodLowPreset
2888 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2889 /* Get the New Preset Name from the field in the AddPresetPanel */
2890 [preset setObject:@"iPod Low-Rez" forKey:@"PresetName"];
2891 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2892 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
2893 /*Set whether or not this is default, at creation set to 0*/
2894 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2895 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2896 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
2897 /* Get the New Preset Description from the field in the AddPresetPanel */
2898 [preset setObject:@"HandBrake's low resolution settings for the iPod. Optimized for great playback on the iPod screen, with smaller file size." forKey:@"PresetDescription"];
2900 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
2901 /* Chapter Markers*/
2902 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
2904 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
2906 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
2907 /* x264 Option String */
2908 [preset setObject:@"keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1" forKey:@"x264Option"];
2910 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
2911 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2912 [preset setObject:@"700" forKey:@"VideoAvgBitrate"];
2913 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2915 /* Video framerate */
2916 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
2918 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
2919 /* 2 Pass Encoding */
2920 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
2922 /*Picture Settings*/
2923 //hb_job_t * job = fTitle->job;
2924 /* Basic Picture Settings */
2925 /* Use Max Picture settings for whatever the dvd is.*/
2926 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2927 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
2928 [preset setObject:[NSNumber numberWithInt:320] forKey:@"PictureWidth"];
2929 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
2930 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
2931 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
2932 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
2933 /* Set crop settings here */
2934 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
2935 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
2936 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
2937 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
2938 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
2941 /* Audio Sample Rate*/
2942 [preset setObject:@"48" forKey:@"AudioSampleRate"];
2943 /* Audio Bitrate Rate*/
2944 [preset setObject:@"160" forKey:@"AudioBitRate"];
2946 [preset setObject:@"None" forKey:@"Subtitles"];
2949 [preset autorelease];
2955 - (NSDictionary *)createIpodHighPreset
2957 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2958 /* Get the New Preset Name from the field in the AddPresetPanel */
2959 [preset setObject:@"iPod High-Rez" forKey:@"PresetName"];
2960 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2961 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
2962 /*Set whether or not this is default, at creation set to 0*/
2963 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2964 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2965 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
2966 /* Get the New Preset Description from the field in the AddPresetPanel */
2967 [preset setObject:@"HandBrake's high resolution settings for the iPod. Good video quality, great for viewing on a TV using your iPod" forKey:@"PresetDescription"];
2969 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
2970 /* Chapter Markers*/
2971 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
2973 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
2975 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
2976 /* x264 Option String */
2977 [preset setObject:@"keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1" forKey:@"x264Option"];
2979 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
2980 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2981 [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
2982 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2984 /* Video framerate */
2985 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
2987 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
2988 /* 2 Pass Encoding */
2989 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
2991 /*Picture Settings*/
2992 //hb_job_t * job = fTitle->job;
2993 /* Basic Picture Settings */
2994 /* Use Max Picture settings for whatever the dvd is.*/
2995 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2996 [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
2997 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
2998 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
2999 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3000 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3001 /* Set crop settings here */
3002 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3003 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3004 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3005 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3006 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3007 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3010 /* Audio Sample Rate*/
3011 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3012 /* Audio Bitrate Rate*/
3013 [preset setObject:@"160" forKey:@"AudioBitRate"];
3015 [preset setObject:@"None" forKey:@"Subtitles"];
3018 [preset autorelease];
3023 - (NSDictionary *)createAppleTVPreset
3025 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3026 /* Get the New Preset Name from the field in the AddPresetPanel */
3027 [preset setObject:@"AppleTV" forKey:@"PresetName"];
3028 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3029 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3030 /*Set whether or not this is default, at creation set to 0*/
3031 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3032 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3033 [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3034 /* Get the New Preset Description from the field in the AddPresetPanel */
3035 [preset setObject:@"HandBrake's settings for the AppleTV. Provides a good balance between quality and file size, and optimizes performance." forKey:@"PresetDescription"];
3037 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3038 /* Chapter Markers*/
3039 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3041 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3043 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3044 /* x264 Option String (We can use this to tweak the appleTV output)*/
3045 [preset setObject:@"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2:cabac=0" forKey:@"x264Option"];
3047 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3048 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3049 [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3050 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3052 /* Video framerate */
3053 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3055 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3056 /* 2 Pass Encoding */
3057 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3059 /*Picture Settings*/
3060 /* For AppleTV we only want to retain UsesMaxPictureSettings
3061 which depend on the source dvd picture settings, so we don't
3062 record the current dvd's picture info since it will vary from
3064 //hb_job_t * job = fTitle->job;
3065 //hb_job_t * job = title->job;
3066 /* Basic Picture Settings */
3067 /* Use Max Picture settings for whatever the dvd is.*/
3068 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3069 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3070 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3071 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3072 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3073 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3074 /* Set crop settings here */
3075 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3076 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3077 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3078 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3079 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3082 /* Audio Sample Rate*/
3083 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3084 /* Audio Bitrate Rate*/
3085 [preset setObject:@"160" forKey:@"AudioBitRate"];
3087 [preset setObject:@"None" forKey:@"Subtitles"];
3090 [preset autorelease];
3095 - (NSDictionary *)createPSThreePreset
3097 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3098 /* Get the New Preset Name from the field in the AddPresetPanel */
3099 [preset setObject:@"PS3" forKey:@"PresetName"];
3100 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3101 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3102 /*Set whether or not this is default, at creation set to 0*/
3103 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3104 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3105 [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3106 /* Get the New Preset Description from the field in the AddPresetPanel */
3107 [preset setObject:@"HandBrake's settings for the Sony PlayStation 3." forKey:@"PresetDescription"];
3109 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3110 /* Chapter Markers*/
3111 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3113 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3115 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3116 /* x264 Option String (We can use this to tweak the appleTV output)*/
3117 [preset setObject:@"level=41:subme=5:me=umh" forKey:@"x264Option"];
3119 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3120 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3121 [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3122 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3124 /* Video framerate */
3125 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3127 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3128 /* 2 Pass Encoding */
3129 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3131 /*Picture Settings*/
3132 /* For PS3 we only want to retain UsesMaxPictureSettings
3133 which depend on the source dvd picture settings, so we don't
3134 record the current dvd's picture info since it will vary from
3136 /* Use Max Picture settings for whatever the dvd is.*/
3137 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3138 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3139 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3140 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3141 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3142 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3143 /* Set crop settings here */
3144 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3145 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3146 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3147 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3148 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3151 /* Audio Sample Rate*/
3152 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3153 /* Audio Bitrate Rate*/
3154 [preset setObject:@"160" forKey:@"AudioBitRate"];
3156 [preset setObject:@"None" forKey:@"Subtitles"];
3159 [preset autorelease];
3163 - (NSDictionary *)createPSPPreset
3165 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3166 /* Get the New Preset Name from the field in the AddPresetPanel */
3167 [preset setObject:@"PSP" forKey:@"PresetName"];
3168 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3169 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3170 /*Set whether or not this is default, at creation set to 0*/
3171 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3172 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3173 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3174 /* Get the New Preset Description from the field in the AddPresetPanel */
3175 [preset setObject:@"HandBrake's settings for the Sony PlayStation Portable." forKey:@"PresetDescription"];
3177 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3178 /* Chapter Markers*/
3179 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3181 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3183 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3184 /* x264 Option String (We can use this to tweak the appleTV output)*/
3185 [preset setObject:@"" forKey:@"x264Option"];
3187 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3188 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3189 [preset setObject:@"1024" forKey:@"VideoAvgBitrate"];
3190 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3192 /* Video framerate */
3193 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3195 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3196 /* 2 Pass Encoding */
3197 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3199 /*Picture Settings*/
3200 /* For PS3 we only want to retain UsesMaxPictureSettings
3201 which depend on the source dvd picture settings, so we don't
3202 record the current dvd's picture info since it will vary from
3204 /* Use Max Picture settings for whatever the dvd is.*/
3205 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3206 [preset setObject:@"368" forKey:@"PictureWidth"];
3207 [preset setObject:@"208" forKey:@"PictureHeight"];
3208 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3209 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3210 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3211 /* Set crop settings here */
3212 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3213 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3214 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3215 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3216 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3217 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3220 /* Audio Sample Rate*/
3221 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3222 /* Audio Bitrate Rate*/
3223 [preset setObject:@"128" forKey:@"AudioBitRate"];
3225 [preset setObject:@"None" forKey:@"Subtitles"];
3228 [preset autorelease];
3233 - (NSDictionary *)createNormalPreset
3235 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3236 /* Get the New Preset Name from the field in the AddPresetPanel */
3237 [preset setObject:@"Normal" forKey:@"PresetName"];
3238 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3239 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3240 /*Set whether or not this is default, at creation set to 0*/
3241 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Default"];
3242 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3243 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3244 /* Get the New Preset Description from the field in the AddPresetPanel */
3245 [preset setObject:@"HandBrake's normal, default settings." forKey:@"PresetDescription"];
3247 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3248 /* Chapter Markers*/
3249 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3251 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3253 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3254 /* x264 Option String */
3255 [preset setObject:@"ref=2:bframes=2:subme=5:me=umh" forKey:@"x264Option"];
3257 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3258 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3259 [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
3260 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3262 /* Video framerate */
3263 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3265 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3266 /* 2 Pass Encoding */
3267 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3268 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3270 /*Picture Settings*/
3271 //hb_job_t * job = fTitle->job;
3272 /* Basic Picture Settings */
3273 /* Use Max Picture settings for whatever the dvd is.*/
3274 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3275 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3276 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3277 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3278 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3279 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3280 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3281 /* Set crop settings here */
3282 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3283 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3284 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3285 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3286 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3289 /* Audio Sample Rate*/
3290 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3291 /* Audio Bitrate Rate*/
3292 [preset setObject:@"160" forKey:@"AudioBitRate"];
3294 [preset setObject:@"None" forKey:@"Subtitles"];
3297 [preset autorelease];
3302 - (NSDictionary *)createClassicPreset
3304 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3305 /* Get the New Preset Name from the field in the AddPresetPanel */
3306 [preset setObject:@"Classic" forKey:@"PresetName"];
3307 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3308 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3309 /*Set whether or not this is default, at creation set to 0*/
3310 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3311 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3312 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3313 /* Get the New Preset Description from the field in the AddPresetPanel */
3314 [preset setObject:@"HandBrake's traditional, faster, lower-quality settings." forKey:@"PresetDescription"];
3316 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3317 /* Chapter Markers*/
3318 [preset setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
3320 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3322 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3323 /* x264 Option String */
3324 [preset setObject:@"" forKey:@"x264Option"];
3326 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3327 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3328 [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
3329 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3331 /* Video framerate */
3332 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3334 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3335 /* 2 Pass Encoding */
3336 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3338 /*Picture Settings*/
3339 //hb_job_t * job = fTitle->job;
3340 /* Basic Picture Settings */
3341 /* Use Max Picture settings for whatever the dvd is.*/
3342 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3343 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3344 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3345 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3346 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3347 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3348 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3349 /* Set crop settings here */
3350 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3351 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3352 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3353 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3354 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3357 /* Audio Sample Rate*/
3358 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3359 /* Audio Bitrate Rate*/
3360 [preset setObject:@"160" forKey:@"AudioBitRate"];
3362 [preset setObject:@"None" forKey:@"Subtitles"];
3365 [preset autorelease];
3370 - (NSDictionary *)createFilmPreset
3372 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3373 /* Get the New Preset Name from the field in the AddPresetPanel */
3374 [preset setObject:@"Film" forKey:@"PresetName"];
3375 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3376 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3377 /*Set whether or not this is default, at creation set to 0*/
3378 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3379 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3380 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3381 /* Get the New Preset Description from the field in the AddPresetPanel */
3382 [preset setObject:@"HandBrake's preset for feature films." forKey:@"PresetDescription"];
3384 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3385 /* Chapter Markers*/
3386 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3388 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3390 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3391 /* x264 Option String */
3392 [preset setObject:@"ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:no-fast-pskip" forKey:@"x264Option"];
3394 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3395 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3396 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
3397 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3399 /* Video framerate */
3400 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3402 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3403 /* 2 Pass Encoding */
3404 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3405 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3407 /*Picture Settings*/
3408 //hb_job_t * job = fTitle->job;
3409 /* Basic Picture Settings */
3410 /* Use Max Picture settings for whatever the dvd is.*/
3411 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3412 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3413 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3414 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3415 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3416 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3417 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3418 /* Set crop settings here */
3419 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3420 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3421 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3422 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3423 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3426 /* Audio Sample Rate*/
3427 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3428 /* Audio Bitrate Rate*/
3429 [preset setObject:@"160" forKey:@"AudioBitRate"];
3431 [preset setObject:@"None" forKey:@"Subtitles"];
3434 [preset autorelease];
3439 - (NSDictionary *)createTelevisionPreset
3441 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3442 /* Get the New Preset Name from the field in the AddPresetPanel */
3443 [preset setObject:@"Television" forKey:@"PresetName"];
3444 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3445 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3446 /*Set whether or not this is default, at creation set to 0*/
3447 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3448 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3449 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3450 /* Get the New Preset Description from the field in the AddPresetPanel */
3451 [preset setObject:@"HandBrake's settings for video from television." forKey:@"PresetDescription"];
3453 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3454 /* Chapter Markers*/
3455 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3457 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3459 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3460 /* x264 Option String */
3461 [preset setObject:@"ref=3:mixed-refs:bframes=6:bime:weightb:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip" forKey:@"x264Option"];
3463 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3464 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3465 [preset setObject:@"1300" forKey:@"VideoAvgBitrate"];
3466 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3468 /* Video framerate */
3469 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3471 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3472 /* 2 Pass Encoding */
3473 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3474 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3476 /*Picture Settings*/
3477 //hb_job_t * job = fTitle->job;
3478 /* Basic Picture Settings */
3479 /* Use Max Picture settings for whatever the dvd is.*/
3480 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3481 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3482 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3483 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3484 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3485 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
3486 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3487 /* Set crop settings here */
3488 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3489 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3490 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3491 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3492 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3495 /* Audio Sample Rate*/
3496 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3497 /* Audio Bitrate Rate*/
3498 [preset setObject:@"160" forKey:@"AudioBitRate"];
3500 [preset setObject:@"None" forKey:@"Subtitles"];
3503 [preset autorelease];
3508 - (NSDictionary *)createAnimationPreset
3510 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3511 /* Get the New Preset Name from the field in the AddPresetPanel */
3512 [preset setObject:@"Animation" forKey:@"PresetName"];
3513 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3514 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3515 /*Set whether or not this is default, at creation set to 0*/
3516 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3517 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3518 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3519 /* Get the New Preset Description from the field in the AddPresetPanel */
3520 [preset setObject:@"HandBrake's settings for cartoons, anime, and CGI." forKey:@"PresetDescription"];
3522 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3523 /* Chapter Markers*/
3524 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3526 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3528 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3529 /* x264 Option String */
3530 [preset setObject:@"ref=5:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=5:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2" forKey:@"x264Option"];
3532 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3533 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3534 [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
3535 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3537 /* Video framerate */
3538 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3540 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3541 /* 2 Pass Encoding */
3542 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3543 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3545 /*Picture Settings*/
3546 //hb_job_t * job = fTitle->job;
3547 /* Basic Picture Settings */
3548 /* Use Max Picture settings for whatever the dvd is.*/
3549 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3550 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3551 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3552 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3553 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3554 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
3555 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3556 /* Set crop settings here */
3557 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3558 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3559 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3560 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3561 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3564 /* Audio Sample Rate*/
3565 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3566 /* Audio Bitrate Rate*/
3567 [preset setObject:@"160" forKey:@"AudioBitRate"];
3569 [preset setObject:@"None" forKey:@"Subtitles"];
3572 [preset autorelease];
3577 - (NSDictionary *)createQuickTimePreset
3579 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3580 /* Get the New Preset Name from the field in the AddPresetPanel */
3581 [preset setObject:@"QuickTime" forKey:@"PresetName"];
3582 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3583 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3584 /*Set whether or not this is default, at creation set to 0*/
3585 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3586 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3587 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3588 /* Get the New Preset Description from the field in the AddPresetPanel */
3589 [preset setObject:@"HandBrake's high quality settings for use with QuickTime. It can be slow, so use it when the Normal preset doesn't look good enough." forKey:@"PresetDescription"];
3591 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3592 /* Chapter Markers*/
3593 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3595 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3597 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3598 /* x264 Option String */
3599 [preset setObject:@"ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct=auto:me=umh:subme=5:analyse=all:8x8dct:trellis=1:no-fast-pskip" forKey:@"x264Option"];
3601 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3602 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3603 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
3604 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3606 /* Video framerate */
3607 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3609 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3610 /* 2 Pass Encoding */
3611 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3612 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3614 /*Picture Settings*/
3615 //hb_job_t * job = fTitle->job;
3616 /* Basic Picture Settings */
3617 /* Use Max Picture settings for whatever the dvd is.*/
3618 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3619 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3620 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3621 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3622 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3623 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3624 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3625 /* Set crop settings here */
3626 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3627 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3628 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3629 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3630 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3633 /* Audio Sample Rate*/
3634 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3635 /* Audio Bitrate Rate*/
3636 [preset setObject:@"160" forKey:@"AudioBitRate"];
3638 [preset setObject:@"None" forKey:@"Subtitles"];
3641 [preset autorelease];
3646 - (NSDictionary *)createBedlamPreset
3648 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3649 /* Get the New Preset Name from the field in the AddPresetPanel */
3650 [preset setObject:@"Bedlam" forKey:@"PresetName"];
3651 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3652 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3653 /*Set whether or not this is default, at creation set to 0*/
3654 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3655 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3656 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3657 /* Get the New Preset Description from the field in the AddPresetPanel */
3658 [preset setObject:@"HandBrake's settings maxed out for slowest encoding and highest quality. Use at your own risk. So slow it's not just insane...it's a trip to the looney bin." forKey:@"PresetDescription"];
3660 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3661 /* Chapter Markers*/
3662 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3664 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3666 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3667 /* x264 Option String */
3668 [preset setObject:@"ref=16:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:me-range=64:analyse=all:8x8dct:trellis=2:no-fast-pskip:no-dct-decimate:filter=-2,-1" forKey:@"x264Option"];
3670 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3671 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3672 [preset setObject:@"1800" forKey:@"VideoAvgBitrate"];
3673 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3675 /* Video framerate */
3676 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3678 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3679 /* 2 Pass Encoding */
3680 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3681 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3683 /*Picture Settings*/
3684 //hb_job_t * job = fTitle->job;
3685 /* Basic Picture Settings */
3686 /* Use Max Picture settings for whatever the dvd is.*/
3687 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3688 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3689 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3690 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3691 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3692 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3693 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3694 /* Set crop settings here */
3695 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3696 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3697 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3698 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3699 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3702 /* Audio Sample Rate*/
3703 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3704 /* Audio Bitrate Rate*/
3705 [preset setObject:@"160" forKey:@"AudioBitRate"];
3707 [preset setObject:@"None" forKey:@"Subtitles"];
3710 [preset autorelease];
3715 - (NSDictionary *)createiPhonePreset
3717 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3718 /* Get the New Preset Name from the field in the AddPresetPanel */
3719 [preset setObject:@"iPhone" forKey:@"PresetName"];
3720 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3721 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3722 /*Set whether or not this is default, at creation set to 0*/
3723 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3724 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3725 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3726 /* Get the New Preset Description from the field in the AddPresetPanel */
3727 [preset setObject:@"HandBrake's settings for the iPhone." forKey:@"PresetDescription"];
3729 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3730 /* Chapter Markers*/
3731 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3733 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3735 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
3736 /* x264 Option String */
3737 [preset setObject:@"cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1" forKey:@"x264Option"];
3739 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3740 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3741 [preset setObject:@"960" forKey:@"VideoAvgBitrate"];
3742 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3744 /* Video framerate */
3745 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3747 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3748 /* 2 Pass Encoding */
3749 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3751 /*Picture Settings*/
3752 //hb_job_t * job = fTitle->job;
3753 /* Basic Picture Settings */
3754 /* Use Max Picture settings for whatever the dvd is.*/
3755 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3756 [preset setObject:[NSNumber numberWithInt:480] forKey:@"PictureWidth"];
3757 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3758 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3759 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3760 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3761 /* Set crop settings here */
3762 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3763 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3764 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3765 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3766 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3767 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3770 /* Audio Sample Rate*/
3771 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3772 /* Audio Bitrate Rate*/
3773 [preset setObject:@"128" forKey:@"AudioBitRate"];
3775 [preset setObject:@"None" forKey:@"Subtitles"];
3778 [preset autorelease];
3783 - (NSDictionary *)createDeuxSixQuatrePreset
3785 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3786 /* Get the New Preset Name from the field in the AddPresetPanel */
3787 [preset setObject:@"Deux Six Quatre" forKey:@"PresetName"];
3788 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3789 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3790 /*Set whether or not this is default, at creation set to 0*/
3791 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3792 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3793 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3794 /* Get the New Preset Description from the field in the AddPresetPanel */
3795 [preset setObject:@"HandBrake's preset for true high profile x264 quality. A good balance of quality and speed, based on community standards found in the wild. This preset will give you a much better sense of x264's capabilities than vanilla main profile." forKey:@"PresetDescription"];
3797 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3798 /* Chapter Markers*/
3799 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3801 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3803 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3804 /* x264 Option String */
3805 [preset setObject:@"ref=5:mixed-refs:bframes=3:bime:weightb:b-rdo:b-pyramid:me=umh:subme=7:trellis=1:analyse=all:8x8dct:no-fast-pskip" forKey:@"x264Option"];
3807 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3808 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3809 [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
3810 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3812 /* Video framerate */
3813 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3815 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3816 /* 2 Pass Encoding */
3817 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3818 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3820 /*Picture Settings*/
3821 //hb_job_t * job = fTitle->job;
3822 /* Basic Picture Settings */
3823 /* Use Max Picture settings for whatever the dvd is.*/
3824 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3825 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3826 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3827 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3828 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3829 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3830 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3831 /* Set crop settings here */
3832 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3833 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3834 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3835 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3836 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3839 /* Audio Sample Rate*/
3840 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3841 /* Audio Bitrate Rate*/
3842 [preset setObject:@"160" forKey:@"AudioBitRate"];
3844 [preset setObject:@"None" forKey:@"Subtitles"];
3847 [preset autorelease];
3852 - (NSDictionary *)createBrokePreset
3854 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3855 /* Get the New Preset Name from the field in the AddPresetPanel */
3856 [preset setObject:@"Broke" forKey:@"PresetName"];
3857 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3858 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3859 /*Set whether or not this is default, at creation set to 0*/
3860 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3861 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3862 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3863 /* Get the New Preset Description from the field in the AddPresetPanel */
3864 [preset setObject:@"HandBrake's preset for people without a lot of money to waste on hard drives. Tries to maximize quality for burning to CDs, so you can party like it's 1999." forKey:@"PresetDescription"];
3866 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3867 /* Chapter Markers*/
3868 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3870 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3872 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3873 /* x264 Option String */
3874 [preset setObject:@"ref=3:mixed-refs:bframes=6:bime:weightb:b-rdo:b-pyramid:direct=auto:me=umh:subme=6:trellis=1:analyse=all:8x8dct:no-fast-pskip" forKey:@"x264Option"];
3876 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoQualityType"];
3877 [preset setObject:@"695" forKey:@"VideoTargetSize"];
3878 [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
3879 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3881 /* Video framerate */
3882 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3884 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3885 /* 2 Pass Encoding */
3886 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3887 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3889 /*Picture Settings*/
3890 //hb_job_t * job = fTitle->job;
3891 /* Basic Picture Settings */
3892 /* Use Max Picture settings for whatever the dvd is.*/
3893 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3894 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3895 [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
3896 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3897 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3898 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3899 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3900 /* Set crop settings here */
3901 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3902 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3903 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3904 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3905 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3908 /* Audio Sample Rate*/
3909 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3910 /* Audio Bitrate Rate*/
3911 [preset setObject:@"128" forKey:@"AudioBitRate"];
3913 [preset setObject:@"None" forKey:@"Subtitles"];
3916 [preset autorelease];
3921 - (NSDictionary *)createBlindPreset
3923 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3924 /* Get the New Preset Name from the field in the AddPresetPanel */
3925 [preset setObject:@"Blind" forKey:@"PresetName"];
3926 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3927 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3928 /*Set whether or not this is default, at creation set to 0*/
3929 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3930 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3931 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3932 /* Get the New Preset Description from the field in the AddPresetPanel */
3933 [preset setObject:@"HandBrake's preset for impatient people who don't care about picture quality." forKey:@"PresetDescription"];
3935 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3936 /* Chapter Markers*/
3937 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3939 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3941 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3942 /* x264 Option String */
3943 [preset setObject:@"" forKey:@"x264Option"];
3945 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3946 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3947 [preset setObject:@"512" forKey:@"VideoAvgBitrate"];
3948 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3950 /* Video framerate */
3951 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3953 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3954 /* 2 Pass Encoding */
3955 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3956 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
3958 /*Picture Settings*/
3959 //hb_job_t * job = fTitle->job;
3960 /* Basic Picture Settings */
3961 /* Use Max Picture settings for whatever the dvd is.*/
3962 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3963 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3964 [preset setObject:[NSNumber numberWithInt:512] forKey:@"PictureWidth"];
3965 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3966 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3967 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3968 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3969 /* Set crop settings here */
3970 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3971 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3972 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3973 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3974 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3977 /* Audio Sample Rate*/
3978 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3979 /* Audio Bitrate Rate*/
3980 [preset setObject:@"128" forKey:@"AudioBitRate"];
3982 [preset setObject:@"None" forKey:@"Subtitles"];
3985 [preset autorelease];
3990 - (NSDictionary *)createCRFPreset
3992 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3993 /* Get the New Preset Name from the field in the AddPresetPanel */
3994 [preset setObject:@"Constant Quality Rate" forKey:@"PresetName"];
3995 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3996 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3997 /*Set whether or not this is default, at creation set to 0*/
3998 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3999 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4000 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4001 /* Get the New Preset Description from the field in the AddPresetPanel */
4002 [preset setObject:@"HandBrake's preset for consistently excellent quality in one pass, with the downside of entirely unpredictable file sizes and bitrates." forKey:@"PresetDescription"];
4004 [preset setObject:@"MKV file" forKey:@"FileFormat"];
4005 /* Chapter Markers*/
4006 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4008 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4010 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4011 /* x264 Option String */
4012 [preset setObject:@"ref=3:mixed-refs:bframes=3:b-pyramid:b-rdo:bime:weightb:filter=-2,-1:subme=6:trellis=1:analyse=all:8x8dct:me=umh" forKey:@"x264Option"];
4014 [preset setObject:[NSNumber numberWithInt:2] forKey:@"VideoQualityType"];
4015 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4016 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4017 [preset setObject:[NSNumber numberWithFloat:0.6471] forKey:@"VideoQualitySlider"];
4019 /* Video framerate */
4020 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4022 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4023 /* 2 Pass Encoding */
4024 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4025 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
4027 /*Picture Settings*/
4028 //hb_job_t * job = fTitle->job;
4029 /* Basic Picture Settings */
4030 /* Use Max Picture settings for whatever the dvd is.*/
4031 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4032 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4033 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4034 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4035 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4036 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4037 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4038 /* Set crop settings here */
4039 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4040 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4041 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4042 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4043 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4046 /* Audio Sample Rate*/
4047 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4048 /* Audio Bitrate Rate*/
4049 [preset setObject:@"160" forKey:@"AudioBitRate"];
4051 [preset setObject:@"None" forKey:@"Subtitles"];
4054 [preset autorelease];
4060 - (IBAction)deletePreset:(id)sender
4063 NSEnumerator *enumerator;
4065 NSMutableArray *tempArray;
4068 if ( [tableView numberOfSelectedRows] == 0 )
4070 /* Alert user before deleting preset */
4071 /* Comment out for now, tie to user pref eventually */
4074 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
4076 if ( status == NSAlertDefaultReturn ) {
4077 enumerator = [tableView selectedRowEnumerator];
4078 tempArray = [NSMutableArray array];
4080 while ( (index = [enumerator nextObject]) ) {
4081 tempObject = [UserPresets objectAtIndex:[index intValue]];
4082 [tempArray addObject:tempObject];
4085 [UserPresets removeObjectsInArray:tempArray];
4086 [tableView reloadData];
4091 - (IBAction)getDefaultPresets:(id)sender
4094 NSEnumerator *enumerator = [UserPresets objectEnumerator];
4096 while (tempObject = [enumerator nextObject])
4098 NSDictionary *thisPresetDict = tempObject;
4099 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
4101 presetHbDefault = i;
4103 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
4105 presetUserDefault = i;
4111 - (IBAction)setDefaultPreset:(id)sender
4114 NSEnumerator *enumerator = [UserPresets objectEnumerator];
4116 /* First make sure the old user specified default preset is removed */
4117 while (tempObject = [enumerator nextObject])
4119 /* make sure we are not removing the default HB preset */
4120 if ([[[UserPresets objectAtIndex:i] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4122 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4126 /* Second, go ahead and set the appropriate user specfied preset */
4127 /* we get the chosen preset from the UserPresets array */
4128 if ([[[UserPresets objectAtIndex:[tableView selectedRow]] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4130 [[UserPresets objectAtIndex:[tableView selectedRow]] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
4132 presetUserDefault = [tableView selectedRow];
4134 /* We save all of the preset data here */
4136 /* We Reload the New Table data for presets */
4137 [tableView reloadData];
4140 - (IBAction)selectDefaultPreset:(id)sender
4142 /* if there is a user specified default, we use it */
4143 if (presetUserDefault)
4145 [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetUserDefault] byExtendingSelection:NO];
4146 [self tableViewSelected:NULL];
4148 else if (presetHbDefault) //else we use the built in default presetHbDefault
4150 [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetHbDefault] byExtendingSelection:NO];
4151 [self tableViewSelected:NULL];
4155 - (IBAction)tableViewSelected:(id)sender
4157 /* Since we cannot disable the presets tableView in terms of clickability
4158 we will use the enabled state of the add presets button to determine whether
4159 or not clicking on a preset will do anything */
4160 if ([fPresetsAdd isEnabled])
4162 if ([tableView selectedRow] >= 0)
4164 /* we get the chosen preset from the UserPresets array */
4165 chosenPreset = [UserPresets objectAtIndex:[tableView selectedRow]];
4166 curUserPresetChosenNum = [sender selectedRow];
4167 /* we set the preset display field in main window here */
4168 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
4169 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
4171 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@ (Default)",[chosenPreset valueForKey:@"PresetName"]]];
4175 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
4178 [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
4179 [self formatPopUpChanged: NULL];
4181 /* Chapter Markers*/
4182 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
4183 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
4184 [fDstMpgLargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
4186 [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
4187 [self codecsPopUpChanged: NULL];
4189 [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
4191 /* We can show the preset options here in the gui if we want to
4192 so we check to see it the user has specified it in the prefs */
4193 [fAdvancedOptions setOptions: [NSString stringWithFormat:[chosenPreset valueForKey:@"x264Option"]]];
4195 /* Lets run through the following functions to get variables set there */
4196 [self encoderPopUpChanged: NULL];
4198 [self calculateBitrate: NULL];
4201 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
4203 [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
4204 [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
4206 [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
4207 [self videoMatrixChanged: NULL];
4209 /* Video framerate */
4210 [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
4213 [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
4215 /* 2 Pass Encoding */
4216 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
4217 [self twoPassCheckboxChanged: NULL];
4218 /* Turbo 1st pass for 2 Pass Encoding */
4219 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
4223 /* Audio Sample Rate*/
4224 [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
4225 /* Audio Bitrate Rate*/
4226 [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
4228 [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
4230 /* Picture Settings */
4231 /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
4232 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
4234 hb_job_t * job = fTitle->job;
4235 /* Check to see if we should use the max picture setting for the current title*/
4236 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
4238 /* Use Max Picture settings for whatever the dvd is.*/
4239 [self revertPictureSizeToMax: NULL];
4240 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
4241 if (job->keep_ratio == 1)
4243 hb_fix_aspect( job, HB_KEEP_WIDTH );
4244 if( job->height > fTitle->height )
4246 job->height = fTitle->height;
4247 hb_fix_aspect( job, HB_KEEP_HEIGHT );
4250 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
4252 else // Apply picture settings that were in effect at the time the preset was saved
4254 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
4255 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
4256 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
4257 if (job->keep_ratio == 1)
4259 hb_fix_aspect( job, HB_KEEP_WIDTH );
4260 if( job->height > fTitle->height )
4262 job->height = fTitle->height;
4263 hb_fix_aspect( job, HB_KEEP_HEIGHT );
4266 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
4267 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
4269 if ([chosenPreset objectForKey:@"PictureDetelecine"])
4271 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
4273 if ([chosenPreset objectForKey:@"PictureDenoise"])
4275 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
4277 /* If Cropping is set to custom, then recall all four crop values from
4278 when the preset was created and apply them */
4279 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
4281 [fPictureController setAutoCrop:NO];
4283 /* Here we use the custom crop values saved at the time the preset was saved */
4284 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
4285 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
4286 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
4287 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
4290 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
4292 [fPictureController setAutoCrop:YES];
4293 /* Here we use the auto crop values determined right after scan */
4294 job->crop[0] = AutoCropTop;
4295 job->crop[1] = AutoCropBottom;
4296 job->crop[2] = AutoCropLeft;
4297 job->crop[3] = AutoCropRight;
4301 [self calculatePictureSizing: NULL];
4305 [[fPresetsActionMenu itemAtIndex:0] setEnabled: YES];
4312 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
4314 return [UserPresets count];
4317 /* we use this to determine display characteristics for
4318 each table cell based on content currently only used to
4319 show the built in presets in a blue font. */
4320 - (void)tableView:(NSTableView *)aTableView
4321 willDisplayCell:(id)aCell
4322 forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
4324 NSDictionary *userPresetDict = [UserPresets objectAtIndex:rowIndex];
4327 NSColor *shadowColor;
4328 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
4329 /* First, we check to see if its a selected row, if so, we use white since its highlighted in blue */
4330 if ([[aTableView selectedRowIndexes] containsIndex:rowIndex] && ([tableView editedRow] != rowIndex))
4333 fontColor = [NSColor whiteColor];
4334 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
4338 /* We set the properties of unselected rows */
4339 /* if built-in preset (defined by "type" == 0) we use a blue font */
4340 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
4342 fontColor = [NSColor blueColor];
4344 else // User created preset, use a black font
4346 fontColor = [NSColor blackColor];
4350 /* We check to see if this is the HB default, if so, color it appropriately */
4351 if (!presetUserDefault && presetHbDefault && rowIndex == presetHbDefault)
4353 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4355 /* We check to see if this is the User Specified default, if so, color it appropriately */
4356 if (presetUserDefault && rowIndex == presetUserDefault)
4358 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4361 [aCell setTextColor:fontColor];
4362 [aCell setFont:txtFont];
4363 /* this shadow stuff (like mail app) for some reason looks crappy, commented out
4364 temporarily in case we want to resurrect it */
4366 NSShadow *shadow = [[NSShadow alloc] init];
4367 NSSize shadowOffset = { width: 1.0, height: -1.5};
4368 [shadow setShadowOffset:shadowOffset];
4369 [shadow setShadowColor:shadowColor];
4374 /* Method to display tooltip with the description for each preset, if available */
4375 - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell
4376 rect:(NSRectPointer)aRect tableColumn:(NSTableColumn *)aTableColumn
4377 row:(int)rowIndex mouseLocation:(NSPoint)aPos
4379 /* initialize the tooltip contents variable */
4381 /* if there is a description for the preset, we show it in the tooltip */
4382 if ([[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"])
4384 loc_tip = [NSString stringWithFormat: @"%@",[[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"]];
4389 loc_tip = @"No description available";
4395 - (id)tableView:(NSTableView *)aTableView
4396 objectValueForTableColumn:(NSTableColumn *)aTableColumn
4399 id theRecord, theValue;
4401 theRecord = [UserPresets objectAtIndex:rowIndex];
4402 theValue = [theRecord objectForKey:[aTableColumn identifier]];
4406 // NSTableDataSource method that we implement to edit values directly in the table...
4407 - (void)tableView:(NSTableView *)aTableView
4408 setObjectValue:(id)anObject
4409 forTableColumn:(NSTableColumn *)aTableColumn
4414 theRecord = [UserPresets objectAtIndex:rowIndex];
4415 [theRecord setObject:anObject forKey:@"PresetName"];
4416 /* We Sort the Presets By Factory or Custom */
4417 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
4418 ascending:YES] autorelease];
4419 /* We Sort the Presets Alphabetically by name */
4420 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
4421 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
4422 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
4423 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
4424 [UserPresets setArray:sortedArray];
4425 /* We Reload the New Table data for presets */
4426 [tableView reloadData];
4427 /* We save all of the preset data here */
4433 [UserPresets writeToFile:UserPresetsFile atomically:YES];
4434 /* We get the default preset in case it changed */
4435 [self getDefaultPresets: NULL];
4439 - (void) controlTextDidBeginEditing: (NSNotification *) notification
4441 [self calculateBitrate: NULL];
4444 - (void) controlTextDidEndEditing: (NSNotification *) notification
4446 [self calculateBitrate: NULL];
4449 - (void) controlTextDidChange: (NSNotification *) notification
4451 [self calculateBitrate: NULL];
4454 - (IBAction) openHomepage: (id) sender
4456 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4457 URLWithString:@"http://handbrake.m0k.org/"]];
4460 - (IBAction) openForums: (id) sender
4462 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4463 URLWithString:@"http://handbrake.m0k.org/forum/"]];
4465 - (IBAction) openUserGuide: (id) sender
4467 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4468 URLWithString:@"http://handbrake.m0k.org/trac/wiki/HandBrakeGuide"]];
4472 * Shows debug output window.
4474 - (IBAction)showDebugOutputPanel:(id)sender
4476 [outputPanel showOutputPanel:sender];
4480 * Creates preferences controller, shows preferences window modally, and
4481 * releases the controller after user has closed the window.
4483 - (IBAction)showPreferencesWindow:(id)sender
4485 HBPreferencesController *controller = [[HBPreferencesController alloc] init];
4486 [controller runModal:nil];
4487 [controller release];
4491 * Shows queue window.
4493 - (IBAction) showQueueWindow:(id)sender
4495 [fQueueController showQueueWindow:sender];
4499 - (IBAction) toggleDrawer:(id)sender {
4500 [fPresetDrawer toggle:self];