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];
86 fPreferencesController = [[HBPreferencesController alloc] init];
90 - (void) applicationDidFinishLaunching: (NSNotification *) notification
96 int debugLevel = [[NSUserDefaults standardUserDefaults] boolForKey:@"ShowVerboseOutput"] ? HB_DEBUG_ALL : HB_DEBUG_NONE;
97 fHandle = hb_init(debugLevel, [[NSUserDefaults standardUserDefaults] boolForKey:@"CheckForUpdates"]);
99 // Set the Growl Delegate
100 [GrowlApplicationBridge setGrowlDelegate: self];
101 /* Init others controllers */
102 [fPictureController SetHandle: fHandle];
103 [fQueueController setHandle: fHandle];
105 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
106 [fChapterTable setDataSource:fChapterTitlesDelegate];
108 /* Call UpdateUI every 1/2 sec */
109 [[NSRunLoop currentRunLoop] addTimer: [NSTimer
110 scheduledTimerWithTimeInterval: 0.5 target: self
111 selector: @selector( updateUI: ) userInfo: NULL repeats: YES]
112 forMode: NSEventTrackingRunLoopMode];
114 if( ( build = hb_check_update( fHandle, &version ) ) > -1 )
116 /* Update available - tell the user */
118 NSBeginInformationalAlertSheet( _( @"Update is available" ),
119 _( @"Go get it!" ), _( @"Discard" ), NULL, fWindow, self,
120 @selector( updateAlertDone:returnCode:contextInfo: ),
121 NULL, NULL, [NSString stringWithFormat:
122 _( @"HandBrake %s (build %d) is now available for download." ),
128 // Open debug output window now if it was visible when HB was closed
129 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
130 [self showDebugOutputPanel:nil];
132 // Open queue window now if it was visible when HB was closed
133 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
134 [self showQueueWindow:nil];
136 [self openMainWindow:nil];
138 /* Show scan panel ASAP */
139 [self performSelectorOnMainThread: @selector(showScanPanel:)
140 withObject: NULL waitUntilDone: NO];
143 - (NSApplicationTerminateReply) applicationShouldTerminate:
144 (NSApplication *) app
147 hb_get_state2( fHandle, &s );
148 if ( s.state == HB_STATE_WORKING )
151 return NSTerminateCancel;
153 return NSTerminateNow;
156 - (void)applicationWillTerminate:(NSNotification *)aNotification
158 [outputPanel release];
159 [fQueueController release];
164 - (void) awakeFromNib
167 [fWindow setExcludedFromWindowsMenu:YES];
168 [fAdvancedOptions setView:fAdvancedView];
170 /* Initialize currentScanCount so HB can use it to
171 evaluate successive scans */
172 currentScanCount = 0;
174 /* Init UserPresets .plist */
177 fRipIndicatorShown = NO; // initially out of view in the nib
179 /* Show/Dont Show Presets drawer upon launch based
180 on user preference DefaultPresetsDrawerShow*/
181 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
183 [fPresetDrawer open];
188 [fDstFormatPopUp removeAllItems];
189 [fDstFormatPopUp addItemWithTitle: _( @"MP4 file" )];
190 [fDstFormatPopUp addItemWithTitle: _( @"AVI file" )];
191 [fDstFormatPopUp addItemWithTitle: _( @"OGM file" )];
192 [fDstFormatPopUp addItemWithTitle: _( @"MKV file" )];
193 [fDstFormatPopUp selectItemAtIndex: 0];
195 [self formatPopUpChanged: NULL];
197 /* We enable the create chapters checkbox here since we are .mp4 */
198 [fCreateChapterMarkers setEnabled: YES];
199 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
201 [fCreateChapterMarkers setState: NSOnState];
207 [fDstFile2Field setStringValue: [NSString stringWithFormat:
208 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
211 [fVidEncoderPopUp removeAllItems];
212 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
213 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
218 [fVidTargetSizeField setIntValue: 700];
219 [fVidBitrateField setIntValue: 1000];
221 [fVidQualityMatrix selectCell: fVidBitrateCell];
222 [self videoMatrixChanged: NULL];
224 /* Video framerate */
225 [fVidRatePopUp removeAllItems];
226 [fVidRatePopUp addItemWithTitle: _( @"Same as source" )];
227 for( int i = 0; i < hb_video_rates_count; i++ )
229 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
231 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
232 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
234 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
236 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
237 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
239 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
241 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
242 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
246 [fVidRatePopUp addItemWithTitle:
247 [NSString stringWithCString: hb_video_rates[i].string]];
250 [fVidRatePopUp selectItemAtIndex: 0];
252 /* Picture Settings */
253 [fPicLabelPAROutputX setStringValue: @""];
254 [fPicSettingPARWidth setStringValue: @""];
255 [fPicSettingPARHeight setStringValue: @""];
257 /* Set Auto Crop to On at launch */
258 [fPictureController setAutoCrop:YES];
261 [fAudBitratePopUp removeAllItems];
262 for( int i = 0; i < hb_audio_bitrates_count; i++ )
264 [fAudBitratePopUp addItemWithTitle:
265 [NSString stringWithCString: hb_audio_bitrates[i].string]];
268 [fAudBitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
270 /* Audio samplerate */
271 [fAudRatePopUp removeAllItems];
272 for( int i = 0; i < hb_audio_rates_count; i++ )
274 [fAudRatePopUp addItemWithTitle:
275 [NSString stringWithCString: hb_audio_rates[i].string]];
277 [fAudRatePopUp selectItemAtIndex: hb_audio_rates_default];
280 [fStatusField setStringValue: @""];
285 [fPresetsActionButton setMenu:fPresetsActionMenu];
287 /* We disable the Turbo 1st pass checkbox since we are not x264 */
288 [fVidTurboPassCheck setEnabled: NO];
289 [fVidTurboPassCheck setState: NSOffState];
292 /* lets get our default prefs here */
293 [self getDefaultPresets: NULL];
294 /* lets initialize the current successful scancount here to 0 */
295 currentSuccessfulScanCount = 0;
299 - (void) loadPresets {
300 /* We declare the default NSFileManager into fileManager */
301 NSFileManager * fileManager = [NSFileManager defaultManager];
302 /* we set the files and support paths here */
303 AppSupportDirectory = @"~/Library/Application Support/HandBrake";
304 AppSupportDirectory = [AppSupportDirectory stringByExpandingTildeInPath];
305 //UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
306 //UserPresetsFile = [UserPresetsFile stringByExpandingTildeInPath];
307 /* We check for the app support directory for handbrake */
308 if ([fileManager fileExistsAtPath:AppSupportDirectory] == 0)
310 // If it doesnt exist yet, we create it here
311 [fileManager createDirectoryAtPath:AppSupportDirectory attributes:nil];
313 /* We check for the presets.plist here */
314 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
316 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
318 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
319 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
321 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
322 if (nil == UserPresets)
324 UserPresets = [[NSMutableArray alloc] init];
325 [self addFactoryPresets:NULL];
330 // ============================================================
331 // NSToolbar Related Methods
332 // ============================================================
334 - (void) setupToolbar {
335 toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
337 [toolbar setAllowsUserCustomization: YES];
338 [toolbar setAutosavesConfiguration: YES];
339 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
341 [toolbar setDelegate: self];
343 [fWindow setToolbar: toolbar];
346 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
347 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
348 NSToolbarItem * item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
350 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
352 [item setLabel: @"Toggle Presets"];
353 [item setPaletteLabel: @"Toggler Presets"];
354 [item setToolTip: @"Open/Close Preset Drawer"];
355 [item setImage: [NSImage imageNamed: @"Drawer-List2"]];
356 [item setTarget: self];
357 [item setAction: @selector(toggleDrawer:)];
358 [item setAutovalidates: NO];
360 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
362 [item setLabel: @"Start"];
363 [item setPaletteLabel: @"Start Encoding"];
364 [item setToolTip: @"Start Encoding"];
365 [item setImage: [NSImage imageNamed: @"Play"]];
366 [item setTarget: self];
367 [item setAction: @selector(Rip:)];
369 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
371 [item setLabel: @"Show Queue"];
372 [item setPaletteLabel: @"Show Queue"];
373 [item setToolTip: @"Show Queue"];
374 [item setImage: [NSImage imageNamed: @"Brushed Window"]];
375 [item setTarget: self];
376 [item setAction: @selector(showQueueWindow:)];
377 [item setAutovalidates: NO];
379 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
381 [item setLabel: @"Add to Queue"];
382 [item setPaletteLabel: @"Add to Queue"];
383 [item setToolTip: @"Add to Queue"];
384 [item setImage: [NSImage imageNamed: @"Add"]];
385 [item setTarget: self];
386 [item setAction: @selector(addToQueue:)];
388 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
390 [item setLabel: @"Pause"];
391 [item setPaletteLabel: @"Pause Encoding"];
392 [item setToolTip: @"Pause Encoding"];
393 [item setImage: [NSImage imageNamed: @"Pause"]];
394 [item setTarget: self];
395 [item setAction: @selector(Pause:)];
397 else if ([itemIdent isEqualToString: ShowActivityIdentifier]) {
398 [item setLabel: @"Activity Window"];
399 [item setPaletteLabel: @"Show Activity Window"];
400 [item setToolTip: @"Show Activity Window"];
401 [item setImage: [NSImage imageNamed: @"Terminal"]];
402 [item setTarget: self];
403 [item setAction: @selector(showDebugOutputPanel:)];
404 [item setAutovalidates: NO];
406 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
408 [item setLabel: @"Source"];
409 [item setPaletteLabel: @"Source"];
410 [item setToolTip: @"Choose Video Source"];
411 [item setImage: [NSImage imageNamed: @"Disc"]];
412 [item setTarget: self];
413 [item setAction: @selector(showScanPanel:)];
414 [item setAutovalidates: NO];
425 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
427 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
428 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
429 NSToolbarSpaceItemIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
432 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
434 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
435 ChooseSourceIdentifier, ShowQueueIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
436 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSpaceItemIdentifier,
437 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
440 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
442 NSString * ident = [toolbarItem itemIdentifier];
447 hb_get_state2( fHandle, &s );
449 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
451 if ([ident isEqualToString: StartEncodingIdentifier])
453 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
454 [toolbarItem setLabel: @"Cancel"];
455 [toolbarItem setPaletteLabel: @"Cancel"];
456 [toolbarItem setToolTip: @"Cancel Encoding"];
459 if ([ident isEqualToString: PauseEncodingIdentifier])
461 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
462 [toolbarItem setLabel: @"Pause"];
463 [toolbarItem setPaletteLabel: @"Pause Encoding"];
464 [toolbarItem setToolTip: @"Pause Encoding"];
468 if ([ident isEqualToString: AddToQueueIdentifier])
471 else if (s.state == HB_STATE_PAUSED)
473 if ([ident isEqualToString: PauseEncodingIdentifier])
475 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
476 [toolbarItem setLabel: @"Resume"];
477 [toolbarItem setPaletteLabel: @"Resume Encoding"];
478 [toolbarItem setToolTip: @"Resume Encoding"];
481 if ([ident isEqualToString: StartEncodingIdentifier])
483 if ([ident isEqualToString: AddToQueueIdentifier])
486 else if (s.state == HB_STATE_SCANNING)
488 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
490 if ([ident isEqualToString: StartEncodingIdentifier])
492 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
493 [toolbarItem setLabel: @"Start"];
494 [toolbarItem setPaletteLabel: @"Start Encoding"];
495 [toolbarItem setToolTip: @"Start Encoding"];
498 if ([ident isEqualToString: AddToQueueIdentifier])
504 if ([ident isEqualToString: ShowQueueIdentifier])
506 if ([ident isEqualToString: ToggleDrawerIdentifier])
508 if ([ident isEqualToString: ChooseSourceIdentifier])
510 if ([ident isEqualToString: ShowActivityIdentifier])
516 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
518 SEL action = [menuItem action];
521 hb_get_state2( fHandle, &s );
525 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
526 return SuccessfulScan && [fWindow attachedSheet] == nil;
528 if (action == @selector(showScanPanel:))
530 if (s.state == HB_STATE_SCANNING)
533 return [fWindow attachedSheet] == nil;
535 if (action == @selector(selectDefaultPreset:))
536 return [tableView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
537 if (action == @selector(Pause:))
539 if (s.state == HB_STATE_WORKING)
541 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
542 [menuItem setTitle:@"Pause Encoding"];
545 else if (s.state == HB_STATE_PAUSED)
547 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
548 [menuItem setTitle:@"Resume Encoding"];
554 if (action == @selector(Rip:))
555 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
557 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
558 [menuItem setTitle:@"Stop Encoding"];
561 else if (SuccessfulScan)
563 if(![[menuItem title] isEqualToString:@"Start Encoding"])
564 [menuItem setTitle:@"Start Encoding"];
565 return [fWindow attachedSheet] == nil;
575 // register a test notification and make
576 // it enabled by default
577 #define SERVICE_NAME @"Encode Done"
578 - (NSDictionary *)registrationDictionaryForGrowl
580 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
581 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
582 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
585 return registrationDictionary;
588 - (void) TranslateStrings
590 [fSrcTitleField setStringValue: _( @"Title:" )];
591 [fSrcChapterField setStringValue: _( @"Chapters:" )];
592 [fSrcChapterToField setStringValue: _( @"to" )];
593 [fSrcDuration1Field setStringValue: _( @"Duration:" )];
595 [fDstFormatField setStringValue: _( @"Format:" )];
596 [fDstCodecsField setStringValue: _( @"Codecs:" )];
597 [fDstFile1Field setStringValue: _( @"File:" )];
598 [fDstBrowseButton setTitle: _( @"Browse" )];
600 [fVidRateField setStringValue: _( @"Framerate (fps):" )];
601 [fVidEncoderField setStringValue: _( @"Encoder:" )];
602 [fVidQualityField setStringValue: _( @"Quality:" )];
605 /***********************************************************************
607 ***********************************************************************
608 * Shows a progression bar on the dock icon, filled according to
609 * 'progress' (0.0 <= progress <= 1.0).
610 * Called with progress < 0.0 or progress > 1.0, restores the original
612 **********************************************************************/
613 - (void) UpdateDockIcon: (float) progress
617 NSBitmapImageRep * bmp;
619 uint32_t black = htonl( 0x000000FF );
620 uint32_t red = htonl( 0xFF0000FF );
621 uint32_t white = htonl( 0xFFFFFFFF );
622 int row_start, row_end;
625 /* Get application original icon */
626 icon = [NSImage imageNamed: @"NSApplicationIcon"];
628 if( progress < 0.0 || progress > 1.0 )
630 [NSApp setApplicationIconImage: icon];
634 /* Get it in a raw bitmap form */
635 tiff = [icon TIFFRepresentationUsingCompression:
636 NSTIFFCompressionNone factor: 1.0];
637 bmp = [NSBitmapImageRep imageRepWithData: tiff];
639 /* Draw the progression bar */
640 /* It's pretty simple (ugly?) now, but I'm no designer */
642 row_start = 3 * (int) [bmp size].height / 4;
643 row_end = 7 * (int) [bmp size].height / 8;
645 for( i = row_start; i < row_start + 2; i++ )
647 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
648 for( j = 0; j < (int) [bmp size].width; j++ )
653 for( i = row_start + 2; i < row_end - 2; i++ )
655 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
658 for( j = 2; j < (int) [bmp size].width - 2; j++ )
660 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
672 for( i = row_end - 2; i < row_end; i++ )
674 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
675 for( j = 0; j < (int) [bmp size].width; j++ )
681 /* Now update the dock icon */
682 tiff = [bmp TIFFRepresentationUsingCompression:
683 NSTIFFCompressionNone factor: 1.0];
684 icon = [[NSImage alloc] initWithData: tiff];
685 [NSApp setApplicationIconImage: icon];
689 - (void) updateUI: (NSTimer *) timer
693 list = hb_get_titles( fHandle );
694 /* check to see if there has been a new scan done
695 this bypasses the constraints of HB_STATE_WORKING
696 not allowing setting a newly scanned source */
697 int checkScanCount = hb_get_scancount( fHandle );
698 if (checkScanCount > currentScanCount)
701 currentScanCount = checkScanCount;
702 //[fScanController Cancel: NULL];
703 [fScanIndicator setIndeterminate: NO];
704 [fScanIndicator setDoubleValue: 0.0];
705 [fScanIndicator setHidden: YES];
707 [self showNewScan: NULL];
710 BOOL jobGroups = [[NSUserDefaults standardUserDefaults] boolForKey:@"QueueShowsJobsAsGroups"];
713 hb_get_state( fHandle, &s );
720 #define p s.param.scanning
721 case HB_STATE_SCANNING:
723 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
724 _( @"Scanning title %d of %d..." ),
725 p.title_cur, p.title_count]];
726 [fScanIndicator setIndeterminate: NO];
727 [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) /
733 #define p s.param.scandone
734 case HB_STATE_SCANDONE:
737 [fScanIndicator setIndeterminate: NO];
738 [fScanIndicator setDoubleValue: 0.0];
739 [fScanIndicator setHidden: YES];
740 [self showNewScan: NULL];
741 [toolbar validateVisibleItems];
746 #define p s.param.working
747 case HB_STATE_WORKING:
749 float progress_total;
750 NSMutableString * string;
751 /* Currently, p.job_cur and p.job_count get screwed up when adding
752 jobs during encoding, if they cannot be fixed in libhb, will implement a
753 nasty but working cocoa solution */
754 /* Update text field */
755 string = [NSMutableString stringWithFormat: _( @"Encoding: task %d of %d, %.2f %%" ), p.job_cur, p.job_count, 100.0 * p.progress];
759 [string appendFormat:
760 _( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)" ),
761 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
763 [fStatusField setStringValue: string];
766 progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
767 [fRipIndicator setIndeterminate: NO];
768 [fRipIndicator setDoubleValue: 100.0 * progress_total];
770 // If progress bar hasn't been revealed at the bottom of the window, do
771 // that now. This code used to be in _Rip. I moved it to here to handle
772 // the case where hb_start is called by HBQueueController and not from
774 if (!fRipIndicatorShown)
776 NSRect frame = [fWindow frame];
777 if (frame.size.width <= 591)
778 frame.size.width = 591;
779 frame.size.height += 36;
780 frame.origin.y -= 36;
781 [fWindow setFrame:frame display:YES animate:YES];
782 fRipIndicatorShown = YES;
785 /* Update dock icon */
786 [self UpdateDockIcon: progress_total];
788 // Has current job changed? That means the queue has probably changed as
790 if (fLastKnownCurrentJob != hb_current_job(fHandle))
792 fLastKnownCurrentJob = hb_current_job(fHandle);
793 [fQueueController updateQueueUI];
795 [fQueueController updateCurrentJobUI];
801 #define p s.param.muxing
802 case HB_STATE_MUXING:
804 NSMutableString * string;
806 /* Update text field */
807 string = [NSMutableString stringWithFormat:
809 [fStatusField setStringValue: string];
812 [fRipIndicator setIndeterminate: YES];
813 [fRipIndicator startAnimation: nil];
815 /* Update dock icon */
816 [self UpdateDockIcon: 1.0];
818 // Pass along the info to HBQueueController
819 [fQueueController updateCurrentJobUI];
825 case HB_STATE_PAUSED:
826 [fStatusField setStringValue: _( @"Paused" )];
828 // Pass along the info to HBQueueController
829 [fQueueController updateCurrentJobUI];
833 case HB_STATE_WORKDONE:
835 [fStatusField setStringValue: _( @"Done." )];
836 [fRipIndicator setIndeterminate: NO];
837 [fRipIndicator setDoubleValue: 0.0];
838 [toolbar validateVisibleItems];
840 /* Restore dock icon */
841 [self UpdateDockIcon: -1.0];
845 // Delete all remaining scans of this job
847 while( ( job = hb_job( fHandle, 0 ) ) && (job->sequence_id != 0) )
848 hb_rem( fHandle, job );
851 // Start processing back up if jobs still left in queue
852 if (hb_count(fHandle) > 0)
858 if (fRipIndicatorShown)
860 NSRect frame = [fWindow frame];
861 if (frame.size.width <= 591)
862 frame.size.width = 591;
863 frame.size.height += -36;
864 frame.origin.y -= -36;
865 [fWindow setFrame:frame display:YES animate:YES];
866 fRipIndicatorShown = NO;
869 // Queue has been modified so update the UI
870 fLastKnownCurrentJob = nil;
871 [fQueueController updateQueueUI];
872 [fQueueController updateCurrentJobUI];
874 /* Check to see if the encode state has not been cancelled
875 to determine if we should check for encode done notifications */
876 if (fEncodeState != 2) {
877 /* If Growl Notification or Window and Growl has been selected */
878 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
879 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
881 /*Growl Notification*/
882 [self showGrowlDoneNotification: NULL];
884 /* If Alert Window or Window and Growl has been selected */
885 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
886 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
888 /*On Screen Notification*/
891 status = NSRunAlertPanel(@"Put down that cocktail...",@"your HandBrake encode is done!", @"OK", nil, nil);
892 [NSApp requestUserAttention:NSCriticalRequest];
893 if ( status == NSAlertDefaultReturn )
895 [self enableUI: YES];
900 [self enableUI: YES];
902 /* If sleep has been selected */
903 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
906 NSDictionary* errorDict;
907 NSAppleEventDescriptor* returnDescriptor = NULL;
908 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
909 @"tell application \"Finder\" to sleep"];
910 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
911 [scriptObject release];
912 [self enableUI: YES];
914 /* If Shutdown has been selected */
915 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
918 NSDictionary* errorDict;
919 NSAppleEventDescriptor* returnDescriptor = NULL;
920 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
921 @"tell application \"Finder\" to shut down"];
922 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
923 [scriptObject release];
924 [self enableUI: YES];
927 // MetaX insertion via AppleScript
928 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
930 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", [fDstFile2Field stringValue], @"\")"]];
931 [myScript executeAndReturnError: nil];
939 [self enableUI: YES];
945 /* Lets show the queue status here in the main window */
946 int queue_count = jobGroups ? hb_group_count( fHandle ) : hb_count( fHandle );
949 [fQueueStatus setStringValue: [NSString stringWithFormat:
950 @"%d task%s in the queue",
951 queue_count, ( queue_count > 1 ) ? "s" : ""]];
955 [fQueueStatus setStringValue: @""];
959 - (IBAction) showNewScan:(id)sender
963 int indxpri=0; // Used to search the longuest title (default in combobox)
964 int longuestpri=0; // Used to search the longuest title (default in combobox)
966 list = hb_get_titles( fHandle );
968 if( !hb_list_count( list ) )
970 /* We display a message if a valid dvd source was not chosen */
971 [fSrcDVD2Field setStringValue: @"No Valid Title Found"];
976 /* We increment the successful scancount here by one,
977 which we use at the end of this function to tell the gui
978 if this is the first successful scan since launch and whether
979 or not we should set all settings to the defaults */
982 currentSuccessfulScanCount++;
984 [self enableUI: YES];
986 [toolbar validateVisibleItems];
988 [fSrcTitlePopUp removeAllItems];
989 for( int i = 0; i < hb_list_count( list ); i++ )
991 title = (hb_title_t *) hb_list_item( list, i );
992 /*Set DVD Name at top of window*/
993 [fSrcDVD2Field setStringValue:[NSString stringWithUTF8String: title->name]];
995 currentSource = [NSString stringWithUTF8String: title->dvd];
998 /* Use the dvd name in the default output field here
999 May want to add code to remove blank spaces for some dvd names*/
1000 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1001 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1003 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1004 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[NSString
1005 stringWithUTF8String: title->name]]];
1009 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1010 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[NSString
1011 stringWithUTF8String: title->name]]];
1015 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1017 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1022 int format = [fDstFormatPopUp indexOfSelectedItem];
1028 /*Get Default MP4 File Extension for mpeg4 (.mp4 or .m4v) from prefs*/
1029 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1050 NSString * string = [fDstFile2Field stringValue];
1051 /* Add/replace File Output name to the correct extension*/
1052 if( [string characterAtIndex: [string length] - 4] == '.' )
1054 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1055 @"%@.%s", [string substringToIndex: [string length] - 4],
1060 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1061 @"%@.%s", string, ext]];
1065 [fSrcTitlePopUp addItemWithTitle: [NSString
1066 stringWithFormat: @"%d - %02dh%02dm%02ds",
1067 title->index, title->hours, title->minutes,
1071 // Select the longuest title
1072 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1073 [self titlePopUpChanged: NULL];
1077 [self enableUI: YES];
1079 /* we record the current source name here in case the next scan is unsuccessful,
1080 then we can replace the scan progress with the old name if necessary */
1081 sourceDisplayName = [NSString stringWithFormat:[fSrcDVD2Field stringValue]];
1083 /* if its the initial successful scan after awakeFromNib */
1084 if (currentSuccessfulScanCount == 1)
1086 [self selectDefaultPreset: NULL];
1087 /* if Deinterlace upon launch is specified in the prefs, then set to 1 for "Fast",
1088 if not, then set to 0 for none */
1089 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1090 [fPictureController setDeinterlace:1];
1092 [fPictureController setDeinterlace:0];
1098 -(IBAction)showGrowlDoneNotification:(id)sender
1100 [GrowlApplicationBridge
1101 notifyWithTitle:@"Put down that cocktail..."
1102 description:@"your HandBrake encode is done!"
1103 notificationName:SERVICE_NAME
1110 - (void) enableUI: (bool) b
1112 NSControl * controls[] =
1113 { fSrcTitleField, fSrcTitlePopUp,
1114 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
1115 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
1116 fDstFormatField, fDstFormatPopUp, fDstCodecsField,
1117 fDstCodecsPopUp, fDstFile1Field, fDstFile2Field,
1118 fDstBrowseButton, fVidRateField, fVidRatePopUp,
1119 fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
1120 fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
1121 fAudLang1Field, fAudLang1PopUp, fAudLang2Field, fAudLang2PopUp,
1122 fAudTrack1MixLabel, fAudTrack1MixPopUp, fAudTrack2MixLabel, fAudTrack2MixPopUp,
1123 fAudRateField, fAudRatePopUp, fAudBitrateField,
1124 fAudBitratePopUp, fPictureButton,fQueueStatus,
1125 fPicSrcWidth,fPicSrcHeight,fPicSettingWidth,fPicSettingHeight,fPicSettingARkeep,
1126 fPicSettingDeinterlace,fPicLabelSettings,fPicLabelSrc,fPicLabelOutp,
1127 fPicLabelAr,fPicLabelDeinterlace,fPicLabelSrcX,fPicLabelOutputX,
1128 fPicLabelPAROutputX,fPicSettingPARWidth,fPicSettingPARHeight,
1129 fPicSettingPAR,fPicLabelAnamorphic,tableView,fPresetsAdd,fPresetsDelete,
1130 fCreateChapterMarkers,fVidTurboPassCheck,fDstMpgLargeFileCheck,fPicLabelAutoCrop,
1131 fPicSettingAutoCrop,fPicSettingDetelecine,fPicLabelDetelecine,fPicLabelDenoise,fPicSettingDenoise,fSubForcedCheck,};
1133 for( unsigned i = 0;
1134 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
1136 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
1138 NSTextField * tf = (NSTextField *) controls[i];
1139 if( ![tf isBezeled] )
1141 [tf setTextColor: b ? [NSColor controlTextColor] :
1142 [NSColor disabledControlTextColor]];
1146 [controls[i] setEnabled: b];
1152 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
1153 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
1154 [self setEnabledStateOfAudioMixdownControls: NULL];
1158 [tableView setEnabled: NO];
1162 [self videoMatrixChanged: NULL];
1163 [fAdvancedOptions enableUI:b];
1166 - (IBAction) showScanPanel: (id) sender
1168 [self enableUI: NO];
1170 [self browseSources:NULL];
1173 - (void) browseSources: (id) sender
1175 NSOpenPanel * panel;
1177 panel = [NSOpenPanel openPanel];
1178 [panel setAllowsMultipleSelection: NO];
1179 [panel setCanChooseFiles: YES];
1180 [panel setCanChooseDirectories: YES ];
1181 NSString * sourceDirectory;
1182 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1184 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1188 sourceDirectory = @"~/Desktop";
1189 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1191 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1192 modalForWindow: fWindow modalDelegate: self
1193 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1197 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1198 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1200 /* User selected a file to open */
1201 if( returnCode == NSOKButton )
1203 [fSrcDVD2Field setStringValue: _( @"Opening a new source ..." )];
1204 [fScanIndicator setHidden: NO];
1205 [fScanIndicator setIndeterminate: YES];
1206 [fScanIndicator startAnimation: nil];
1208 /* we set the last source directory in the prefs here */
1209 NSString *sourceDirectory = [[[sheet filenames] objectAtIndex: 0] stringByDeletingLastPathComponent];
1210 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1212 NSString *path = [[sheet filenames] objectAtIndex: 0];
1213 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1214 if( [detector isVideoDVD] )
1216 // The chosen path was actually on a DVD, so use the raw block
1217 // device path instead.
1218 path = [detector devicePath];
1221 hb_scan( fHandle, [path UTF8String], 0 );
1223 else // User clicked Cancel in browse window
1225 /* if we have a title loaded up */
1226 if ([[fSrcDVD2Field stringValue] length] > 0)
1228 [self enableUI: YES];
1233 - (IBAction) openMainWindow: (id) sender
1235 [fWindow makeKeyAndOrderFront:nil];
1236 [fWindow setReleasedWhenClosed: YES];
1239 - (BOOL) windowShouldClose: (id) sender
1241 [fWindow setReleasedWhenClosed: NO];
1245 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1248 [fWindow makeKeyAndOrderFront:nil];
1249 [fWindow setReleasedWhenClosed: YES];
1257 - (IBAction) videoMatrixChanged: (id) sender;
1259 bool target, bitrate, quality;
1261 target = bitrate = quality = false;
1262 if( [fVidQualityMatrix isEnabled] )
1264 switch( [fVidQualityMatrix selectedRow] )
1277 [fVidTargetSizeField setEnabled: target];
1278 [fVidBitrateField setEnabled: bitrate];
1279 [fVidQualitySlider setEnabled: quality];
1280 [fVidTwoPassCheck setEnabled: !quality &&
1281 [fVidQualityMatrix isEnabled]];
1284 [fVidTwoPassCheck setState: NSOffState];
1285 [fVidTurboPassCheck setHidden: YES];
1286 [fVidTurboPassCheck setState: NSOffState];
1289 [self qualitySliderChanged: sender];
1290 [self calculateBitrate: sender];
1291 [self customSettingUsed: sender];
1294 - (IBAction) qualitySliderChanged: (id) sender
1296 [fVidConstantCell setTitle: [NSString stringWithFormat:
1297 _( @"Constant quality: %.0f %%" ), 100.0 *
1298 [fVidQualitySlider floatValue]]];
1299 [self customSettingUsed: sender];
1302 - (IBAction) browseFile: (id) sender
1304 /* Open a panel to let the user choose and update the text field */
1305 NSSavePanel * panel = [NSSavePanel savePanel];
1306 /* We get the current file name and path from the destination field here */
1307 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1308 modalForWindow: fWindow modalDelegate: self
1309 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1313 - (void) browseFileDone: (NSSavePanel *) sheet
1314 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1316 if( returnCode == NSOKButton )
1318 [fDstFile2Field setStringValue: [sheet filename]];
1322 - (IBAction) showPicturePanel: (id) sender
1324 hb_list_t * list = hb_get_titles( fHandle );
1325 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1326 [fSrcTitlePopUp indexOfSelectedItem] );
1327 [fPictureController showPanelInWindow:fWindow forTitle:title];
1330 - (void)pictureSettingsDidChange {
1331 [self calculatePictureSizing: NULL];
1336 hb_list_t * list = hb_get_titles( fHandle );
1337 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1338 [fSrcTitlePopUp indexOfSelectedItem] );
1339 hb_job_t * job = title->job;
1342 /* Chapter selection */
1343 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
1344 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
1346 /* Format and codecs */
1347 int format = [fDstFormatPopUp indexOfSelectedItem];
1348 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1349 job->mux = FormatSettings[format][codecs] & HB_MUX_MASK;
1350 job->vcodec = FormatSettings[format][codecs] & HB_VCODEC_MASK;
1351 job->acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
1352 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
1353 if ([fDstFormatPopUp indexOfSelectedItem] == 0)
1355 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
1356 mpeg4 and the checkbox being checked
1357 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
1358 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0 && [fDstMpgLargeFileCheck state] == NSOnState)
1360 job->largeFileSize = 1;
1364 job->largeFileSize = 0;
1367 if ([fDstFormatPopUp indexOfSelectedItem] == 0 || [fDstFormatPopUp indexOfSelectedItem] == 3)
1369 /* We set the chapter marker extraction here based on the format being
1370 mpeg4 or mkv and the checkbox being checked */
1371 if ([fCreateChapterMarkers state] == NSOnState)
1373 job->chapter_markers = 1;
1377 job->chapter_markers = 0;
1380 if( ( job->vcodec & HB_VCODEC_FFMPEG ) &&
1381 [fVidEncoderPopUp indexOfSelectedItem] > 0 )
1383 job->vcodec = HB_VCODEC_XVID;
1385 if( job->vcodec & HB_VCODEC_X264 )
1387 if ([fVidEncoderPopUp indexOfSelectedItem] > 0 )
1389 /* Just use new Baseline Level 3.0
1390 Lets Deprecate Baseline Level 1.3h264_level*/
1391 job->h264_level = 30;
1392 job->mux = HB_MUX_IPOD;
1393 /* move sanity check for iPod Encoding here */
1394 job->pixel_ratio = 0 ;
1398 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
1399 Currently only used with Constant Quality setting*/
1400 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
1405 /* Below Sends x264 options to the core library if x264 is selected*/
1406 /* Lets use this as per Nyx, Thanks Nyx!*/
1407 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1408 /* Turbo first pass if two pass and Turbo First pass is selected */
1409 if( [fVidTwoPassCheck state] == NSOnState && [fVidTurboPassCheck state] == NSOnState )
1411 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
1412 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0";
1413 /* append the "Turbo" string variable to the existing opts string.
1414 Note: the "Turbo" string must be appended, not prepended to work properly*/
1415 NSString *firstPassOptStringCombined = [[fAdvancedOptions optionsString] stringByAppendingString:firstPassOptStringTurbo];
1416 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
1420 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
1423 job->h264_13 = [fVidEncoderPopUp indexOfSelectedItem];
1426 /* Video settings */
1427 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
1429 job->vrate = 27000000;
1430 job->vrate_base = hb_video_rates[[fVidRatePopUp
1431 indexOfSelectedItem]-1].rate;
1435 job->vrate = title->rate;
1436 job->vrate_base = title->rate_base;
1439 switch( [fVidQualityMatrix selectedRow] )
1443 Bitrate should already have been calculated and displayed
1444 in fVidBitrateField, so let's just use it */
1446 job->vquality = -1.0;
1447 job->vbitrate = [fVidBitrateField intValue];
1450 job->vquality = [fVidQualitySlider floatValue];
1455 job->grayscale = ( [fVidGrayscaleCheck state] == NSOnState );
1457 /* Subtitle settings */
1458 job->subtitle = [fSubPopUp indexOfSelectedItem] - 2;
1460 /* Audio tracks and mixdowns */
1461 /* check for the condition where track 2 has an audio selected, but track 1 does not */
1462 /* we will use track 2 as track 1 in this scenario */
1463 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1465 job->audios[0] = [fAudLang1PopUp indexOfSelectedItem] - 1;
1466 job->audios[1] = [fAudLang2PopUp indexOfSelectedItem] - 1; /* will be -1 if "none" is selected */
1467 job->audios[2] = -1;
1468 job->audio_mixdowns[0] = [[fAudTrack1MixPopUp selectedItem] tag];
1469 job->audio_mixdowns[1] = [[fAudTrack2MixPopUp selectedItem] tag];
1471 else if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1473 job->audios[0] = [fAudLang2PopUp indexOfSelectedItem] - 1;
1474 job->audio_mixdowns[0] = [[fAudTrack2MixPopUp selectedItem] tag];
1475 job->audios[1] = -1;
1479 job->audios[0] = -1;
1482 /* Audio settings */
1483 job->arate = hb_audio_rates[[fAudRatePopUp
1484 indexOfSelectedItem]].rate;
1485 job->abitrate = [[fAudBitratePopUp selectedItem] tag];
1487 job->filters = hb_list_init();
1490 if ([fPictureController detelecine])
1492 hb_list_add( job->filters, &hb_filter_detelecine );
1496 if ([fPictureController deinterlace] == 1)
1498 /* Run old deinterlacer by default */
1499 hb_filter_deinterlace.settings = "-1";
1500 hb_list_add( job->filters, &hb_filter_deinterlace );
1502 else if ([fPictureController deinterlace] == 2)
1504 /* Yadif mode 0 (1-pass with spatial deinterlacing.) */
1505 hb_filter_deinterlace.settings = "0";
1506 hb_list_add( job->filters, &hb_filter_deinterlace );
1508 else if ([fPictureController deinterlace] == 3)
1510 /* Yadif (1-pass w/o spatial deinterlacing) and Mcdeint */
1511 hb_filter_deinterlace.settings = "2:-1:1";
1512 hb_list_add( job->filters, &hb_filter_deinterlace );
1514 else if ([fPictureController deinterlace] == 4)
1516 /* Yadif (2-pass w/ spatial deinterlacing) and Mcdeint*/
1517 hb_filter_deinterlace.settings = "1:-1:1";
1518 hb_list_add( job->filters, &hb_filter_deinterlace );
1523 if ([fPictureController denoise] == 1) // Weak in popup
1525 hb_filter_denoise.settings = "2:1:2:3";
1526 hb_list_add( job->filters, &hb_filter_denoise );
1528 else if ([fPictureController denoise] == 2) // Medium in popup
1530 hb_filter_denoise.settings = "3:2:2:3";
1531 hb_list_add( job->filters, &hb_filter_denoise );
1533 else if ([fPictureController denoise] == 3) // Strong in popup
1535 hb_filter_denoise.settings = "7:7:5:5";
1536 hb_list_add( job->filters, &hb_filter_denoise );
1543 - (IBAction) addToQueue: (id) sender
1545 /* We get the destination directory from the destingation field here */
1546 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1547 /* We check for a valid destination here */
1548 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
1550 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1555 hb_list_t * list = hb_get_titles( fHandle );
1556 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1557 [fSrcTitlePopUp indexOfSelectedItem] );
1558 hb_job_t * job = title->job;
1560 // Assign a sequence number, starting at zero, to each job added so they can
1561 // be lumped together in the UI.
1562 job->sequence_id = -1;
1566 /* Destination file */
1567 job->file = [[fDstFile2Field stringValue] UTF8String];
1569 if( [fSubForcedCheck state] == NSOnState )
1571 job->subtitle_force = 1;
1573 job->subtitle_force = 0;
1577 * subtitle of -1 is a scan
1579 if( job->subtitle == -1 )
1584 * When subtitle scan is enabled do a fast pre-scan job
1585 * which will determine which subtitles to enable, if any.
1588 x264opts_tmp = job->x264opts;
1591 job->x264opts = NULL;
1593 job->subtitle_scan = 1;
1595 job->select_subtitle = (hb_subtitle_t**)malloc(sizeof(hb_subtitle_t*));
1596 *(job->select_subtitle) = NULL;
1599 * Add the pre-scan job
1601 job->sequence_id++; // for job grouping
1602 hb_add( fHandle, job );
1604 job->x264opts = x264opts_tmp;
1606 job->select_subtitle = NULL;
1609 /* No subtitle were selected, so reset the subtitle to -1 (which before
1610 * this point meant we were scanning
1612 if( job->subtitle == -2 )
1617 if( [fVidTwoPassCheck state] == NSOnState )
1619 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
1620 job->select_subtitle = NULL;
1621 job->subtitle_scan = 0;
1624 job->sequence_id++; // for job grouping
1625 hb_add( fHandle, job );
1628 job->sequence_id++; // for job grouping
1630 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1631 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
1633 job->select_subtitle = subtitle_tmp;
1635 hb_add( fHandle, job );
1639 job->subtitle_scan = 0;
1641 job->sequence_id++; // for job grouping
1642 hb_add( fHandle, job );
1645 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1646 /* Lets try to update stuff, taken from remove in the queue controller */
1647 [fQueueController performSelectorOnMainThread: @selector( updateQueueUI )
1648 withObject: NULL waitUntilDone: NO];
1652 - (IBAction) Rip: (id) sender
1654 /* Rip or Cancel ? */
1656 hb_get_state2( fHandle, &s );
1658 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
1660 [self Cancel: sender];
1663 /* if there is no job in the queue, then add it to the queue and rip
1664 otherwise, there are already jobs in queue, so just rip the queue */
1665 int count = hb_count( fHandle );
1668 [self addToQueue: sender];
1671 /* We check for duplicate name here */
1672 if( [[NSFileManager defaultManager] fileExistsAtPath:
1673 [fDstFile2Field stringValue]] )
1675 NSBeginCriticalAlertSheet( _( @"File already exists" ),
1676 _( @"Cancel" ), _( @"Overwrite" ), NULL, fWindow, self,
1677 @selector( overWriteAlertDone:returnCode:contextInfo: ),
1678 NULL, NULL, [NSString stringWithFormat:
1679 _( @"Do you want to overwrite %@?" ),
1680 [fDstFile2Field stringValue]] );
1683 /* We get the destination directory from the destination field here */
1684 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1685 /* We check for a valid destination here */
1686 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
1688 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1692 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1700 - (void) overWriteAlertDone: (NSWindow *) sheet
1701 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1703 if( returnCode == NSAlertAlternateReturn )
1709 - (void) updateAlertDone: (NSWindow *) sheet
1710 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1712 if( returnCode == NSAlertAlternateReturn )
1714 /* Show scan panel */
1715 [self performSelectorOnMainThread: @selector(showScanPanel:)
1716 withObject: NULL waitUntilDone: NO];
1720 /* Go to HandBrake homepage and exit */
1721 [self openHomepage: NULL];
1722 [NSApp terminate: self];
1727 /* Let libhb do the job */
1728 hb_start( fHandle );
1729 /*set the fEncodeState State */
1733 - (IBAction) Cancel: (id) sender
1735 NSBeginCriticalAlertSheet( _( @"Cancel - Are you sure?" ),
1736 _( @"Keep working" ), _( @"Cancel encoding" ), NULL, fWindow, self,
1737 @selector( _Cancel:returnCode:contextInfo: ), NULL, NULL,
1738 _( @"Encoding won't be recoverable." ) );
1741 - (void) _Cancel: (NSWindow *) sheet
1742 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1744 if( returnCode == NSAlertAlternateReturn )
1747 /*set the fEncodeState State */
1752 - (IBAction) Pause: (id) sender
1755 hb_get_state2( fHandle, &s );
1757 if( s.state == HB_STATE_PAUSED )
1759 hb_resume( fHandle );
1763 hb_pause( fHandle );
1767 - (IBAction) titlePopUpChanged: (id) sender
1769 hb_list_t * list = hb_get_titles( fHandle );
1770 hb_title_t * title = (hb_title_t*)
1771 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1774 /* If Auto Naming is on. We create an output filename of dvd name - title number */
1775 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0)
1777 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1778 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
1779 [NSString stringWithUTF8String: title->name],
1781 [[fDstFile2Field stringValue] pathExtension]]];
1784 /* Update chapter popups */
1785 [fSrcChapterStartPopUp removeAllItems];
1786 [fSrcChapterEndPopUp removeAllItems];
1787 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
1789 [fSrcChapterStartPopUp addItemWithTitle: [NSString
1790 stringWithFormat: @"%d", i + 1]];
1791 [fSrcChapterEndPopUp addItemWithTitle: [NSString
1792 stringWithFormat: @"%d", i + 1]];
1794 [fSrcChapterStartPopUp selectItemAtIndex: 0];
1795 [fSrcChapterEndPopUp selectItemAtIndex:
1796 hb_list_count( title->list_chapter ) - 1];
1797 [self chapterPopUpChanged: NULL];
1799 /* Start Get and set the initial pic size for display */
1800 hb_job_t * job = title->job;
1802 /* Turn Deinterlace on/off depending on the preference */
1803 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1805 [fPictureController setDeinterlace:1];
1809 [fPictureController setDeinterlace:0];
1812 /* Pixel Ratio Setting */
1813 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PixelRatio"])
1815 job->pixel_ratio = 1 ;
1819 job->pixel_ratio = 0 ;
1821 /*Set Source Size Fields Here */
1822 [fPicSrcWidth setStringValue: [NSString stringWithFormat:
1823 @"%d", fTitle->width]];
1824 [fPicSrcHeight setStringValue: [NSString stringWithFormat:
1825 @"%d", fTitle->height]];
1827 /* Set Auto Crop to on upon selecting a new title */
1828 [fPictureController setAutoCrop:YES];
1830 /* We get the originial output picture width and height and put them
1831 in variables for use with some presets later on */
1832 PicOrigOutputWidth = job->width;
1833 PicOrigOutputHeight = job->height;
1834 AutoCropTop = job->crop[0];
1835 AutoCropBottom = job->crop[1];
1836 AutoCropLeft = job->crop[2];
1837 AutoCropRight = job->crop[3];
1838 /* we test getting the max output value for pic sizing here to be used later*/
1839 [fPicSettingWidth setStringValue: [NSString stringWithFormat:
1840 @"%d", PicOrigOutputWidth]];
1841 [fPicSettingHeight setStringValue: [NSString stringWithFormat:
1842 @"%d", PicOrigOutputHeight]];
1843 /* we run the picture size values through
1844 calculatePictureSizing to get all picture size
1846 [self calculatePictureSizing: NULL];
1847 /* Run Through encoderPopUpChanged to see if there
1848 needs to be any pic value modifications based on encoder settings */
1849 //[self encoderPopUpChanged: NULL];
1850 /* END Get and set the initial pic size for display */
1852 /* Update subtitle popups */
1853 hb_subtitle_t * subtitle;
1854 [fSubPopUp removeAllItems];
1855 [fSubPopUp addItemWithTitle: @"None"];
1856 [fSubPopUp addItemWithTitle: @"Autoselect"];
1857 for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
1859 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
1861 /* We cannot use NSPopUpButton's addItemWithTitle because
1862 it checks for duplicate entries */
1863 [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
1864 subtitle->lang] action: NULL keyEquivalent: @""];
1866 [fSubPopUp selectItemAtIndex: 0];
1868 [self subtitleSelectionChanged: NULL];
1870 /* Update chapter table */
1871 [fChapterTitlesDelegate resetWithTitle:title];
1872 [fChapterTable reloadData];
1874 /* Update audio popups */
1875 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
1876 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
1877 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
1878 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
1879 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
1880 [self selectAudioTrackInPopUp: fAudLang2PopUp searchPrefixString: NULL selectIndexIfNotFound: 0];
1882 /* changing the title may have changed the audio channels on offer, */
1883 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1884 [self audioTrackPopUpChanged: fAudLang1PopUp];
1885 [self audioTrackPopUpChanged: fAudLang2PopUp];
1886 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
1887 [self tableViewSelected:NULL];
1890 - (IBAction) chapterPopUpChanged: (id) sender
1893 /* If start chapter popup is greater than end chapter popup,
1894 we set the end chapter popup to the same as start chapter popup */
1895 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
1897 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
1901 hb_list_t * list = hb_get_titles( fHandle );
1902 hb_title_t * title = (hb_title_t *)
1903 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1905 hb_chapter_t * chapter;
1906 int64_t duration = 0;
1907 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
1908 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
1910 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
1911 duration += chapter->duration;
1914 duration /= 90000; /* pts -> seconds */
1915 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
1916 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
1919 [self calculateBitrate: sender];
1922 - (IBAction) formatPopUpChanged: (id) sender
1924 NSString * string = [fDstFile2Field stringValue];
1925 int format = [fDstFormatPopUp indexOfSelectedItem];
1927 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
1928 [fDstMpgLargeFileCheck setHidden: YES];
1929 /* Update the codecs popup */
1930 [fDstCodecsPopUp removeAllItems];
1934 /*Get Default MP4 File Extension*/
1935 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1943 [fDstCodecsPopUp addItemWithTitle:
1944 _( @"MPEG-4 Video / AAC Audio" )];
1945 [fDstCodecsPopUp addItemWithTitle:
1946 _( @"AVC/H.264 Video / AAC Audio" )];
1947 /* We enable the create chapters checkbox here since we are .mp4*/
1948 [fCreateChapterMarkers setEnabled: YES];
1949 /* We show the Large File (64 bit formatting) checkbox since we are .mp4
1950 if we have enabled the option in the global preferences*/
1951 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0)
1953 [fDstMpgLargeFileCheck setHidden: NO];
1957 /* if not enable in global preferences, we additionaly sanity check that the
1958 hidden checkbox is set to off. */
1959 [fDstMpgLargeFileCheck setState: NSOffState];
1964 [fDstCodecsPopUp addItemWithTitle:
1965 _( @"MPEG-4 Video / MP3 Audio" )];
1966 [fDstCodecsPopUp addItemWithTitle:
1967 _( @"MPEG-4 Video / AC-3 Audio" )];
1968 [fDstCodecsPopUp addItemWithTitle:
1969 _( @"AVC/H.264 Video / MP3 Audio" )];
1970 [fDstCodecsPopUp addItemWithTitle:
1971 _( @"AVC/H.264 Video / AC-3 Audio" )];
1972 /* We disable the create chapters checkbox here since we are NOT .mp4
1973 and make sure it is unchecked*/
1974 [fCreateChapterMarkers setEnabled: NO];
1975 [fCreateChapterMarkers setState: NSOffState];
1979 [fDstCodecsPopUp addItemWithTitle:
1980 _( @"MPEG-4 Video / Vorbis Audio" )];
1981 [fDstCodecsPopUp addItemWithTitle:
1982 _( @"MPEG-4 Video / MP3 Audio" )];
1983 /* We disable the create chapters checkbox here since we are NOT .mp4
1984 and make sure it is unchecked*/
1985 [fCreateChapterMarkers setEnabled: NO];
1986 [fCreateChapterMarkers setState: NSOffState];
1990 [fDstCodecsPopUp addItemWithTitle:
1991 _( @"MPEG-4 Video / AAC Audio" )];
1992 [fDstCodecsPopUp addItemWithTitle:
1993 _( @"MPEG-4 Video / AC-3 Audio" )];
1994 [fDstCodecsPopUp addItemWithTitle:
1995 _( @"MPEG-4 Video / MP3 Audio" )];
1996 [fDstCodecsPopUp addItemWithTitle:
1997 _( @"MPEG-4 Video / Vorbis Audio" )];
1999 [fDstCodecsPopUp addItemWithTitle:
2000 _( @"AVC/H.264 Video / AAC Audio" )];
2001 [fDstCodecsPopUp addItemWithTitle:
2002 _( @"AVC/H.264 Video / AC-3 Audio" )];
2003 [fDstCodecsPopUp addItemWithTitle:
2004 _( @"AVC/H.264 Video / MP3 Audio" )];
2005 [fDstCodecsPopUp addItemWithTitle:
2006 _( @"AVC/H.264 Video / Vorbis Audio" )];
2007 /* We enable the create chapters checkbox here since */
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] )];
2670 /* Method to determine if we should change the UI
2671 To reflect whether or not a Preset is being used or if
2672 the user is using "Custom" settings by determining the sender*/
2673 - (IBAction) customSettingUsed: (id) sender
2675 if ([sender stringValue] != NULL)
2677 /* Deselect the currently selected Preset if there is one*/
2678 [tableView deselectRow:[tableView selectedRow]];
2679 [[fPresetsActionMenu itemAtIndex:0] setEnabled: NO];
2680 /* Change UI to show "Custom" settings are being used */
2681 [fPresetSelectedDisplay setStringValue: @"Custom"];
2683 curUserPresetChosenNum = nil;
2688 /* We use this method to recreate new, updated factory
2690 - (IBAction)addFactoryPresets:(id)sender
2692 /* First, we delete any existing built in presets */
2693 [self deleteFactoryPresets: sender];
2694 /* Then, we re-create new built in presets programmatically CreateIpodOnlyPreset*/
2695 [UserPresets addObject:[self createNormalPreset]];
2696 [UserPresets addObject:[self createClassicPreset]];
2697 [UserPresets addObject:[self createQuickTimePreset]];
2698 [UserPresets addObject:[self createIpodLowPreset]];
2699 [UserPresets addObject:[self createIpodHighPreset]];
2700 [UserPresets addObject:[self createAppleTVPreset]];
2701 [UserPresets addObject:[self createiPhonePreset]];
2702 [UserPresets addObject:[self createPSThreePreset]];
2703 [UserPresets addObject:[self createPSPPreset]];
2704 [UserPresets addObject:[self createFilmPreset]];
2705 [UserPresets addObject:[self createTelevisionPreset]];
2706 [UserPresets addObject:[self createAnimationPreset]];
2707 [UserPresets addObject:[self createBedlamPreset]];
2708 [UserPresets addObject:[self createDeuxSixQuatrePreset]];
2709 [UserPresets addObject:[self createBrokePreset]];
2710 [UserPresets addObject:[self createBlindPreset]];
2711 [UserPresets addObject:[self createCRFPreset]];
2715 - (IBAction)deleteFactoryPresets:(id)sender
2718 NSEnumerator *enumerator = [UserPresets objectEnumerator];
2722 NSMutableArray *tempArray;
2725 tempArray = [NSMutableArray array];
2726 /* we look here to see if the preset is we move on to the next one */
2727 while ( tempObject = [enumerator nextObject] )
2729 /* if the preset is "Factory" then we put it in the array of
2730 presets to delete */
2731 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
2733 [tempArray addObject:tempObject];
2737 [UserPresets removeObjectsInArray:tempArray];
2738 [tableView reloadData];
2743 - (IBAction) showAddPresetPanel: (id) sender
2745 /* Deselect the currently selected Preset if there is one*/
2746 [tableView deselectRow:[tableView selectedRow]];
2748 /* Populate the preset picture settings popup here */
2749 [fPresetNewPicSettingsPopUp removeAllItems];
2750 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
2751 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
2752 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
2753 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
2755 /* Erase info from the input fields fPresetNewDesc*/
2756 [fPresetNewName setStringValue: @""];
2757 [fPresetNewDesc setStringValue: @""];
2758 /* Show the panel */
2759 [NSApp beginSheet: fAddPresetPanel modalForWindow: fWindow modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
2762 - (IBAction) closeAddPresetPanel: (id) sender
2764 [NSApp endSheet: fAddPresetPanel];
2765 [fAddPresetPanel orderOut: self];
2768 - (IBAction)addUserPreset:(id)sender
2770 if (![[fPresetNewName stringValue] length])
2771 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
2774 /* Here we create a custom user preset */
2775 [UserPresets addObject:[self createPreset]];
2778 [self closeAddPresetPanel:NULL];
2785 /* We Sort the Presets By Factory or Custom */
2786 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
2787 ascending:YES] autorelease];
2788 /* We Sort the Presets Alphabetically by name */
2789 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
2790 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
2791 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
2792 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
2793 [UserPresets setArray:sortedArray];
2796 /* We Reload the New Table data for presets */
2797 [tableView reloadData];
2798 /* We save all of the preset data here */
2802 - (IBAction)insertPreset:(id)sender
2804 int index = [tableView selectedRow];
2805 [UserPresets insertObject:[self createPreset] atIndex:index];
2806 [tableView reloadData];
2810 - (NSDictionary *)createPreset
2812 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2813 /* Get the New Preset Name from the field in the AddPresetPanel */
2814 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
2815 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2816 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
2817 /*Set whether or not this is default, at creation set to 0*/
2818 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2819 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2820 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
2821 /* Get New Preset Description from the field in the AddPresetPanel*/
2822 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
2824 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
2825 /* Chapter Markers fCreateChapterMarkers*/
2826 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
2827 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2828 [preset setObject:[NSNumber numberWithInt:[fDstMpgLargeFileCheck state]] forKey:@"Mp4LargeFile"];
2830 [preset setObject:[fDstCodecsPopUp titleOfSelectedItem] forKey:@"FileCodecs"];
2832 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
2833 /* x264 Option String */
2834 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
2836 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
2837 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2838 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
2839 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2841 /* Video framerate */
2842 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
2844 [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
2845 /* 2 Pass Encoding */
2846 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
2847 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
2848 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
2849 /*Picture Settings*/
2850 hb_job_t * job = fTitle->job;
2851 /* Basic Picture Settings */
2852 /* Use Max Picture settings for whatever the dvd is.*/
2853 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2854 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2855 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2856 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2857 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
2858 [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
2859 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
2860 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
2861 /* Set crop settings here */
2862 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
2863 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2865 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2866 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2867 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2868 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2871 /* Audio Sample Rate*/
2872 [preset setObject:[fAudRatePopUp titleOfSelectedItem] forKey:@"AudioSampleRate"];
2873 /* Audio Bitrate Rate*/
2874 [preset setObject:[fAudBitratePopUp titleOfSelectedItem] forKey:@"AudioBitRate"];
2876 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
2879 [preset autorelease];
2884 - (NSDictionary *)createIpodLowPreset
2886 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2887 /* Get the New Preset Name from the field in the AddPresetPanel */
2888 [preset setObject:@"iPod Low-Rez" forKey:@"PresetName"];
2889 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2890 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
2891 /*Set whether or not this is default, at creation set to 0*/
2892 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2893 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2894 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
2895 /* Get the New Preset Description from the field in the AddPresetPanel */
2896 [preset setObject:@"HandBrake's low resolution settings for the iPod. Optimized for great playback on the iPod screen, with smaller file size." forKey:@"PresetDescription"];
2898 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
2899 /* Chapter Markers*/
2900 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
2902 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
2904 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
2905 /* x264 Option String */
2906 [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"];
2908 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
2909 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2910 [preset setObject:@"700" forKey:@"VideoAvgBitrate"];
2911 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2913 /* Video framerate */
2914 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
2916 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
2917 /* 2 Pass Encoding */
2918 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
2920 /*Picture Settings*/
2921 //hb_job_t * job = fTitle->job;
2922 /* Basic Picture Settings */
2923 /* Use Max Picture settings for whatever the dvd is.*/
2924 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2925 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
2926 [preset setObject:[NSNumber numberWithInt:320] forKey:@"PictureWidth"];
2927 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
2928 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
2929 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
2930 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
2931 /* Set crop settings here */
2932 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
2933 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
2934 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
2935 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
2936 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
2939 /* Audio Sample Rate*/
2940 [preset setObject:@"48" forKey:@"AudioSampleRate"];
2941 /* Audio Bitrate Rate*/
2942 [preset setObject:@"160" forKey:@"AudioBitRate"];
2944 [preset setObject:@"None" forKey:@"Subtitles"];
2947 [preset autorelease];
2953 - (NSDictionary *)createIpodHighPreset
2955 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2956 /* Get the New Preset Name from the field in the AddPresetPanel */
2957 [preset setObject:@"iPod High-Rez" forKey:@"PresetName"];
2958 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2959 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
2960 /*Set whether or not this is default, at creation set to 0*/
2961 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2962 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2963 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
2964 /* Get the New Preset Description from the field in the AddPresetPanel */
2965 [preset setObject:@"HandBrake's high resolution settings for the iPod. Good video quality, great for viewing on a TV using your iPod" forKey:@"PresetDescription"];
2967 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
2968 /* Chapter Markers*/
2969 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
2971 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
2973 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
2974 /* x264 Option String */
2975 [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"];
2977 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
2978 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2979 [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
2980 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2982 /* Video framerate */
2983 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
2985 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
2986 /* 2 Pass Encoding */
2987 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
2989 /*Picture Settings*/
2990 //hb_job_t * job = fTitle->job;
2991 /* Basic Picture Settings */
2992 /* Use Max Picture settings for whatever the dvd is.*/
2993 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2994 [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
2995 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
2996 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
2997 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
2998 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
2999 /* Set crop settings here */
3000 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3001 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3002 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3003 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3004 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3005 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3008 /* Audio Sample Rate*/
3009 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3010 /* Audio Bitrate Rate*/
3011 [preset setObject:@"160" forKey:@"AudioBitRate"];
3013 [preset setObject:@"None" forKey:@"Subtitles"];
3016 [preset autorelease];
3021 - (NSDictionary *)createAppleTVPreset
3023 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3024 /* Get the New Preset Name from the field in the AddPresetPanel */
3025 [preset setObject:@"AppleTV" forKey:@"PresetName"];
3026 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3027 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3028 /*Set whether or not this is default, at creation set to 0*/
3029 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3030 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3031 [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3032 /* Get the New Preset Description from the field in the AddPresetPanel */
3033 [preset setObject:@"HandBrake's settings for the AppleTV. Provides a good balance between quality and file size, and optimizes performance." forKey:@"PresetDescription"];
3035 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3036 /* Chapter Markers*/
3037 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3039 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3041 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3042 /* x264 Option String (We can use this to tweak the appleTV output)*/
3043 [preset setObject:@"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2:cabac=0" forKey:@"x264Option"];
3045 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3046 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3047 [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3048 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3050 /* Video framerate */
3051 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3053 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3054 /* 2 Pass Encoding */
3055 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3057 /*Picture Settings*/
3058 /* For AppleTV we only want to retain UsesMaxPictureSettings
3059 which depend on the source dvd picture settings, so we don't
3060 record the current dvd's picture info since it will vary from
3062 //hb_job_t * job = fTitle->job;
3063 //hb_job_t * job = title->job;
3064 /* Basic Picture Settings */
3065 /* Use Max Picture settings for whatever the dvd is.*/
3066 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3067 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3068 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3069 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3070 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3071 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3072 /* Set crop settings here */
3073 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3074 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3075 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3076 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3077 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3080 /* Audio Sample Rate*/
3081 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3082 /* Audio Bitrate Rate*/
3083 [preset setObject:@"160" forKey:@"AudioBitRate"];
3085 [preset setObject:@"None" forKey:@"Subtitles"];
3088 [preset autorelease];
3093 - (NSDictionary *)createPSThreePreset
3095 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3096 /* Get the New Preset Name from the field in the AddPresetPanel */
3097 [preset setObject:@"PS3" forKey:@"PresetName"];
3098 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3099 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3100 /*Set whether or not this is default, at creation set to 0*/
3101 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3102 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3103 [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3104 /* Get the New Preset Description from the field in the AddPresetPanel */
3105 [preset setObject:@"HandBrake's settings for the Sony PlayStation 3." forKey:@"PresetDescription"];
3107 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3108 /* Chapter Markers*/
3109 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3111 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3113 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3114 /* x264 Option String (We can use this to tweak the appleTV output)*/
3115 [preset setObject:@"level=41:subme=5:me=umh" forKey:@"x264Option"];
3117 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3118 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3119 [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3120 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3122 /* Video framerate */
3123 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3125 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3126 /* 2 Pass Encoding */
3127 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3129 /*Picture Settings*/
3130 /* For PS3 we only want to retain UsesMaxPictureSettings
3131 which depend on the source dvd picture settings, so we don't
3132 record the current dvd's picture info since it will vary from
3134 /* Use Max Picture settings for whatever the dvd is.*/
3135 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3136 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3137 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3138 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3139 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3140 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3141 /* Set crop settings here */
3142 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3143 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3144 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3145 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3146 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3149 /* Audio Sample Rate*/
3150 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3151 /* Audio Bitrate Rate*/
3152 [preset setObject:@"160" forKey:@"AudioBitRate"];
3154 [preset setObject:@"None" forKey:@"Subtitles"];
3157 [preset autorelease];
3161 - (NSDictionary *)createPSPPreset
3163 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3164 /* Get the New Preset Name from the field in the AddPresetPanel */
3165 [preset setObject:@"PSP" forKey:@"PresetName"];
3166 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3167 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3168 /*Set whether or not this is default, at creation set to 0*/
3169 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3170 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3171 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3172 /* Get the New Preset Description from the field in the AddPresetPanel */
3173 [preset setObject:@"HandBrake's settings for the Sony PlayStation Portable." forKey:@"PresetDescription"];
3175 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3176 /* Chapter Markers*/
3177 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3179 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3181 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3182 /* x264 Option String (We can use this to tweak the appleTV output)*/
3183 [preset setObject:@"" forKey:@"x264Option"];
3185 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3186 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3187 [preset setObject:@"1024" forKey:@"VideoAvgBitrate"];
3188 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3190 /* Video framerate */
3191 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3193 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3194 /* 2 Pass Encoding */
3195 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3197 /*Picture Settings*/
3198 /* For PS3 we only want to retain UsesMaxPictureSettings
3199 which depend on the source dvd picture settings, so we don't
3200 record the current dvd's picture info since it will vary from
3202 /* Use Max Picture settings for whatever the dvd is.*/
3203 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3204 [preset setObject:@"368" forKey:@"PictureWidth"];
3205 [preset setObject:@"208" forKey:@"PictureHeight"];
3206 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3207 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3208 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3209 /* Set crop settings here */
3210 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3211 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3212 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3213 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3214 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3215 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3218 /* Audio Sample Rate*/
3219 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3220 /* Audio Bitrate Rate*/
3221 [preset setObject:@"128" forKey:@"AudioBitRate"];
3223 [preset setObject:@"None" forKey:@"Subtitles"];
3226 [preset autorelease];
3231 - (NSDictionary *)createNormalPreset
3233 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3234 /* Get the New Preset Name from the field in the AddPresetPanel */
3235 [preset setObject:@"Normal" forKey:@"PresetName"];
3236 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3237 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3238 /*Set whether or not this is default, at creation set to 0*/
3239 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Default"];
3240 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3241 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3242 /* Get the New Preset Description from the field in the AddPresetPanel */
3243 [preset setObject:@"HandBrake's normal, default settings." forKey:@"PresetDescription"];
3245 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3246 /* Chapter Markers*/
3247 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3249 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3251 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3252 /* x264 Option String */
3253 [preset setObject:@"ref=2:bframes=2:subme=5:me=umh" forKey:@"x264Option"];
3255 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3256 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3257 [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
3258 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3260 /* Video framerate */
3261 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3263 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3264 /* 2 Pass Encoding */
3265 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3266 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3268 /*Picture Settings*/
3269 //hb_job_t * job = fTitle->job;
3270 /* Basic Picture Settings */
3271 /* Use Max Picture settings for whatever the dvd is.*/
3272 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3273 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3274 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3275 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3276 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3277 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3278 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3279 /* Set crop settings here */
3280 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3281 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3282 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3283 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3284 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3287 /* Audio Sample Rate*/
3288 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3289 /* Audio Bitrate Rate*/
3290 [preset setObject:@"160" forKey:@"AudioBitRate"];
3292 [preset setObject:@"None" forKey:@"Subtitles"];
3295 [preset autorelease];
3300 - (NSDictionary *)createClassicPreset
3302 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3303 /* Get the New Preset Name from the field in the AddPresetPanel */
3304 [preset setObject:@"Classic" forKey:@"PresetName"];
3305 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3306 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3307 /*Set whether or not this is default, at creation set to 0*/
3308 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3309 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3310 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3311 /* Get the New Preset Description from the field in the AddPresetPanel */
3312 [preset setObject:@"HandBrake's traditional, faster, lower-quality settings." forKey:@"PresetDescription"];
3314 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3315 /* Chapter Markers*/
3316 [preset setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
3318 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3320 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3321 /* x264 Option String */
3322 [preset setObject:@"" forKey:@"x264Option"];
3324 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3325 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3326 [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
3327 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3329 /* Video framerate */
3330 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3332 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3333 /* 2 Pass Encoding */
3334 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3336 /*Picture Settings*/
3337 //hb_job_t * job = fTitle->job;
3338 /* Basic Picture Settings */
3339 /* Use Max Picture settings for whatever the dvd is.*/
3340 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3341 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3342 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3343 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3344 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3345 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3346 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3347 /* Set crop settings here */
3348 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3349 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3350 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3351 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3352 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3355 /* Audio Sample Rate*/
3356 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3357 /* Audio Bitrate Rate*/
3358 [preset setObject:@"160" forKey:@"AudioBitRate"];
3360 [preset setObject:@"None" forKey:@"Subtitles"];
3363 [preset autorelease];
3368 - (NSDictionary *)createFilmPreset
3370 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3371 /* Get the New Preset Name from the field in the AddPresetPanel */
3372 [preset setObject:@"Film" forKey:@"PresetName"];
3373 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3374 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3375 /*Set whether or not this is default, at creation set to 0*/
3376 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3377 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3378 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3379 /* Get the New Preset Description from the field in the AddPresetPanel */
3380 [preset setObject:@"HandBrake's preset for feature films." forKey:@"PresetDescription"];
3382 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3383 /* Chapter Markers*/
3384 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3386 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3388 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3389 /* x264 Option String */
3390 [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"];
3392 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3393 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3394 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
3395 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3397 /* Video framerate */
3398 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3400 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3401 /* 2 Pass Encoding */
3402 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3403 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3405 /*Picture Settings*/
3406 //hb_job_t * job = fTitle->job;
3407 /* Basic Picture Settings */
3408 /* Use Max Picture settings for whatever the dvd is.*/
3409 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3410 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3411 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3412 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3413 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3414 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3415 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3416 /* Set crop settings here */
3417 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3418 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3419 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3420 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3421 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3424 /* Audio Sample Rate*/
3425 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3426 /* Audio Bitrate Rate*/
3427 [preset setObject:@"160" forKey:@"AudioBitRate"];
3429 [preset setObject:@"None" forKey:@"Subtitles"];
3432 [preset autorelease];
3437 - (NSDictionary *)createTelevisionPreset
3439 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3440 /* Get the New Preset Name from the field in the AddPresetPanel */
3441 [preset setObject:@"Television" forKey:@"PresetName"];
3442 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3443 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3444 /*Set whether or not this is default, at creation set to 0*/
3445 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3446 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3447 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3448 /* Get the New Preset Description from the field in the AddPresetPanel */
3449 [preset setObject:@"HandBrake's settings for video from television." forKey:@"PresetDescription"];
3451 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3452 /* Chapter Markers*/
3453 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3455 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3457 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3458 /* x264 Option String */
3459 [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"];
3461 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3462 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3463 [preset setObject:@"1300" forKey:@"VideoAvgBitrate"];
3464 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3466 /* Video framerate */
3467 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3469 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3470 /* 2 Pass Encoding */
3471 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3472 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3474 /*Picture Settings*/
3475 //hb_job_t * job = fTitle->job;
3476 /* Basic Picture Settings */
3477 /* Use Max Picture settings for whatever the dvd is.*/
3478 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3479 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3480 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3481 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3482 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3483 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
3484 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3485 /* Set crop settings here */
3486 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3487 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3488 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3489 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3490 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3493 /* Audio Sample Rate*/
3494 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3495 /* Audio Bitrate Rate*/
3496 [preset setObject:@"160" forKey:@"AudioBitRate"];
3498 [preset setObject:@"None" forKey:@"Subtitles"];
3501 [preset autorelease];
3506 - (NSDictionary *)createAnimationPreset
3508 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3509 /* Get the New Preset Name from the field in the AddPresetPanel */
3510 [preset setObject:@"Animation" forKey:@"PresetName"];
3511 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3512 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3513 /*Set whether or not this is default, at creation set to 0*/
3514 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3515 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3516 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3517 /* Get the New Preset Description from the field in the AddPresetPanel */
3518 [preset setObject:@"HandBrake's settings for cartoons, anime, and CGI." forKey:@"PresetDescription"];
3520 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3521 /* Chapter Markers*/
3522 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3524 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3526 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3527 /* x264 Option String */
3528 [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"];
3530 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3531 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3532 [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
3533 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3535 /* Video framerate */
3536 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3538 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3539 /* 2 Pass Encoding */
3540 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3541 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3543 /*Picture Settings*/
3544 //hb_job_t * job = fTitle->job;
3545 /* Basic Picture Settings */
3546 /* Use Max Picture settings for whatever the dvd is.*/
3547 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3548 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3549 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3550 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3551 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3552 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
3553 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3554 /* Set crop settings here */
3555 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3556 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3557 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3558 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3559 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3562 /* Audio Sample Rate*/
3563 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3564 /* Audio Bitrate Rate*/
3565 [preset setObject:@"160" forKey:@"AudioBitRate"];
3567 [preset setObject:@"None" forKey:@"Subtitles"];
3570 [preset autorelease];
3575 - (NSDictionary *)createQuickTimePreset
3577 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3578 /* Get the New Preset Name from the field in the AddPresetPanel */
3579 [preset setObject:@"QuickTime" forKey:@"PresetName"];
3580 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3581 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3582 /*Set whether or not this is default, at creation set to 0*/
3583 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3584 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3585 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3586 /* Get the New Preset Description from the field in the AddPresetPanel */
3587 [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"];
3589 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3590 /* Chapter Markers*/
3591 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3593 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3595 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3596 /* x264 Option String */
3597 [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"];
3599 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3600 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3601 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
3602 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3604 /* Video framerate */
3605 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3607 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3608 /* 2 Pass Encoding */
3609 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3610 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3612 /*Picture Settings*/
3613 //hb_job_t * job = fTitle->job;
3614 /* Basic Picture Settings */
3615 /* Use Max Picture settings for whatever the dvd is.*/
3616 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3617 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3618 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3619 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3620 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3621 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3622 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3623 /* Set crop settings here */
3624 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3625 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3626 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3627 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3628 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3631 /* Audio Sample Rate*/
3632 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3633 /* Audio Bitrate Rate*/
3634 [preset setObject:@"160" forKey:@"AudioBitRate"];
3636 [preset setObject:@"None" forKey:@"Subtitles"];
3639 [preset autorelease];
3644 - (NSDictionary *)createBedlamPreset
3646 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3647 /* Get the New Preset Name from the field in the AddPresetPanel */
3648 [preset setObject:@"Bedlam" forKey:@"PresetName"];
3649 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3650 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3651 /*Set whether or not this is default, at creation set to 0*/
3652 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3653 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3654 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3655 /* Get the New Preset Description from the field in the AddPresetPanel */
3656 [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"];
3658 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3659 /* Chapter Markers*/
3660 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3662 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3664 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3665 /* x264 Option String */
3666 [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"];
3668 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3669 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3670 [preset setObject:@"1800" forKey:@"VideoAvgBitrate"];
3671 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3673 /* Video framerate */
3674 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3676 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3677 /* 2 Pass Encoding */
3678 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3679 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3681 /*Picture Settings*/
3682 //hb_job_t * job = fTitle->job;
3683 /* Basic Picture Settings */
3684 /* Use Max Picture settings for whatever the dvd is.*/
3685 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3686 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3687 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3688 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3689 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3690 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3691 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3692 /* Set crop settings here */
3693 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3694 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3695 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3696 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3697 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3700 /* Audio Sample Rate*/
3701 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3702 /* Audio Bitrate Rate*/
3703 [preset setObject:@"160" forKey:@"AudioBitRate"];
3705 [preset setObject:@"None" forKey:@"Subtitles"];
3708 [preset autorelease];
3713 - (NSDictionary *)createiPhonePreset
3715 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3716 /* Get the New Preset Name from the field in the AddPresetPanel */
3717 [preset setObject:@"iPhone" forKey:@"PresetName"];
3718 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3719 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3720 /*Set whether or not this is default, at creation set to 0*/
3721 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3722 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3723 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3724 /* Get the New Preset Description from the field in the AddPresetPanel */
3725 [preset setObject:@"HandBrake's settings for the iPhone." forKey:@"PresetDescription"];
3727 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3728 /* Chapter Markers*/
3729 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3731 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3733 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
3734 /* x264 Option String */
3735 [preset setObject:@"cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1" forKey:@"x264Option"];
3737 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3738 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3739 [preset setObject:@"960" forKey:@"VideoAvgBitrate"];
3740 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3742 /* Video framerate */
3743 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3745 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3746 /* 2 Pass Encoding */
3747 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3749 /*Picture Settings*/
3750 //hb_job_t * job = fTitle->job;
3751 /* Basic Picture Settings */
3752 /* Use Max Picture settings for whatever the dvd is.*/
3753 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3754 [preset setObject:[NSNumber numberWithInt:480] forKey:@"PictureWidth"];
3755 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3756 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3757 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3758 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3759 /* Set crop settings here */
3760 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3761 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3762 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3763 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3764 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3765 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3768 /* Audio Sample Rate*/
3769 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3770 /* Audio Bitrate Rate*/
3771 [preset setObject:@"128" forKey:@"AudioBitRate"];
3773 [preset setObject:@"None" forKey:@"Subtitles"];
3776 [preset autorelease];
3781 - (NSDictionary *)createDeuxSixQuatrePreset
3783 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3784 /* Get the New Preset Name from the field in the AddPresetPanel */
3785 [preset setObject:@"Deux Six Quatre" forKey:@"PresetName"];
3786 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3787 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3788 /*Set whether or not this is default, at creation set to 0*/
3789 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3790 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3791 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3792 /* Get the New Preset Description from the field in the AddPresetPanel */
3793 [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"];
3795 [preset setObject:@"MKV file" forKey:@"FileFormat"];
3796 /* Chapter Markers*/
3797 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3799 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3801 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3802 /* x264 Option String */
3803 [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"];
3805 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3806 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3807 [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
3808 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3810 /* Video framerate */
3811 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3813 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3814 /* 2 Pass Encoding */
3815 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3816 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3818 /*Picture Settings*/
3819 //hb_job_t * job = fTitle->job;
3820 /* Basic Picture Settings */
3821 /* Use Max Picture settings for whatever the dvd is.*/
3822 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3823 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3824 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3825 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3826 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3827 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3828 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3829 /* Set crop settings here */
3830 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3831 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3832 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3833 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3834 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3837 /* Audio Sample Rate*/
3838 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3839 /* Audio Bitrate Rate*/
3840 [preset setObject:@"160" forKey:@"AudioBitRate"];
3842 [preset setObject:@"None" forKey:@"Subtitles"];
3845 [preset autorelease];
3850 - (NSDictionary *)createBrokePreset
3852 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3853 /* Get the New Preset Name from the field in the AddPresetPanel */
3854 [preset setObject:@"Broke" forKey:@"PresetName"];
3855 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3856 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3857 /*Set whether or not this is default, at creation set to 0*/
3858 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3859 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3860 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3861 /* Get the New Preset Description from the field in the AddPresetPanel */
3862 [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"];
3864 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3865 /* Chapter Markers*/
3866 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3868 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3870 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3871 /* x264 Option String */
3872 [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"];
3874 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoQualityType"];
3875 [preset setObject:@"695" forKey:@"VideoTargetSize"];
3876 [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
3877 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3879 /* Video framerate */
3880 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3882 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3883 /* 2 Pass Encoding */
3884 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3885 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3887 /*Picture Settings*/
3888 //hb_job_t * job = fTitle->job;
3889 /* Basic Picture Settings */
3890 /* Use Max Picture settings for whatever the dvd is.*/
3891 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3892 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3893 [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
3894 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3895 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3896 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3897 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3898 /* Set crop settings here */
3899 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3900 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3901 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3902 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3903 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3906 /* Audio Sample Rate*/
3907 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3908 /* Audio Bitrate Rate*/
3909 [preset setObject:@"128" forKey:@"AudioBitRate"];
3911 [preset setObject:@"None" forKey:@"Subtitles"];
3914 [preset autorelease];
3919 - (NSDictionary *)createBlindPreset
3921 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3922 /* Get the New Preset Name from the field in the AddPresetPanel */
3923 [preset setObject:@"Blind" forKey:@"PresetName"];
3924 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3925 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3926 /*Set whether or not this is default, at creation set to 0*/
3927 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3928 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3929 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3930 /* Get the New Preset Description from the field in the AddPresetPanel */
3931 [preset setObject:@"HandBrake's preset for impatient people who don't care about picture quality." forKey:@"PresetDescription"];
3933 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3934 /* Chapter Markers*/
3935 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3937 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3939 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3940 /* x264 Option String */
3941 [preset setObject:@"" forKey:@"x264Option"];
3943 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3944 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3945 [preset setObject:@"512" forKey:@"VideoAvgBitrate"];
3946 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3948 /* Video framerate */
3949 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3951 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3952 /* 2 Pass Encoding */
3953 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3954 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
3956 /*Picture Settings*/
3957 //hb_job_t * job = fTitle->job;
3958 /* Basic Picture Settings */
3959 /* Use Max Picture settings for whatever the dvd is.*/
3960 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3961 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3962 [preset setObject:[NSNumber numberWithInt:512] forKey:@"PictureWidth"];
3963 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3964 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3965 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3966 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3967 /* Set crop settings here */
3968 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3969 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3970 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3971 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3972 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3975 /* Audio Sample Rate*/
3976 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3977 /* Audio Bitrate Rate*/
3978 [preset setObject:@"128" forKey:@"AudioBitRate"];
3980 [preset setObject:@"None" forKey:@"Subtitles"];
3983 [preset autorelease];
3988 - (NSDictionary *)createCRFPreset
3990 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3991 /* Get the New Preset Name from the field in the AddPresetPanel */
3992 [preset setObject:@"Constant Quality Rate" forKey:@"PresetName"];
3993 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3994 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3995 /*Set whether or not this is default, at creation set to 0*/
3996 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3997 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3998 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3999 /* Get the New Preset Description from the field in the AddPresetPanel */
4000 [preset setObject:@"HandBrake's preset for consistently excellent quality in one pass, with the downside of entirely unpredictable file sizes and bitrates." forKey:@"PresetDescription"];
4002 [preset setObject:@"MKV file" forKey:@"FileFormat"];
4003 /* Chapter Markers*/
4004 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4006 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4008 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4009 /* x264 Option String */
4010 [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"];
4012 [preset setObject:[NSNumber numberWithInt:2] forKey:@"VideoQualityType"];
4013 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4014 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4015 [preset setObject:[NSNumber numberWithFloat:0.6471] forKey:@"VideoQualitySlider"];
4017 /* Video framerate */
4018 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4020 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4021 /* 2 Pass Encoding */
4022 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4023 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
4025 /*Picture Settings*/
4026 //hb_job_t * job = fTitle->job;
4027 /* Basic Picture Settings */
4028 /* Use Max Picture settings for whatever the dvd is.*/
4029 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4030 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4031 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4032 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4033 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4034 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4035 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4036 /* Set crop settings here */
4037 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4038 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4039 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4040 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4041 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4044 /* Audio Sample Rate*/
4045 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4046 /* Audio Bitrate Rate*/
4047 [preset setObject:@"160" forKey:@"AudioBitRate"];
4049 [preset setObject:@"None" forKey:@"Subtitles"];
4052 [preset autorelease];
4058 - (IBAction)deletePreset:(id)sender
4061 NSEnumerator *enumerator;
4063 NSMutableArray *tempArray;
4066 if ( [tableView numberOfSelectedRows] == 0 )
4068 /* Alert user before deleting preset */
4069 /* Comment out for now, tie to user pref eventually */
4072 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
4074 if ( status == NSAlertDefaultReturn ) {
4075 enumerator = [tableView selectedRowEnumerator];
4076 tempArray = [NSMutableArray array];
4078 while ( (index = [enumerator nextObject]) ) {
4079 tempObject = [UserPresets objectAtIndex:[index intValue]];
4080 [tempArray addObject:tempObject];
4083 [UserPresets removeObjectsInArray:tempArray];
4084 [tableView reloadData];
4089 - (IBAction)getDefaultPresets:(id)sender
4092 NSEnumerator *enumerator = [UserPresets objectEnumerator];
4094 while (tempObject = [enumerator nextObject])
4096 NSDictionary *thisPresetDict = tempObject;
4097 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
4099 presetHbDefault = i;
4101 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
4103 presetUserDefault = i;
4109 - (IBAction)setDefaultPreset:(id)sender
4112 NSEnumerator *enumerator = [UserPresets objectEnumerator];
4114 /* First make sure the old user specified default preset is removed */
4115 while (tempObject = [enumerator nextObject])
4117 /* make sure we are not removing the default HB preset */
4118 if ([[[UserPresets objectAtIndex:i] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4120 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4124 /* Second, go ahead and set the appropriate user specfied preset */
4125 /* we get the chosen preset from the UserPresets array */
4126 if ([[[UserPresets objectAtIndex:[tableView selectedRow]] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4128 [[UserPresets objectAtIndex:[tableView selectedRow]] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
4130 presetUserDefault = [tableView selectedRow];
4132 /* We save all of the preset data here */
4134 /* We Reload the New Table data for presets */
4135 [tableView reloadData];
4138 - (IBAction)selectDefaultPreset:(id)sender
4140 /* if there is a user specified default, we use it */
4141 if (presetUserDefault)
4143 [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetUserDefault] byExtendingSelection:NO];
4144 [self tableViewSelected:NULL];
4146 else if (presetHbDefault) //else we use the built in default presetHbDefault
4148 [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetHbDefault] byExtendingSelection:NO];
4149 [self tableViewSelected:NULL];
4153 - (IBAction)tableViewSelected:(id)sender
4155 /* Since we cannot disable the presets tableView in terms of clickability
4156 we will use the enabled state of the add presets button to determine whether
4157 or not clicking on a preset will do anything */
4158 if ([fPresetsAdd isEnabled])
4160 if ([tableView selectedRow] >= 0)
4162 /* we get the chosen preset from the UserPresets array */
4163 chosenPreset = [UserPresets objectAtIndex:[tableView selectedRow]];
4164 curUserPresetChosenNum = [sender selectedRow];
4165 /* we set the preset display field in main window here */
4166 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
4167 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
4169 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@ (Default)",[chosenPreset valueForKey:@"PresetName"]]];
4173 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
4176 [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
4177 [self formatPopUpChanged: NULL];
4179 /* Chapter Markers*/
4180 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
4181 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
4182 [fDstMpgLargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
4184 [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
4185 [self codecsPopUpChanged: NULL];
4187 [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
4189 /* We can show the preset options here in the gui if we want to
4190 so we check to see it the user has specified it in the prefs */
4191 [fAdvancedOptions setOptions: [NSString stringWithFormat:[chosenPreset valueForKey:@"x264Option"]]];
4193 /* Lets run through the following functions to get variables set there */
4194 [self encoderPopUpChanged: NULL];
4196 [self calculateBitrate: NULL];
4199 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
4201 [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
4202 [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
4204 [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
4205 [self videoMatrixChanged: NULL];
4207 /* Video framerate */
4208 [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
4211 [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
4213 /* 2 Pass Encoding */
4214 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
4215 [self twoPassCheckboxChanged: NULL];
4216 /* Turbo 1st pass for 2 Pass Encoding */
4217 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
4221 /* Audio Sample Rate*/
4222 [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
4223 /* Audio Bitrate Rate*/
4224 [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
4226 [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
4228 /* Picture Settings */
4229 /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
4230 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
4232 hb_job_t * job = fTitle->job;
4233 /* Check to see if we should use the max picture setting for the current title*/
4234 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
4236 /* Use Max Picture settings for whatever the dvd is.*/
4237 [self revertPictureSizeToMax: NULL];
4238 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
4239 if (job->keep_ratio == 1)
4241 hb_fix_aspect( job, HB_KEEP_WIDTH );
4242 if( job->height > fTitle->height )
4244 job->height = fTitle->height;
4245 hb_fix_aspect( job, HB_KEEP_HEIGHT );
4248 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
4250 else // Apply picture settings that were in effect at the time the preset was saved
4252 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
4253 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
4254 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
4255 if (job->keep_ratio == 1)
4257 hb_fix_aspect( job, HB_KEEP_WIDTH );
4258 if( job->height > fTitle->height )
4260 job->height = fTitle->height;
4261 hb_fix_aspect( job, HB_KEEP_HEIGHT );
4264 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
4265 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
4267 if ([chosenPreset objectForKey:@"PictureDetelecine"])
4269 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
4271 if ([chosenPreset objectForKey:@"PictureDenoise"])
4273 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
4275 /* If Cropping is set to custom, then recall all four crop values from
4276 when the preset was created and apply them */
4277 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
4279 [fPictureController setAutoCrop:NO];
4281 /* Here we use the custom crop values saved at the time the preset was saved */
4282 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
4283 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
4284 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
4285 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
4288 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
4290 [fPictureController setAutoCrop:YES];
4291 /* Here we use the auto crop values determined right after scan */
4292 job->crop[0] = AutoCropTop;
4293 job->crop[1] = AutoCropBottom;
4294 job->crop[2] = AutoCropLeft;
4295 job->crop[3] = AutoCropRight;
4299 [self calculatePictureSizing: NULL];
4303 [[fPresetsActionMenu itemAtIndex:0] setEnabled: YES];
4310 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
4312 return [UserPresets count];
4315 /* we use this to determine display characteristics for
4316 each table cell based on content currently only used to
4317 show the built in presets in a blue font. */
4318 - (void)tableView:(NSTableView *)aTableView
4319 willDisplayCell:(id)aCell
4320 forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
4322 NSDictionary *userPresetDict = [UserPresets objectAtIndex:rowIndex];
4325 NSColor *shadowColor;
4326 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
4327 /* First, we check to see if its a selected row, if so, we use white since its highlighted in blue */
4328 if ([[aTableView selectedRowIndexes] containsIndex:rowIndex] && ([tableView editedRow] != rowIndex))
4331 fontColor = [NSColor whiteColor];
4332 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
4336 /* We set the properties of unselected rows */
4337 /* if built-in preset (defined by "type" == 0) we use a blue font */
4338 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
4340 fontColor = [NSColor blueColor];
4342 else // User created preset, use a black font
4344 fontColor = [NSColor blackColor];
4348 /* We check to see if this is the HB default, if so, color it appropriately */
4349 if (!presetUserDefault && presetHbDefault && rowIndex == presetHbDefault)
4351 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4353 /* We check to see if this is the User Specified default, if so, color it appropriately */
4354 if (presetUserDefault && rowIndex == presetUserDefault)
4356 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4359 [aCell setTextColor:fontColor];
4360 [aCell setFont:txtFont];
4361 /* this shadow stuff (like mail app) for some reason looks crappy, commented out
4362 temporarily in case we want to resurrect it */
4364 NSShadow *shadow = [[NSShadow alloc] init];
4365 NSSize shadowOffset = { width: 1.0, height: -1.5};
4366 [shadow setShadowOffset:shadowOffset];
4367 [shadow setShadowColor:shadowColor];
4372 /* Method to display tooltip with the description for each preset, if available */
4373 - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell
4374 rect:(NSRectPointer)aRect tableColumn:(NSTableColumn *)aTableColumn
4375 row:(int)rowIndex mouseLocation:(NSPoint)aPos
4377 /* initialize the tooltip contents variable */
4379 /* if there is a description for the preset, we show it in the tooltip */
4380 if ([[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"])
4382 loc_tip = [NSString stringWithFormat: @"%@",[[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"]];
4387 loc_tip = @"No description available";
4393 - (id)tableView:(NSTableView *)aTableView
4394 objectValueForTableColumn:(NSTableColumn *)aTableColumn
4397 id theRecord, theValue;
4399 theRecord = [UserPresets objectAtIndex:rowIndex];
4400 theValue = [theRecord objectForKey:[aTableColumn identifier]];
4404 // NSTableDataSource method that we implement to edit values directly in the table...
4405 - (void)tableView:(NSTableView *)aTableView
4406 setObjectValue:(id)anObject
4407 forTableColumn:(NSTableColumn *)aTableColumn
4412 theRecord = [UserPresets objectAtIndex:rowIndex];
4413 [theRecord setObject:anObject forKey:@"PresetName"];
4414 /* We Sort the Presets By Factory or Custom */
4415 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
4416 ascending:YES] autorelease];
4417 /* We Sort the Presets Alphabetically by name */
4418 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
4419 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
4420 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
4421 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
4422 [UserPresets setArray:sortedArray];
4423 /* We Reload the New Table data for presets */
4424 [tableView reloadData];
4425 /* We save all of the preset data here */
4431 [UserPresets writeToFile:UserPresetsFile atomically:YES];
4432 /* We get the default preset in case it changed */
4433 [self getDefaultPresets: NULL];
4437 - (void) controlTextDidChange: (NSNotification *) notification
4439 [self calculateBitrate: NULL];
4442 - (IBAction) openHomepage: (id) sender
4444 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4445 URLWithString:@"http://handbrake.m0k.org/"]];
4448 - (IBAction) openForums: (id) sender
4450 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4451 URLWithString:@"http://handbrake.m0k.org/forum/"]];
4453 - (IBAction) openUserGuide: (id) sender
4455 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4456 URLWithString:@"http://handbrake.m0k.org/trac/wiki/HandBrakeGuide"]];
4460 * Shows debug output window.
4462 - (IBAction)showDebugOutputPanel:(id)sender
4464 [outputPanel showOutputPanel:sender];
4468 * Shows preferences window modally.
4470 - (IBAction) showPreferencesWindow: (id) sender
4472 NSWindow * window = [fPreferencesController window];
4473 if (![window isVisible])
4476 [window makeKeyAndOrderFront: nil];
4480 * Shows queue window.
4482 - (IBAction) showQueueWindow:(id)sender
4484 [fQueueController showQueueWindow:sender];
4488 - (IBAction) toggleDrawer:(id)sender {
4489 [fPresetDrawer toggle:self];