1 /* HBAdvancedController
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
7 #import "HBAdvancedController.h"
9 @implementation HBAdvancedController
19 - (void) setView: (NSBox *) box
22 [fOptionsBox setContentView:fX264optView];
25 - (BOOL) loadMyNibFile
27 if(![NSBundle loadNibNamed:@"AdvancedView" owner:self])
29 NSLog(@"Warning! Could not load myNib file.\n");
36 - (NSString *) optionsString
38 return [fDisplayX264Options stringValue];
41 - (void) setOptions: (NSString *)string
43 [fDisplayX264Options setStringValue:string];
44 [self X264AdvancedOptionsSet:nil];
47 - (void) setHidden: (BOOL) hide
51 [fOptionsBox setContentView:fEmptyView];
52 [fX264optViewTitleLabel setStringValue: NSLocalizedStringFromTable(@"Only Used With The x264 (H.264) Codec", @"Advanced", @"")];
56 [fOptionsBox setContentView:fX264optView];
57 [fX264optViewTitleLabel setStringValue: @""];
62 - (void) enableUI: (bool) b
65 NSControl * controls[] =
66 { fX264optViewTitleLabel,fDisplayX264Options,fDisplayX264OptionsLabel,fX264optBframesLabel,
67 fX264optBframesPopUp,fX264optRefLabel,fX264optRefPopUp,fX264optNfpskipLabel,fX264optNfpskipSwitch,
68 fX264optNodctdcmtLabel,fX264optNodctdcmtSwitch,fX264optSubmeLabel,fX264optSubmePopUp,
69 fX264optTrellisLabel,fX264optTrellisPopUp,fX264optMixedRefsLabel,fX264optMixedRefsSwitch,
70 fX264optMotionEstLabel,fX264optMotionEstPopUp,fX264optMERangeLabel,fX264optMERangePopUp,
71 fX264optWeightBLabel,fX264optWeightBSwitch, fX264optBPyramidLabel,fX264optBPyramidSwitch,
72 fX264optDirectPredLabel,fX264optDirectPredPopUp,fX264optDeblockLabel,fX264optAnalyseLabel,
73 fX264optAnalysePopUp,fX264opt8x8dctLabel,fX264opt8x8dctSwitch,fX264optCabacLabel,fX264optCabacSwitch,
74 fX264optAlphaDeblockPopUp,fX264optBetaDeblockPopUp, fX264optPsyRDSlider, fX264optPsyRDLabel, fX264optPsyTrellisSlider, fX264optPsyTrellisLabel, fX264optBAdaptPopUp, fX264optBAdaptLabel };
76 for( i = 0; i < sizeof( controls ) / sizeof( NSControl * ); i++ )
78 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
80 NSTextField * tf = (NSTextField *) controls[i];
83 [tf setTextColor: b ? [NSColor controlTextColor] :
84 [NSColor disabledControlTextColor]];
88 [controls[i] setEnabled: b];
92 [fX264optView setWantsLayer:YES];
101 * Populates the option widgets
103 - (IBAction) X264AdvancedOptionsSet: (id) sender
105 /*Set opt widget values here*/
107 NSString * toolTip = @"";
109 /*B-Frames fX264optBframesPopUp*/
111 [fX264optBframesPopUp removeAllItems];
113 [fX264optBframesPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (0)", @"Advanced", @"")];
115 [fX264optBframesPopUp addItemWithTitle:@"Default (3)"];
118 [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
121 @"Sane values are 1-6. B-Frames are smaller than other frames, so they let you pack in more quality at the same bitrate. Use more of them with animated material.";
122 [fX264optBframesPopUp setToolTip: toolTip];
123 [fX264optBframesLabel setToolTip: toolTip];
125 /*Reference Frames fX264optRefPopUp*/
126 [fX264optRefPopUp removeAllItems];
128 [fX264optRefPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (1)", @"Advanced", @"")];
130 [fX264optRefPopUp addItemWithTitle:@"Default (3)"];
133 [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
136 @"Sane values are 1-6. The more you add, the higher the quality — but the slower the encode. Be careful...too many and QuickTime struggle to play the video back.";
137 [fX264optRefPopUp setToolTip: toolTip];
138 [fX264optRefLabel setToolTip: toolTip];
140 /*No Fast P-Skip fX264optNfpskipSwitch BOOLEAN*/
141 [fX264optNfpskipSwitch setState:0];
143 @"This can help with blocking on solid colors like blue skies, but it also slows down the encode.";
144 [fX264optNfpskipSwitch setToolTip: toolTip];
145 [fX264optNfpskipLabel setToolTip: toolTip];
147 /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
148 [fX264optNodctdcmtSwitch setState:0];
150 @"To save space, x264 will \"zero out\" blocks when it thinks they won't be perceptible by the viewer. This negligibly reduces quality, but in rare cases it can mess up and produce visible artifacts. This situation can be alleviated by telling x264 not to decimate DCT blocks.\n\nIt increases quality but also bitrate/file size, so if you use it when you've specified a target bitrate you will end up with a worse picture than without it. However, when used with constant quality encoding, or if you boost the average bitrate to compensate, you might get a better result.";
151 [fX264optNodctdcmtSwitch setToolTip: toolTip];
152 [fX264optNodctdcmtLabel setToolTip: toolTip];
154 /*Sub Me fX264optSubmePopUp*/
155 [fX264optSubmePopUp removeAllItems];
157 [fX264optSubmePopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (6)", @"Advanced", @"")];
158 [fX264optSubmePopUp addItemWithTitle:@"Default (7)"];
162 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
165 @"This setting is finer-grained than the motion estimation settings above. Instead of dealing with whole pixels, it deals with 4 fractional pixels, or quarter pixels (qpel). Higher levels increase quality by further refining the motion prediction for these quarter pixels, but take longer to encode.\n\nLevel 6, turns on a feature called rate distortion optimization, including psychovisual enhancements. 7, the default, enables that rate distortion for B-frames. 8 refines those decisions for I and P frames, and 9 adds on refinement for B-frames as well.";
166 [fX264optSubmePopUp setToolTip: toolTip];
167 [fX264optSubmeLabel setToolTip: toolTip];
169 /*Trellis fX264optTrellisPopUp*/
170 [fX264optTrellisPopUp removeAllItems];
172 [fX264optTrellisPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (0)", @"Advanced", @"")];
174 [fX264optTrellisPopUp addItemWithTitle:@"Default (1)"];
177 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
179 [fX264optTrellisPopUp setWantsLayer:YES];
181 @"Trellis fine-tunes how bitrate is doled out, so it can reduce file size/bitrate or increase quality. A value of 1 means it only fine-tunes the final encode of a block of pixels, while 2 means it is considered during earlier phases of the decision-making process as well.";
182 [fX264optTrellisPopUp setToolTip: toolTip];
183 [fX264optTrellisLabel setToolTip: toolTip];
185 /*Mixed-references fX264optMixedRefsSwitch BOOLEAN*/
186 [fX264optMixedRefsSwitch setState:1];
187 [fX264optMixedRefsSwitch setWantsLayer:YES];
189 @"With this on, different references can be used for different parts of each 16x16 pixel macroblock, increasing quality.";
190 [fX264optMixedRefsSwitch setToolTip: toolTip];
191 [fX264optMixedRefsLabel setToolTip: toolTip];
193 /*Motion Estimation fX264optMotionEstPopUp*/
194 [fX264optMotionEstPopUp removeAllItems];
196 [fX264optMotionEstPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (Hexagon)", @"Advanced", @"")];
197 [fX264optMotionEstPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Diamond", @"Advanced", @"")];
198 [fX264optMotionEstPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Hexagon", @"Advanced", @"")];
199 [fX264optMotionEstPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Uneven Multi-Hexagon", @"Advanced", @"")];
200 [fX264optMotionEstPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Exhaustive", @"Advanced", @"")];
202 [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
203 [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
204 [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
205 [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
206 [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
207 [fX264optMotionEstPopUp addItemWithTitle:@"Transformed Exhaustive"];
209 @"Controls the motion estimation method. Motion estimation is how the encoder decides how each block of pixels in a frame has moved, compared to most similar blocks in the other frames it references. There are many ways of finding the most similar blocks, with varying speeds and accuracy.\n\nAt the most basic setting, dia, x264 will only consider a diamond-shaped region around each pixel.\n\nThe default setting, hex, is similar to dia but uses a hexagon shape.\n\nUneven multi-hexagon, umh, searches a number of different patterns across a wider area and thus is slower than hex and dia but further increases compression efficiency and quality.\n\nesa, an exhaustive search of a square around each pixel (whose size is controlled by the me-range parameter), is much slower and offers only minimal quality gains.\n\ntesa, transformed exhaustive search, which performs just as thorough a search, is slower still but offers further slight improvements to quality.";
210 [fX264optMotionEstPopUp setToolTip: toolTip];
211 [fX264optMotionEstLabel setToolTip: toolTip];
213 /*Motion Estimation range fX264optMERangePopUp*/
214 [fX264optMERangePopUp removeAllItems];
215 [fX264optMERangePopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (16)", @"Advanced", @"")];
218 [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
221 @"This range is the radius, in pixels, x264 should use for motion estimation searches. It only has an effect when you use Uneven Multi-Hexagonal, Exhaustive, or Transformed Exhaustive searching. 24, 32, and 64 are good values, with each being progressively smaller for progressively less improvement to picture quality.";
222 [fX264optMERangePopUp setToolTip: toolTip];
223 [fX264optMERangeLabel setToolTip: toolTip];
225 /*Weighted B-Frame Prediction fX264optWeightBSwitch BOOLEAN*/
226 [fX264optWeightBSwitch setState:1];
227 [fX264optWeightBSwitch setWantsLayer:YES];
229 @"Sometimes x264 will base a B-frame's motion compensation on frames both before and after. With weighted B-frames, the amount of influence each frame has is related to its distance from the frame being encoded, instead of both having equal influence. The AppleTV can have issues with this.";
230 [fX264optWeightBSwitch setToolTip: toolTip];
231 [fX264optWeightBLabel setToolTip: toolTip];
233 /*B-frame Pyramids fX264optBPyramidSwitch BOOLEAN*/
234 [fX264optBPyramidSwitch setState:0];
235 [fX264optBPyramidSwitch setWantsLayer:YES];
237 @"B-frame pyramids are a High Profile feature. Pyramidal B-frames mean that B-frames don't just reference surrounding reference frames — instead, it also treats a previous B-frame as a reference, improving quality/lowering bitrate at the expense of complexity. Logically, to reference an earlier B-frame, you must tell x264 to use at least 2 B-frames.";
238 [fX264optBPyramidSwitch setToolTip: toolTip];
239 [fX264optBPyramidLabel setToolTip: toolTip];
241 /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
242 [fX264optDirectPredPopUp removeAllItems];
243 [fX264optDirectPredPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (Spatial)", @"Advanced", @"")];
244 [fX264optDirectPredPopUp addItemWithTitle:NSLocalizedStringFromTable(@"None", @"Advanced", @"")];
245 [fX264optDirectPredPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Spatial", @"Advanced", @"")];
246 [fX264optDirectPredPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Temporal", @"Advanced", @"")];
247 [fX264optDirectPredPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Automatic", @"Advanced", @"")];
248 [fX264optDirectPredPopUp setWantsLayer:YES];
250 @"Direct prediction tells x264 what method to use when guessing motion for certain parts of a B-frame. It can either look at other parts of the current frame (spatial) or compare against the following P-frameframe (temporal). You're best off setting this to automatic, so x264 decides which method is best on its own. Don't select none assuming it will be faster; instead it will take longer and look worse. If you're going to choose between spatial and temporal, spatial is usually better.";
251 [fX264optDirectPredPopUp setToolTip: toolTip];
252 [fX264optDirectPredLabel setToolTip: toolTip];
254 /* Adaptive B-Frames Mode fX264optBAdaptPopUp */
255 [fX264optBAdaptPopUp removeAllItems];
256 [fX264optBAdaptPopUp addItemWithTitle:@"Default (Fast)"];
257 [fX264optBAdaptPopUp addItemWithTitle:@"Off"];
258 [fX264optBAdaptPopUp addItemWithTitle:@"Fast"];
259 [fX264optBAdaptPopUp addItemWithTitle:@"Optimal"];
260 [fX264optBAdaptPopUp setWantsLayer:YES];
262 @"When adaptive B-Frames are disabled, the number of B-Frames you specify is the constant length of every B-Frame sequence. When one of the adaptive modes is enabled, the number of B-Frames is treated as a maximum, with the length of each sequence varying, but never exceeding the max.\n\nFast mode takes the same amount of time no matter how many B-frames you specify. However, it doesn't always make the best decisions on how many B-Frames to use in a sequence.\n\nOptimal mode gets slower as the maximum number of B-Frames increases, but does a much better job at deciding sequence length, which can mean smaller file sizes and better quality.";
263 [fX264optBAdaptPopUp setToolTip: toolTip];
264 [fX264optBAdaptLabel setToolTip: toolTip];
267 [fX264optAlphaDeblockPopUp removeAllItems];
268 [fX264optAlphaDeblockPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (0)", @"Advanced", @"")];
271 [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
274 @"x264 includes an in-loop deblocking filter. What this means is that blocky compression artifacts are smoothed away when you play back the video. It has two settings: strength and threshold, just like a simple filter in Photoshop.\n\nStrength controls the amount of deblocking applied to the whole frame. If you drop down below 0, you reduce the amount of blurring. Go too negative, and you'll get an effect somewhat like oversharpening an image. Go into positive values, and the image may become too soft.\n\nThreshold controls how sensitive the filter is to whether something in a block is detail that needs to be preserved: lower numbers blur details less.\n\nThe default deblocking values are 0 and 0. This does not mean zero deblocking. It means x264 will apply the regular deblocking strength and thresholds the codec authors have selected as working the best in most cases.\n\nWhile many, many people stick with the default deblocking values of 0,0, and you should never change the deblocking without disabling adaptive quantization, other people disagree. Some prefer a slightly less blurred image for live action material, and use values like -2,-1 or -2,-2. Others will raise it to 1,1 or even 3,3 for animation. While the values for each setting extend from -6 to 6, the consensus is that going below -3 or above 3 is worthless.";
275 [fX264optAlphaDeblockPopUp setToolTip: toolTip];
276 [fX264optDeblockLabel setToolTip: toolTip];
279 [fX264optBetaDeblockPopUp removeAllItems];
280 [fX264optBetaDeblockPopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (0)", @"Advanced", @"")];
283 [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
285 [fX264optBetaDeblockPopUp setToolTip: toolTip];
286 [fX264optDeblockLabel setToolTip: toolTip];
288 /* Analysis fX264optAnalysePopUp */
289 [fX264optAnalysePopUp removeAllItems];
291 [fX264optAnalysePopUp addItemWithTitle:NSLocalizedStringFromTable(@"Default (some)", @"Advanced", @"")]; /* 0=default */
292 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"None", @"Advanced", @"")]]; /* 1=none */
293 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"All", @"Advanced", @"")]]; /* 2=all */
295 [fX264optAnalysePopUp addItemWithTitle:@"Default (some)"]; /* 0=default */
296 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
297 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 2=all */
299 @"Analysis controls how finely x264 divides up a frame to capture detail. Full macroblocks are 16x16 pixels, but x264 can go down all the way to 4x4 blocks if it judges it necessary. By default it only breaks up key frames that much. To give x264 the freedom to make the best decisions for all frames, use \"all\" analysis. If you want to create a high profile H.264 video (which is less compatible with the world at large than main profile), also check the \"8x8 DCT blocks\" box to add yet another block size for analysis.";
300 [fX264optAnalysePopUp setToolTip: toolTip];
301 [fX264optAnalyseLabel setToolTip: toolTip];
303 /* 8x8 DCT fX264op8x8dctSwitch */
304 [fX264opt8x8dctSwitch setState:1];
305 [fX264opt8x8dctSwitch setWantsLayer:YES];
307 @"Checking this box lets x264 break key frames down into 8x8 blocks of pixels for analysis. This is a high profile feature of H.264, which makes it less compatible. It should slightly decrease bitrate or improve quality. Turn it on whenever possible.";
308 [fX264opt8x8dctSwitch setToolTip: toolTip];
309 [fX264opt8x8dctLabel setToolTip: toolTip];
311 /* CABAC fX264opCabacSwitch */
312 [fX264optCabacSwitch setState:1];
314 @"CABAC, or context adaptive binary arithmetic coding, is used by x264 to reduce the bitrate needed for a given quality by 15\%. This makes it very cool and very useful, and it should be left on whenever possible. However, it is incompatible with the iPod, and makes the AppleTV struggle. So turn it off for those.\n\nCABAC is a kind of entropy coding, which means that it compresses data by making shorthand symbols to represent long streams of data. The \"entropy\" part means that the symbols it uses the most often are the smallest. When you disable CABAC, another entropy coding scheme gets enabled, called CAVLC (context adaptive variable-length coding). CAVLC is a lot less efficient, which is why it needs 15\% more bitrate to achieve the same quality as CABAC.";
315 [fX264optCabacSwitch setToolTip: toolTip];
316 [fX264optCabacLabel setToolTip: toolTip];
318 /* PsyRDO fX264optPsyRDSlider */
319 [fX264optPsyRDSlider setMinValue:0.0];
320 [fX264optPsyRDSlider setMaxValue:1.0];
321 [fX264optPsyRDSlider setTickMarkPosition:NSTickMarkBelow];
322 [fX264optPsyRDSlider setNumberOfTickMarks:11];
323 [fX264optPsyRDSlider setAllowsTickMarkValuesOnly:YES];
324 [fX264optPsyRDSlider setFloatValue:1.0];
326 @"Psychovisual Rate Distortion Optimization sure is a mouthful, isn't it? Basically, it means x264 tries to retain detail, for better quality to the human eye, as opposed to trying to maximize quality the way a computer understands it, through signal-to-noise ratios that have trouble telling apart fine detail and noise.";
327 [fX264optPsyRDSlider setToolTip: toolTip];
328 [fX264optPsyRDLabel setToolTip: toolTip];
330 /* PsyTrellis fX264optPsyRDSlider */
331 [fX264optPsyTrellisSlider setMinValue:0.0];
332 [fX264optPsyTrellisSlider setMaxValue:1.0];
333 [fX264optPsyTrellisSlider setTickMarkPosition:NSTickMarkBelow];
334 [fX264optPsyTrellisSlider setNumberOfTickMarks:11];
335 [fX264optPsyTrellisSlider setAllowsTickMarkValuesOnly:YES];
336 [fX264optPsyTrellisSlider setFloatValue:0.0];
338 @"Psychovisual Trellis tries to retain more sharpness and detail, but can cause artifacting. It is considered experimental, which is why it's off by default. Good values are 0.1 to 0.2.";
339 [fX264optPsyTrellisSlider setToolTip: toolTip];
340 [fX264optPsyTrellisLabel setToolTip: toolTip];
342 /* Standardize the option string */
343 [self X264AdvancedOptionsStandardizeOptString:nil];
345 /* Set Current GUI Settings based on newly standardized string */
346 [self X264AdvancedOptionsSetCurrentSettings:sender];
348 /* Fade out options that don't apply */
349 [self X264AdvancedOptionsAnimate: sender];
353 * Cleans the option string to use a standard format of option=value
355 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
357 /* Set widgets depending on the opt string in field */
358 NSString * thisOpt; // The separated option such as "bframes=3"
359 NSString * optName = @""; // The option name such as "bframes"
360 NSString * optValue = @"";// The option value such as "3"
361 NSString * changedOptString = @"";
362 NSArray *currentOptsArray;
364 /*First, we get an opt string to process */
365 NSString *currentOptString = [fDisplayX264Options stringValue];
367 /* Verify there is an opt string to process by making sure an
368 option is getting its value set. If so, start to process it. */
369 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
370 if (currentOptRange.location != NSNotFound)
372 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
373 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
375 /*iterate through the array and get <opts> and <values*/
377 int currentOptsArrayCount = [currentOptsArray count];
378 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
380 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
382 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
383 if (splitOptRange.location != NSNotFound)
385 optName = [thisOpt substringToIndex:splitOptRange.location];
386 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
388 /* Standardize the names here depending on whats in the string */
389 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
390 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];
392 else // No value given so we use a default of "1"
396 /* Standardize the names here depending on whats in the string */
397 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
398 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
401 /* Construct New String for opts here.*/
402 if ([thisOpt isEqualToString:@""])
404 /* Blank option, just add it to the string. (Why?) */
405 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
409 if ([changedOptString isEqualToString:@""])
411 /* Blank string, output the current option. */
412 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
416 /* Option exists and string exists, so append the option
417 to the string with a semi-colon inbetween them. */
418 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
424 /* Change the option string to reflect the new standardized option string */
425 [fDisplayX264Options setStringValue:changedOptString];
429 * Cleans the option string to use a standard set of option names, by conflating synonyms.
431 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
433 /* Reference Frames */
434 if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
436 cleanOptNameString = @"ref";
439 /*No Fast PSkip nofast_pskip*/
440 if ([cleanOptNameString isEqualToString:@"no-fast-pskip"] || [cleanOptNameString isEqualToString:@"no_fast_pskip"] || [cleanOptNameString isEqualToString:@"nofast_pskip"])
442 cleanOptNameString = @"no-fast-pskip";
446 if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
448 cleanOptNameString = @"no-dct-decimate";
452 if ([cleanOptNameString isEqualToString:@"subme"])
454 cleanOptNameString = @"subq";
458 if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
459 cleanOptNameString = @"merange";
462 if ([cleanOptNameString isEqualToString:@"weight-b"] || [cleanOptNameString isEqualToString:@"weight_b"])
464 cleanOptNameString = @"weightb";
468 if ([cleanOptNameString isEqualToString:@"b_pyramid"])
470 cleanOptNameString = @"b-pyramid";
473 /*Direct Prediction*/
474 if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
476 cleanOptNameString = @"direct";
480 if ([cleanOptNameString isEqualToString:@"filter"])
482 cleanOptNameString = @"deblock";
486 if ([cleanOptNameString isEqualToString:@"partitions"])
488 cleanOptNameString = @"analyse";
491 return cleanOptNameString;
495 * Fades options in and out depending on whether they're available..
497 - (IBAction) X264AdvancedOptionsAnimate: (id) sender
499 /* Lots of situations to cover.
500 - B-frames (when 0 turn of b-frame specific stuff, when < 2 disable b-pyramid)
501 - CABAC (when 0 turn off trellis)
502 - analysis (if none, turn off 8x8dct)
503 - refs (under 2, disable mixed-refs)
504 - subme (if under 6, turn off psy-rd and psy-trel)
505 - trellis (if 0, turn off psy-trel)
508 if( sender == fX264optBframesPopUp || sender == nil || sender == fDisplayX264Options )
510 if ( [fX264optBframesPopUp indexOfSelectedItem ] > 0 &&
511 [fX264optBframesPopUp indexOfSelectedItem ] < 2)
513 /* If the b-frame widget is at 0 or 1, the user has chosen
514 not to use b-frames at all. So disable the options
515 that can only be used when b-frames are enabled. */
517 if( [fX264optWeightBSwitch isHidden] == false)
519 [[fX264optWeightBSwitch animator] setHidden:YES];
520 [[fX264optWeightBLabel animator] setHidden:YES];
521 if ( [fX264optWeightBSwitch state] == 1 )
522 [fX264optWeightBSwitch performClick:self];
525 if( [fX264optBPyramidSwitch isHidden] == false )
527 [[fX264optBPyramidSwitch animator] setHidden:YES];
528 [[fX264optBPyramidLabel animator] setHidden:YES];
529 if ( [fX264optBPyramidSwitch state] == 1 )
530 [fX264optBPyramidSwitch performClick:self];
533 if( [fX264optDirectPredPopUp isHidden] == false )
535 [[fX264optDirectPredPopUp animator] setHidden:YES];
536 [[fX264optDirectPredLabel animator] setHidden:YES];
537 if ( [fX264optDirectPredPopUp indexOfSelectedItem] > 0 )
539 [fX264optDirectPredPopUp selectItemAtIndex: 0];
540 [[fX264optDirectPredPopUp cell] performClick:self];
544 if( [fX264optBAdaptPopUp isHidden] == false )
546 [[fX264optBAdaptPopUp animator] setHidden:YES];
547 [[fX264optBAdaptLabel animator] setHidden:YES];
548 if ( [fX264optBAdaptPopUp indexOfSelectedItem] > 0 )
550 [fX264optBAdaptPopUp selectItemAtIndex: 0];
551 [[fX264optBAdaptPopUp cell] performClick:self];
555 else if ( [fX264optBframesPopUp indexOfSelectedItem ] == 2)
557 /* Only 1 b-frame? Disable b-pyramid. */
558 if( [fX264optBPyramidSwitch isHidden] == false )
560 [[fX264optBPyramidSwitch animator] setHidden:YES];
561 [[fX264optBPyramidLabel animator] setHidden:YES];
562 if ( [fX264optBPyramidSwitch state] == 1 )
563 [fX264optBPyramidSwitch performClick:self];
566 if( [fX264optWeightBSwitch isHidden] == true )
568 [[fX264optWeightBSwitch animator] setHidden:NO];
569 [[fX264optWeightBLabel animator] setHidden:NO];
572 if( [fX264optDirectPredPopUp isHidden] == true )
574 [[fX264optDirectPredPopUp animator] setHidden:NO];
575 [[fX264optDirectPredLabel animator] setHidden:NO];
578 if( [fX264optBAdaptPopUp isHidden] == true )
580 [[fX264optBAdaptPopUp animator] setHidden:NO];
581 [[fX264optBAdaptLabel animator] setHidden:NO];
586 if( [fX264optBPyramidSwitch isHidden] == true )
588 [[fX264optBPyramidSwitch animator] setHidden:NO];
589 [[fX264optBPyramidLabel animator] setHidden:NO];
592 if( [fX264optWeightBSwitch isHidden] == true )
594 [[fX264optWeightBSwitch animator] setHidden:NO];
595 [[fX264optWeightBLabel animator] setHidden:NO];
598 if( [fX264optDirectPredPopUp isHidden] == true )
600 [[fX264optDirectPredPopUp animator] setHidden:NO];
601 [[fX264optDirectPredLabel animator] setHidden:NO];
604 if( [fX264optBAdaptPopUp isHidden] == true )
606 [[fX264optBAdaptPopUp animator] setHidden:NO];
607 [[fX264optBAdaptLabel animator] setHidden:NO];
612 if( sender == fX264optCabacSwitch || sender == nil || sender == fDisplayX264Options )
614 if ( [fX264optCabacSwitch state] == false)
616 if( [fX264optTrellisPopUp isHidden] == false )
618 /* Without CABAC entropy coding, trellis doesn't run. */
619 [[fX264optTrellisPopUp animator] setHidden:YES];
620 [[fX264optTrellisLabel animator] setHidden:YES];
621 [fX264optTrellisPopUp selectItemAtIndex:0];
622 [[fX264optTrellisPopUp cell] performClick:self];
625 else if( [fX264optTrellisPopUp isHidden] == true)
627 [[fX264optTrellisPopUp animator] setHidden:NO];
628 [[fX264optTrellisLabel animator] setHidden:NO];
632 if( sender == fX264optAnalysePopUp || sender == nil || sender == fDisplayX264Options )
634 if ( [fX264optAnalysePopUp indexOfSelectedItem] == 1)
636 /* No analysis? Disable 8x8dct */
637 if( [fX264opt8x8dctSwitch isHidden] == false )
639 [[fX264opt8x8dctSwitch animator] setHidden:YES];
640 [[fX264opt8x8dctLabel animator] setHidden:YES];
641 if ( [fX264opt8x8dctSwitch state] == 1 )
642 [fX264opt8x8dctSwitch performClick:self];
647 if( [fX264opt8x8dctSwitch isHidden] == true )
649 [[fX264opt8x8dctSwitch animator] setHidden:NO];
650 [[fX264opt8x8dctLabel animator] setHidden:NO];
655 if( sender == fX264optRefPopUp || sender == nil || sender == fDisplayX264Options )
657 if ( [fX264optRefPopUp indexOfSelectedItem] > 0 &&
658 [fX264optRefPopUp indexOfSelectedItem] < 3 )
660 if( [fX264optMixedRefsSwitch isHidden] == false )
662 /* Only do mixed-refs when there are at least 2 refs to mix. */
663 [[fX264optMixedRefsSwitch animator] setHidden:YES];
664 [[fX264optMixedRefsLabel animator] setHidden:YES];
665 if( [fX264optMixedRefsSwitch state] == 1 )
666 [fX264optMixedRefsSwitch performClick:self];
671 if( [fX264optMixedRefsSwitch isHidden] == true )
673 [[fX264optMixedRefsSwitch animator] setHidden:NO];
674 [[fX264optMixedRefsLabel animator] setHidden:NO];
679 if( sender == fX264optMotionEstPopUp || sender == nil || sender == fDisplayX264Options )
681 if ( [fX264optMotionEstPopUp indexOfSelectedItem] < 3 )
683 /* ME-range can only be above 16 if me >= umh
684 and changing it to < 16 is idiotic so hide it . */
685 if( [fX264optMERangePopUp isHidden] == false )
687 [[fX264optMERangePopUp animator] setHidden:YES];
688 [[fX264optMERangeLabel animator] setHidden:YES];
689 if ( [fX264optMERangePopUp indexOfSelectedItem] > 0 )
691 [fX264optMERangePopUp selectItemAtIndex:0];
692 [[fX264optMERangePopUp cell] performClick:self];
698 if( [fX264optMERangePopUp isHidden] == true )
700 [[fX264optMERangePopUp animator] setHidden:NO];
701 [[fX264optMERangeLabel animator] setHidden:NO];
706 if( sender == fX264optSubmePopUp || sender == nil || sender == fDisplayX264Options )
708 if( [fX264optSubmePopUp indexOfSelectedItem] != 0 && [fX264optSubmePopUp indexOfSelectedItem] < 7 )
710 /* No Psy-RDO or Psy=trel if subme < 6. */
711 if( [fX264optPsyRDSlider isHidden] == false )
713 [[fX264optPsyRDSlider animator] setHidden:YES];
714 [[fX264optPsyRDLabel animator] setHidden:YES];
715 [[fX264optPsyRDSlider animator] setFloatValue:1];
716 if ( [fX264optPsyRDSlider floatValue] < 1.0 )
718 [fX264optPsyRDSlider setFloatValue:1.0];
719 [[fX264optPsyRDSlider cell] performClick:self];
723 if( [fX264optPsyTrellisSlider isHidden] == false)
725 [[fX264optPsyTrellisSlider animator] setHidden:YES];
726 [[fX264optPsyTrellisLabel animator] setHidden:YES];
727 [[fX264optPsyTrellisSlider animator] setFloatValue:0];
728 if ( [fX264optPsyTrellisSlider floatValue] > 0.0 )
730 [fX264optPsyTrellisSlider setFloatValue:0.0];
731 [[fX264optPsyTrellisSlider cell] performClick:self];
737 if( [fX264optPsyRDSlider isHidden] == true )
739 [[fX264optPsyRDSlider animator] setHidden:NO];
740 [[fX264optPsyRDLabel animator] setHidden:NO];
743 if( ( [fX264optTrellisPopUp indexOfSelectedItem] == 0 || [fX264optTrellisPopUp indexOfSelectedItem] >= 2 ) && [fX264optCabacSwitch state] == true && [fX264optPsyTrellisSlider isHidden] == true )
745 [[fX264optPsyTrellisSlider animator] setHidden:NO];
746 [[fX264optPsyTrellisLabel animator] setHidden:NO];
751 if( sender == fX264optTrellisPopUp || sender == nil || sender == fDisplayX264Options )
753 if( [fX264optTrellisPopUp indexOfSelectedItem] > 0 && [fX264optTrellisPopUp indexOfSelectedItem] < 2 )
755 if( [fX264optPsyTrellisSlider isHidden] == false )
757 /* No Psy-trellis without trellis. */
758 [[fX264optPsyTrellisSlider animator] setHidden:YES];
759 [[fX264optPsyTrellisLabel animator] setHidden:YES];
760 [[fX264optPsyTrellisSlider animator] setFloatValue:0.0];
761 [[fX264optPsyTrellisSlider cell] performClick:self];
766 if( ( [fX264optSubmePopUp indexOfSelectedItem] == 0 || [fX264optSubmePopUp indexOfSelectedItem] >= 7 ) && [fX264optCabacSwitch state] == true && [fX264optPsyTrellisSlider isHidden] == true )
768 [[fX264optPsyTrellisSlider animator] setHidden:NO];
769 [[fX264optPsyTrellisLabel animator] setHidden:NO];
776 * Resets the GUI widgets to the contents of the option string.
778 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
780 /* Set widgets depending on the opt string in field */
781 NSString * thisOpt; // The separated option such as "bframes=3"
782 NSString * optName = @""; // The option name such as "bframes"
783 NSString * optValue = @"";// The option value such as "3"
784 NSArray *currentOptsArray;
786 /*First, we get an opt string to process */
787 NSString *currentOptString = [fDisplayX264Options stringValue];
789 /* Verify there is an opt string to process by making sure an
790 option is getting its value set. If so, start to process it. */
791 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
792 if (currentOptRange.location != NSNotFound)
794 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
795 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
797 /*iterate through the array and get <opts> and <values*/
799 int currentOptsArrayCount = [currentOptsArray count];
800 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
802 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
804 /* Verify the option sets a value */
805 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
806 if (splitOptRange.location != NSNotFound)
808 /* Split thisOpt into an optName setting an optValue. */
809 optName = [thisOpt substringToIndex:splitOptRange.location];
810 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
812 /*Run through the available widgets for x264 opts and set them, as you add widgets,
813 they need to be added here. This should be moved to its own method probably*/
815 /*bframes NSPopUpButton*/
816 if ([optName isEqualToString:@"bframes"])
818 [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
820 /*ref NSPopUpButton*/
821 if ([optName isEqualToString:@"ref"])
823 [fX264optRefPopUp selectItemAtIndex:[optValue intValue]+1];
825 /*No Fast PSkip NSButton*/
826 if ([optName isEqualToString:@"no-fast-pskip"])
828 [fX264optNfpskipSwitch setState:[optValue intValue]];
830 /*No Dict Decimate NSButton*/
831 if ([optName isEqualToString:@"no-dct-decimate"])
833 [fX264optNodctdcmtSwitch setState:[optValue intValue]];
835 /*Sub Me NSPopUpButton*/
836 if ([optName isEqualToString:@"subq"])
838 [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
840 /*Trellis NSPopUpButton*/
841 if ([optName isEqualToString:@"trellis"])
843 [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
845 /*Mixed Refs NSButton*/
846 if ([optName isEqualToString:@"mixed-refs"])
848 [fX264optMixedRefsSwitch setState:[optValue intValue]];
850 /*Motion Estimation NSPopUpButton*/
851 if ([optName isEqualToString:@"me"])
853 if ([optValue isEqualToString:NSLocalizedStringFromTable(@"dia", @"Advanced", @"")])
854 [fX264optMotionEstPopUp selectItemAtIndex:1];
855 else if ([optValue isEqualToString:NSLocalizedStringFromTable(@"hex", @"Advanced", @"")])
856 [fX264optMotionEstPopUp selectItemAtIndex:2];
857 else if ([optValue isEqualToString:NSLocalizedStringFromTable(@"umh", @"Advanced", @"")])
858 [fX264optMotionEstPopUp selectItemAtIndex:3];
860 else if ([optValue isEqualToString:NSLocalizedStringFromTable(@"esa", @"Advanced", @"")])
861 [fX264optMotionEstPopUp selectItemAtIndex:4];
863 else if ([optValue isEqualToString:@"esa"])
864 [fX264optMotionEstPopUp selectItemAtIndex:4];
865 else if ([optValue isEqualToString:@"tesa"])
866 [fX264optMotionEstPopUp selectItemAtIndex:5];
868 /*ME Range NSPopUpButton*/
869 if ([optName isEqualToString:@"merange"])
871 [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
873 /* Adaptive B-Frames NSPopUpButton*/
874 if ([optName isEqualToString:@"b-adapt"])
876 [fX264optBAdaptPopUp selectItemAtIndex:[optValue intValue]+1];
878 /*Weighted B-Frames NSButton*/
879 if ([optName isEqualToString:@"weightb"])
881 [fX264optWeightBSwitch setState:[optValue intValue]];
883 /*B Pyramid NSPButton*/
884 if ([optName isEqualToString:@"b-pyramid"])
886 [fX264optBPyramidSwitch setState:[optValue intValue]];
888 /*Direct B-frame Prediction NSPopUpButton*/
889 if ([optName isEqualToString:@"direct"])
891 if ([optValue isEqualToString:NSLocalizedStringFromTable(@"none", @"Advanced", @"")])
892 [fX264optDirectPredPopUp selectItemAtIndex:1];
893 else if ([optValue isEqualToString:NSLocalizedStringFromTable(@"spatial", @"Advanced", @"")])
894 [fX264optDirectPredPopUp selectItemAtIndex:2];
895 else if ([optValue isEqualToString:NSLocalizedStringFromTable(@"temporal", @"Advanced", @"")])
896 [fX264optDirectPredPopUp selectItemAtIndex:3];
897 else if ([optValue isEqualToString:NSLocalizedStringFromTable(@"auto", @"Advanced", @"")])
898 [fX264optDirectPredPopUp selectItemAtIndex:4];
900 /*Deblocking NSPopUpButtons*/
901 if ([optName isEqualToString:@"deblock"])
903 NSString * alphaDeblock = @"";
904 NSString * betaDeblock = @"";
906 NSRange splitDeblock = [optValue rangeOfString:@","];
907 alphaDeblock = [optValue substringToIndex:splitDeblock.location];
908 betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
910 if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
912 /* When both filters are at 0, default */
913 [fX264optAlphaDeblockPopUp selectItemAtIndex:0];
914 [fX264optBetaDeblockPopUp selectItemAtIndex:0];
918 if (![alphaDeblock isEqualToString:@"0"])
920 /* Alpha isn't 0, so set it. The offset of 7 is
921 because filters start at -6 instead of at 0. */
922 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
926 /* Set alpha filter to 0, which is 7 up
927 because filters start at -6, not 0. */
928 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];
931 if (![betaDeblock isEqualToString:@"0"])
933 /* Beta isn't 0, so set it. */
934 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
938 /* Set beta filter to 0. */
939 [fX264optBetaDeblockPopUp selectItemAtIndex:7];
943 /* Analysis NSPopUpButton */
944 if ([optName isEqualToString:@"analyse"])
946 if ([optValue isEqualToString:NSLocalizedStringFromTable(@"p8x8,b8x8,i8x8,i4x4", @"Advanced", @"")])
948 /* Default ("some") */
949 [fX264optAnalysePopUp selectItemAtIndex:0];
951 if ([optValue isEqualToString:NSLocalizedStringFromTable(@"none", @"Advanced", @"")])
953 [fX264optAnalysePopUp selectItemAtIndex:1];
955 if ([optValue isEqualToString:NSLocalizedStringFromTable(@"all", @"Advanced", @"")])
957 [fX264optAnalysePopUp selectItemAtIndex:2];
960 /* 8x8 DCT NSButton */
961 if ([optName isEqualToString:@"8x8dct"])
963 [fX264opt8x8dctSwitch setState:[optValue intValue]];
966 if ([optName isEqualToString:@"cabac"])
968 [fX264optCabacSwitch setState:[optValue intValue]];
970 /* Psy-RD and Psy-Trellis NSSliders */
971 if ([optName isEqualToString:@"psy-rd"])
973 NSString * rdOpt = @"";
974 NSString * trellisOpt = @"";
976 NSRange splitRD = [optValue rangeOfString:@","];
977 rdOpt = [optValue substringToIndex:splitRD.location];
978 trellisOpt = [optValue substringFromIndex:splitRD.location + 1];
980 [fX264optPsyRDSlider setFloatValue:[rdOpt floatValue]];
981 [fX264optPsyTrellisSlider setFloatValue:[trellisOpt floatValue]];
988 - (NSString *) X264AdvancedOptionsOptIDToString: (id) widget
990 /*Determine which outlet is being used and set optName to process accordingly */
991 NSString * optNameToChange = @""; // The option name such as "bframes"
993 if (widget == fX264optBframesPopUp)
995 optNameToChange = @"bframes";
997 if (widget == fX264optRefPopUp)
999 optNameToChange = @"ref";
1001 if (widget == fX264optNfpskipSwitch)
1003 optNameToChange = @"no-fast-pskip";
1005 if (widget == fX264optNodctdcmtSwitch)
1007 optNameToChange = @"no-dct-decimate";
1009 if (widget == fX264optSubmePopUp)
1011 optNameToChange = @"subq";
1013 if (widget == fX264optTrellisPopUp)
1015 optNameToChange = @"trellis";
1017 if (widget == fX264optMixedRefsSwitch)
1019 optNameToChange = @"mixed-refs";
1021 if (widget == fX264optMotionEstPopUp)
1023 optNameToChange = @"me";
1025 if (widget == fX264optMERangePopUp)
1027 optNameToChange = @"merange";
1029 if (widget == fX264optBAdaptPopUp)
1031 optNameToChange = @"b-adapt";
1033 if (widget == fX264optWeightBSwitch)
1035 optNameToChange = @"weightb";
1037 if (widget == fX264optBPyramidSwitch)
1039 optNameToChange = @"b-pyramid";
1041 if (widget == fX264optDirectPredPopUp)
1043 optNameToChange = @"direct";
1045 if (widget == fX264optAlphaDeblockPopUp)
1047 optNameToChange = @"deblock";
1049 if (widget == fX264optBetaDeblockPopUp)
1051 optNameToChange = @"deblock";
1053 if (widget == fX264optAnalysePopUp)
1055 optNameToChange = @"analyse";
1057 if (widget == fX264opt8x8dctSwitch)
1059 optNameToChange = @"8x8dct";
1061 if (widget == fX264optCabacSwitch)
1063 optNameToChange = @"cabac";
1065 if( widget == fX264optPsyRDSlider)
1067 optNameToChange = @"psy-rd";
1069 if( widget == fX264optPsyTrellisSlider)
1071 optNameToChange = @"psy-rd";
1074 return optNameToChange;
1077 - (NSString *) X264AdvancedOptionsWidgetToString: (NSString *) optName withID: (id) sender
1079 NSString * thisOpt = @""; // The option=value string the method will return
1081 if ([optName isEqualToString:@"deblock"])
1083 if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
1085 /* When both deblock widgets are 0 or default or a mix of the two,
1086 use a blank string, since deblocking defaults to 0,0. */
1091 /* Otherwise the format is deblock=a,b, where a and b both have an array
1092 offset of 7 because deblocking values start at -6 instead of at zero. */
1093 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
1097 else if ([optName isEqualToString:@"psy-rd"])
1099 if( [fX264optPsyRDSlider floatValue] == 1.0 && [fX264optPsyTrellisSlider floatValue] == 0.0 )
1101 /* When PsyRD is 1 and PsyTrel is 0 they're default values and can be ignored. */
1106 /* Otherwise the format is deblock=a,b, where a and b both have an array
1107 offset of 7 because deblocking values start at -6 instead of at zero. */
1108 thisOpt = [NSString stringWithFormat:@"%@=%0.1f,%0.1f", optName, [fX264optPsyRDSlider floatValue], [fX264optPsyTrellisSlider floatValue] ];
1112 else if /*Boolean Switches*/ ( [optName isEqualToString:@"b-pyramid"] || [optName isEqualToString:@"no-fast-pskip"] || [optName isEqualToString:@"no-dct-decimate"] )
1114 /* Here is where we take care of the boolean options that work overtly:
1115 no-dct-decimate being on means no-dct-decimate=1, etc. Some options
1116 require the inverse, but those will be handled a couple lines down. */
1117 if ([sender state] == 0)
1119 /* When these options are false, don't include them. They all default
1120 to being set off, so they don't need to be mentioned at all. */
1125 /* Otherwise, include them as optioname=1 */
1126 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
1130 else if ( [optName isEqualToString:@"8x8dct"] || [optName isEqualToString:@"weightb"] || [optName isEqualToString:@"mixed-refs"] || [optName isEqualToString:@"cabac"] )
1132 /* These options default to being on. That means they
1133 only need to be included in the string when turned off. */
1134 if ([sender state] == 1)
1136 /* It's true so don't include it. */
1141 /* Otherwise, include cabac=0, etc, in the string. */
1142 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
1146 else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
1148 /* When a widget is at index 0, it's default. Default means don't add to the string.
1149 The exception for deblocking is because for those, *both* need to at index 0
1150 for it to default, so it's handled separately, above this section. */
1154 else if ([optName isEqualToString:@"me"])
1156 /* Motion estimation uses string values, so this switch
1157 pairs the widget index with the right value string. */
1158 switch ([sender indexOfSelectedItem])
1161 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
1165 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
1169 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
1173 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
1177 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"tesa"];
1184 else if ([optName isEqualToString:@"direct"])
1186 /* Direct prediction uses string values, so this switch
1187 pairs the right string value with the right widget index. */
1188 switch ([sender indexOfSelectedItem])
1191 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1195 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
1199 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
1203 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
1211 else if ([optName isEqualToString:@"analyse"])
1213 /* Analysis uses string values as well. */
1214 switch ([sender indexOfSelectedItem])
1217 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1221 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
1229 else if ([optName isEqualToString:@"merange"])
1231 /* Motion estimation range uses an odd array offset because in addition
1232 to starting with index 0 as default, index 1 starts at 4 instead of 1,
1233 because merange can't go below 4. So it has to be handled separately. */
1234 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
1237 else if ([optName isEqualToString:@"b-adapt"])
1239 /* B-adapt starts at index 0 with default then goes 0, 1, 2)*/
1240 thisOpt = [NSString stringWithFormat:@"%@=%d", optName, [sender indexOfSelectedItem]-1];
1243 else // we have a valid value to change, so change it
1245 if ( [sender indexOfSelectedItem] != 0 )
1246 /* Here's our general case, that catches things like ref frames and b-frames.
1247 Basically, any options that are PopUp menus with index 0 as default and
1248 index 1 as 1, with numerical values, are all handled right here. All of
1249 the above stuff is for the exceptions to the general case. */
1250 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
1256 - (BOOL) X264AdvancedOptionsIsOpt: (NSString *) optNameToChange inString: (NSString *) currentOptString
1258 /* If the option is in the string but not the beginning of it,
1259 it will be in the form of ":optName=value" so we really want
1260 to be looking for ":optNameToChange=" rather than "optNameToChange". */
1261 NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
1263 /* Now we store the part of the string up through the option name in currentOptRange. */
1264 NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
1266 /* We need to know if the option is at the beginning of the string.
1267 If it is at the start, it won't be preceded by a colon.
1268 To figure this out, we'll use the rangeOfString method. First,
1269 store what the option name would be if if it was at the beginning,
1270 in checkOptNameToChangeBeginning. Then, find its range in the string.
1271 If the range is 0, it's the first option listed in the string. */
1272 NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
1273 NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
1275 if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
1282 * Resets the option string to mirror the GUI widgets.
1284 - (IBAction) X264AdvancedOptionsChanged: (id) sender
1286 /* Look up the equivalent string option name of the calling widget. */
1287 NSString * optNameToChange = [self X264AdvancedOptionsOptIDToString: sender];
1289 NSString * thisOpt = @""; // The separated option such as "bframes=3"
1290 NSString * optName = @""; // The option name such as "bframes"
1291 NSString * optValue = @""; // The option value such as "3"
1292 NSArray *currentOptsArray;
1294 /* Get the current opt string being displayed. */
1295 NSString *currentOptString = [fDisplayX264Options stringValue];
1297 /* There are going to be a few possibilities.
1298 - The option might start off the string.
1299 - The option might be in the middle of the string.
1300 - The option might not be in the string at all yet.
1301 - The string itself might not yet exist. */
1303 if( [self X264AdvancedOptionsIsOpt: optNameToChange inString: currentOptString] )
1305 /* If the option is in the string wth a semicolon, or starts the string, it's time to edit.
1306 This means parsing the whole string into an array of options and values. From there,
1307 iterate through the options, and when you reach the one that's been changed, edit it. */
1309 /* Create new empty opt string*/
1310 NSString *changedOptString = @"";
1312 /* Put individual options into an array based on the ":"
1313 separator for processing, result is "<opt>=<value>" */
1314 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
1316 /* Iterate through the array and get <opts> and <values*/
1318 int currentOptsArrayCount = [currentOptsArray count];
1319 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
1321 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
1322 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
1324 if (splitOptRange.location != NSNotFound)
1326 /* First off, it's time to handle option strings that
1327 already have at least one option=value pair in them. */
1329 optName = [thisOpt substringToIndex:splitOptRange.location];
1330 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
1332 /*If the optNameToChange is found, appropriately change the value or delete it if
1333 "Unspecified" is set.*/
1334 if ([optName isEqualToString:optNameToChange])
1336 thisOpt = [self X264AdvancedOptionsWidgetToString: optName withID: sender];
1340 /* Construct New String for opts here */
1341 if ([thisOpt isEqualToString:@""])
1343 /* Blank option, so just add it to the string. (Why?) */
1344 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
1348 if ([changedOptString isEqualToString:@""])
1350 /* No existing string, make the string this option. */
1351 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
1355 /* Existing string, existing option. Append the
1356 option to the string, preceding it with a colon. */
1357 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
1362 /* Change the dislayed option string to reflect the new modified settings */
1363 [fDisplayX264Options setStringValue:changedOptString];
1365 else // if none exists, add it to the string
1367 /* This is where options that aren't already in the string are handled. */
1368 if ([[fDisplayX264Options stringValue] isEqualToString: @""])
1371 [fDisplayX264Options setStringValue:
1372 [self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender]];
1376 /* The string isn't empty, and the option isn't already in it, so
1377 it will need to be appended to the current string with a colon,
1378 as long as the string to be appended isn't just blank (default). */
1379 if( [[self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender] isEqualToString: @""] == false )
1381 [fDisplayX264Options setStringValue:
1382 [NSString stringWithFormat:@"%@:%@",
1384 [self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender] ]];
1389 /* We now need to reset the opt widgets since we changed some stuff */
1390 [self X264AdvancedOptionsSet:sender];