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: @"Only Used With The x264 (H.264) Codec"];
56 [fOptionsBox setContentView:fX264optView];
57 [fX264optViewTitleLabel setStringValue: @""];
62 - (void) enableUI: (bool) b
65 NSControl * controls[] =
66 { fX264optViewTitleLabel,fDisplayX264Options,fDisplayX264OptionsLabel,fX264optBframesLabel,
67 fX264optBframesPopUp,fX264optRefLabel,fX264optRefPopUp,
68 fX264optNodctdcmtLabel,fX264optNodctdcmtSwitch,fX264optSubmeLabel,fX264optSubmePopUp,
69 fX264optTrellisLabel,fX264optTrellisPopUp, fX264optWeightPLabel, fX264optWeightPSwitch,
70 fX264optMotionEstLabel,fX264optMotionEstPopUp,fX264optMERangeLabel,fX264optMERangePopUp,
71 fX264optBPyramidLabel,fX264optBPyramidPopUp, fX264optAqLabel, fX264optAqSlider,
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];
112 [fX264optBframesPopUp addItemWithTitle:@"Default (3)"];
115 [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
118 @"Sane values are ~2-5. This specifies the maximum number of sequential B-frames that the encoder can use. Large numbers generally won't help significantly unless Adaptive B-frames is set to Optimal. Cel-animated source material and B-pyramid also significantly increase the usefulness of larger values. Baseline profile, as required for iPods and similar devices, requires B-frames to be set to 0 (off).";
119 [fX264optBframesPopUp setToolTip: toolTip];
120 [fX264optBframesLabel setToolTip: toolTip];
122 /*Reference Frames fX264optRefPopUp*/
123 [fX264optRefPopUp removeAllItems];
124 [fX264optRefPopUp addItemWithTitle:@"Default (3)"];
127 [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
130 @"Sane values are ~1-6. The more you add, the better the compression, but the slower the encode. Cel animation tends to benefit from more reference frames a lot more than film content. Note that many hardware devices have limitations on the number of supported reference frames, so if you're encoding for a handheld or standalone player, don't touch this unless you're absolutely sure you know what you're doing!";
131 [fX264optRefPopUp setToolTip: toolTip];
132 [fX264optRefLabel setToolTip: toolTip];
134 /*Weight-P fX264optWeightPSwitch BOOLEAN*/
135 [fX264optWeightPSwitch setState:1];
137 @"Performs extra analysis to decide upon weighting parameters for each frame. This improves overall compression slightly and improves the quality of fades greatly. Baseline profile, as required for iPods and similar devices, requires weighted P-frame prediction to be disabled. Note that some devices and players, even those that support Main Profile, may have problems with Weighted P-frame prediction: the Apple TV is completely incompatible with it, for example.";
138 [fX264optWeightPSwitch setToolTip: toolTip];
139 [fX264optWeightPLabel setToolTip: toolTip];
141 /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
142 [fX264optNodctdcmtSwitch setState:0];
144 @"x264 normally zeroes out nearly-empty data blocks to save bits to be better used for some other purpose in the video. However, this can sometimes have slight negative effects on retention of subtle grain and dither. Don't touch this unless you're having banding issues or other such cases where you are having trouble keeping fine noise.";
145 [fX264optNodctdcmtSwitch setToolTip: toolTip];
146 [fX264optNodctdcmtLabel setToolTip: toolTip];
148 /*Sub Me fX264optSubmePopUp*/
149 [fX264optSubmePopUp removeAllItems];
150 [fX264optSubmePopUp addItemWithTitle:@"Default (7)"];
151 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"0: SAD, no subpel (super fast!)"]];
152 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"1: SAD, qpel"]];
153 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"2: SATD, qpel"]];
154 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"3: SATD, multi-qpel"]];
155 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"4: SATD, qpel on all"]];
156 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"5: SATD, multi-qpel on all"]];
157 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"6: RD in I/P-frames"]];
158 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"7: RD in all frames"]];
159 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"8: RD refine in I/P-frames"]];
160 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"9: RD refine in all frames"]];
161 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"10: QPRD in all frames"]];
163 @"This setting controls both subpixel-precision motion estimation and mode decision methods.\n\nSubpixel motion estimation is used for refining motion estimates beyond mere pixel accuracy, improving compression.\n\nMode decision is the method used to choose how to encode each block of the frame: a very important decision.\n\nSAD is the fastest method, followed by SATD, RD, RD refinement, and the slowest, QPRD.\n\n6 or higher is strongly recommended: Psy-RD, a very powerful psy optimization that helps retain detail, requires RD.\n\n10, the most powerful and slowest option, requires trellis=2.";
164 [fX264optSubmePopUp setToolTip: toolTip];
165 [fX264optSubmeLabel setToolTip: toolTip];
167 /*Trellis fX264optTrellisPopUp*/
168 [fX264optTrellisPopUp removeAllItems];
169 [fX264optTrellisPopUp addItemWithTitle:@"Default (Encode only)"];
170 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"Off"]];
171 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"Encode only"]];
172 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"Always"]];
173 [fX264optTrellisPopUp setWantsLayer:YES];
175 @"Trellis fine-tunes the rounding of transform coefficients to squeeze out 3-5% more compression at the cost of some speed. \"Always\" uses trellis not only during the main encoding process, but also during analysis, which improves compression even more, albeit at great speed cost. Trellis costs more speed at higher bitrates and requires CABAC.";
176 [fX264optTrellisPopUp setToolTip: toolTip];
177 [fX264optTrellisLabel setToolTip: toolTip];
179 /*Motion Estimation fX264optMotionEstPopUp*/
180 [fX264optMotionEstPopUp removeAllItems];
181 [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
182 [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
183 [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
184 [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
185 [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
186 [fX264optMotionEstPopUp addItemWithTitle:@"Transformed Exhaustive"];
188 @"Controls the motion estimation method. Motion estimation is how the encoder estimates how each block of pixels in a frame has moved. A better motion search method improves compression at the cost of speed.\n\nDiamond: performs an extremely fast and simple search using a diamond pattern.\n\nHexagon: performs a somewhat more effective but slightly slower search using a hexagon pattern.\n\nUneven Multi-Hex: performs a very wide search using a variety of patterns, more accurately capturing complex motion.\n\nExhaustive: performs a \"dumb\" search of every pixel in a wide area. Significantly slower for only a small compression gain.\n\nTransformed Exhaustive: Like exhaustive, but makes even more accurate decisions. Accordingly, somewhat slower, also for only a small improvement.";
189 [fX264optMotionEstPopUp setToolTip: toolTip];
190 [fX264optMotionEstLabel setToolTip: toolTip];
192 /*Motion Estimation range fX264optMERangePopUp*/
193 [fX264optMERangePopUp removeAllItems];
194 [fX264optMERangePopUp addItemWithTitle:@"Default (16)"];
197 [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
200 @"This is the distance x264 searches from its best guess at the motion of a block in order to try to find its actual motion. Doesn't apply to Diamond or Hexagon search options. The default is fine for most content, but extremely high motion video, especially at HD resolutions, may benefit from higher ranges, albeit at a high speed cost.";
201 [fX264optMERangePopUp setToolTip: toolTip];
202 [fX264optMERangeLabel setToolTip: toolTip];
204 /*B-frame Pyramids fX264optBPyramidPopUp*/
205 [fX264optBPyramidPopUp removeAllItems];
206 [fX264optBPyramidPopUp addItemWithTitle:@"Default (Normal)"];
207 [fX264optBPyramidPopUp addItemWithTitle:@"Off"];
208 [fX264optBPyramidPopUp addItemWithTitle:@"Strict"];
209 [fX264optBPyramidPopUp setWantsLayer:YES];
211 @"B-pyramid improves compression by creating a pyramidal structure (hence the name) of B-frames, allowing B-frames to reference each other to improve compression. Requires Max B-frames greater than 1; optimal adaptive B-frames is strongly recommended for full compression benefit.";
212 [fX264optBPyramidPopUp setToolTip: toolTip];
213 [fX264optBPyramidLabel setToolTip: toolTip];
215 /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
216 [fX264optDirectPredPopUp removeAllItems];
217 [fX264optDirectPredPopUp addItemWithTitle:@"Default (Spatial)"];
218 [fX264optDirectPredPopUp addItemWithTitle:@"None"];
219 [fX264optDirectPredPopUp addItemWithTitle:@"Spatial"];
220 [fX264optDirectPredPopUp addItemWithTitle:@"Temporal"];
221 [fX264optDirectPredPopUp addItemWithTitle:@"Automatic"];
222 [fX264optDirectPredPopUp setWantsLayer:YES];
224 @"H.264 allows for two different prediction modes, spatial and temporal, in B-frames.\n\nSpatial, the default, is almost always better, but temporal is sometimes useful too.\n\nx264 can, at the cost of a small amount of speed (and accordingly for a small compression gain), adaptively select which is better for each particular frame.";
225 [fX264optDirectPredPopUp setToolTip: toolTip];
226 [fX264optDirectPredLabel setToolTip: toolTip];
228 /* Adaptive B-Frames Mode fX264optBAdaptPopUp */
229 [fX264optBAdaptPopUp removeAllItems];
230 [fX264optBAdaptPopUp addItemWithTitle:@"Default (Fast)"];
231 [fX264optBAdaptPopUp addItemWithTitle:@"Off"];
232 [fX264optBAdaptPopUp addItemWithTitle:@"Fast"];
233 [fX264optBAdaptPopUp addItemWithTitle:@"Optimal"];
234 [fX264optBAdaptPopUp setWantsLayer:YES];
236 @"x264 has a variety of algorithms to decide when to use B-frames and how many to use.\n\nFast mode takes roughly the same amount of time no matter how many B-frames you specify. However, while fast, its decisions are often suboptimal.\n\nOptimal mode gets slower as the maximum number of B-Frames increases, but makes much more accurate decisions, especially when used with B-pyramid.";
237 [fX264optBAdaptPopUp setToolTip: toolTip];
238 [fX264optBAdaptLabel setToolTip: toolTip];
241 [fX264optAlphaDeblockPopUp removeAllItems];
242 [fX264optAlphaDeblockPopUp addItemWithTitle:@"Default (0)"];
245 [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
248 @"H.264 has a built-in deblocking filter that smooths out blocking artifacts after decoding each frame. This not only improves visual quality, but also helps compression significantly. The deblocking filter takes a lot of CPU power, so if you're looking to minimize CPU requirements for video playback, disable it.\n\nThe deblocking filter has two adjustable parameters, \"strength\" and \"threshold\". The former controls how strong (or weak) the deblocker is, while the latter controls how many (or few) edges it applies to. Lower values mean less deblocking, higher values mean more deblocking. The default is 0 (normal strength) for both parameters.";
249 [fX264optAlphaDeblockPopUp setToolTip: toolTip];
250 [fX264optDeblockLabel setToolTip: toolTip];
253 [fX264optBetaDeblockPopUp removeAllItems];
254 [fX264optBetaDeblockPopUp addItemWithTitle:@"Default (0)"];
257 [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
259 [fX264optBetaDeblockPopUp setToolTip: toolTip];
260 [fX264optDeblockLabel setToolTip: toolTip];
262 /* Analysis fX264optAnalysePopUp */
263 [fX264optAnalysePopUp removeAllItems];
264 [fX264optAnalysePopUp addItemWithTitle:@"Default (Most)"]; /* 0=default */
265 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
266 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"Some"]]; /* 2=some */
267 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 3=all */
269 @"Mode decision picks from a variety of options to make its decision: this option chooses what options those are. Fewer partitions to check means faster encoding, at the cost of worse decisions, since the best option might have been one that was turned off.";
270 [fX264optAnalysePopUp setToolTip: toolTip];
271 [fX264optAnalyseLabel setToolTip: toolTip];
273 /* 8x8 DCT fX264op8x8dctSwitch */
274 [fX264opt8x8dctSwitch setState:1];
275 [fX264opt8x8dctSwitch setWantsLayer:YES];
277 @"The 8x8 transform is the single most useful feature of x264 in terms of compression-per-speed. It improves compression by at least 5% at a very small speed cost and may provide an unusually high visual quality benefit compared to its compression gain. However, it requires High Profile, which many devices may not support.";
278 [fX264opt8x8dctSwitch setToolTip: toolTip];
279 [fX264opt8x8dctLabel setToolTip: toolTip];
281 /* CABAC fX264opCabacSwitch */
282 [fX264optCabacSwitch setState:1];
284 @"After the encoder has done its work, it has a bunch of data that needs to be compressed losslessly, similar to ZIP or RAR. H.264 provides two options for this: CAVLC and CABAC. CABAC decodes a lot slower but compresses significantly better (10-30%), especially at lower bitrates. If you're looking to minimize CPU requirements for video playback, disable this option. Baseline profile, as required for iPods and similar devices, requires CABAC to be disabled.";
285 [fX264optCabacSwitch setToolTip: toolTip];
286 [fX264optCabacLabel setToolTip: toolTip];
288 /* Adaptive Quantization Strength fX264opAqSlider */
289 [fX264optAqSlider setMinValue:0.0];
290 [fX264optAqSlider setMaxValue:2.0];
291 [fX264optAqSlider setTickMarkPosition:NSTickMarkBelow];
292 [fX264optAqSlider setNumberOfTickMarks:21];
293 [fX264optAqSlider setAllowsTickMarkValuesOnly:YES];
294 [fX264optAqSlider setFloatValue:1.0];
296 @"Adaptive quantization controls how the encoder distributes bits across the frame. Higher values take more bits away from edges and complex areas to improve areas with finer detail.";
297 [fX264optAqSlider setToolTip: toolTip];
298 [fX264optAqLabel setToolTip: toolTip];
300 /* PsyRDO fX264optPsyRDSlider */
301 [fX264optPsyRDSlider setMinValue:0.0];
302 [fX264optPsyRDSlider setMaxValue:2.0];
303 [fX264optPsyRDSlider setTickMarkPosition:NSTickMarkBelow];
304 [fX264optPsyRDSlider setNumberOfTickMarks:21];
305 [fX264optPsyRDSlider setAllowsTickMarkValuesOnly:YES];
306 [fX264optPsyRDSlider setFloatValue:1.0];
308 @"Psychovisual rate-distortion optimization takes advantage of the characteristics of human vision to dramatically improve apparent detail and sharpness. The effect can be made weaker or stronger by adjusting the strength. Being an RD algorithm, it requires mode decision to be at least \"6\".";
309 [fX264optPsyRDSlider setToolTip: toolTip];
310 [fX264optPsyRDLabel setToolTip: toolTip];
312 /* PsyTrellis fX264optPsyRDSlider */
313 [fX264optPsyTrellisSlider setMinValue:0.0];
314 [fX264optPsyTrellisSlider setMaxValue:1.0];
315 [fX264optPsyTrellisSlider setTickMarkPosition:NSTickMarkBelow];
316 [fX264optPsyTrellisSlider setNumberOfTickMarks:21];
317 [fX264optPsyTrellisSlider setAllowsTickMarkValuesOnly:YES];
318 [fX264optPsyTrellisSlider setFloatValue:0.0];
320 @"Psychovisual trellis is an experimental algorithm to further improve sharpness and detail retention beyond what Psychovisual RD does. Recommended values are around 0.2, though higher values may help for very grainy video or lower bitrate encodes. Not recommended for cel animation and other sharp-edged graphics.";
321 [fX264optPsyTrellisSlider setToolTip: toolTip];
322 [fX264optPsyTrellisLabel setToolTip: toolTip];
324 /* Standardize the option string */
325 [self X264AdvancedOptionsStandardizeOptString:nil];
327 /* Set Current GUI Settings based on newly standardized string */
328 [self X264AdvancedOptionsSetCurrentSettings:sender];
330 /* Fade out options that don't apply */
331 [self X264AdvancedOptionsAnimate: sender];
335 * Cleans the option string to use a standard format of option=value
337 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
339 /* Set widgets depending on the opt string in field */
340 NSString * thisOpt; // The separated option such as "bframes=3"
341 NSString * optName = @""; // The option name such as "bframes"
342 NSString * optValue = @"";// The option value such as "3"
343 NSString * changedOptString = @"";
344 NSArray *currentOptsArray;
346 /*First, we get an opt string to process */
347 NSString *currentOptString = [fDisplayX264Options stringValue];
349 /* Verify there is an opt string to process by making sure an
350 option is getting its value set. If so, start to process it. */
351 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
352 if (currentOptRange.location != NSNotFound)
354 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
355 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
357 /*iterate through the array and get <opts> and <values*/
359 int currentOptsArrayCount = [currentOptsArray count];
360 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
362 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
364 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
365 if (splitOptRange.location != NSNotFound)
367 optName = [thisOpt substringToIndex:splitOptRange.location];
368 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
370 /* Standardize the names here depending on whats in the string */
371 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
372 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];
374 else // No value given so we use a default of "1"
378 /* Standardize the names here depending on whats in the string */
379 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
380 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
383 /* Construct New String for opts here.*/
384 if ([thisOpt isEqualToString:@""])
386 /* Blank option, just add it to the string. (Why?) */
387 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
391 if ([changedOptString isEqualToString:@""])
393 /* Blank string, output the current option. */
394 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
398 /* Option exists and string exists, so append the option
399 to the string with a semi-colon inbetween them. */
400 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
406 /* Change the option string to reflect the new standardized option string */
407 [fDisplayX264Options setStringValue:changedOptString];
411 * Cleans the option string to use a standard set of option names, by conflating synonyms.
413 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
415 /* Reference Frames */
416 if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
418 cleanOptNameString = @"ref";
422 if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
424 cleanOptNameString = @"no-dct-decimate";
428 if ([cleanOptNameString isEqualToString:@"subme"])
430 cleanOptNameString = @"subq";
434 if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
435 cleanOptNameString = @"merange";
438 if ([cleanOptNameString isEqualToString:@"b_pyramid"])
440 cleanOptNameString = @"b-pyramid";
443 /*Direct Prediction*/
444 if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
446 cleanOptNameString = @"direct";
450 if ([cleanOptNameString isEqualToString:@"filter"])
452 cleanOptNameString = @"deblock";
456 if ([cleanOptNameString isEqualToString:@"partitions"])
458 cleanOptNameString = @"analyse";
461 return cleanOptNameString;
465 * Fades options in and out depending on whether they're available..
467 - (IBAction) X264AdvancedOptionsAnimate: (id) sender
469 /* Lots of situations to cover.
470 - B-frames (when 0 turn of b-frame specific stuff, when < 2 disable b-pyramid)
471 - CABAC (when 0 turn off trellis and psy-trel)
472 - subme (if under 6, turn off psy-rd and psy-trel)
473 - trellis (if 0, turn off psy-trel)
476 if( sender == fX264optBframesPopUp || sender == nil || sender == fDisplayX264Options )
478 if ( [fX264optBframesPopUp indexOfSelectedItem ] == 1 )
480 /* If the b-frame widget is at 1, the user has chosen
481 not to use b-frames at all. So disable the options
482 that can only be used when b-frames are enabled. */
484 if( [fX264optBPyramidPopUp isHidden] == false )
486 [[fX264optBPyramidPopUp animator] setHidden:YES];
487 [[fX264optBPyramidLabel animator] setHidden:YES];
488 if ( [fX264optBPyramidPopUp indexOfSelectedItem] > 0 )
490 [fX264optBPyramidPopUp selectItemAtIndex: 0];
491 [[fX264optBPyramidPopUp cell] performClick:self];
495 if( [fX264optDirectPredPopUp isHidden] == false )
497 [[fX264optDirectPredPopUp animator] setHidden:YES];
498 [[fX264optDirectPredLabel animator] setHidden:YES];
499 if ( [fX264optDirectPredPopUp indexOfSelectedItem] > 0 )
501 [fX264optDirectPredPopUp selectItemAtIndex: 0];
502 [[fX264optDirectPredPopUp cell] performClick:self];
506 if( [fX264optBAdaptPopUp isHidden] == false )
508 [[fX264optBAdaptPopUp animator] setHidden:YES];
509 [[fX264optBAdaptLabel animator] setHidden:YES];
510 if ( [fX264optBAdaptPopUp indexOfSelectedItem] > 0 )
512 [fX264optBAdaptPopUp selectItemAtIndex: 0];
513 [[fX264optBAdaptPopUp cell] performClick:self];
517 else if ( [fX264optBframesPopUp indexOfSelectedItem ] == 2)
519 /* Only 1 b-frame? Disable b-pyramid. */
520 if( [fX264optBPyramidPopUp isHidden] == false )
522 [[fX264optBPyramidPopUp animator] setHidden:YES];
523 [[fX264optBPyramidLabel animator] setHidden:YES];
524 if ( [fX264optBPyramidPopUp indexOfSelectedItem] > 0 )
526 [fX264optBPyramidPopUp selectItemAtIndex: 0];
527 [[fX264optBPyramidPopUp cell] performClick:self];
531 if( [fX264optDirectPredPopUp isHidden] == true )
533 [[fX264optDirectPredPopUp animator] setHidden:NO];
534 [[fX264optDirectPredLabel animator] setHidden:NO];
537 if( [fX264optBAdaptPopUp isHidden] == true )
539 [[fX264optBAdaptPopUp animator] setHidden:NO];
540 [[fX264optBAdaptLabel animator] setHidden:NO];
545 if( [fX264optBPyramidPopUp isHidden] == true )
547 [[fX264optBPyramidPopUp animator] setHidden:NO];
548 [[fX264optBPyramidLabel animator] setHidden:NO];
551 if( [fX264optDirectPredPopUp isHidden] == true )
553 [[fX264optDirectPredPopUp animator] setHidden:NO];
554 [[fX264optDirectPredLabel animator] setHidden:NO];
557 if( [fX264optBAdaptPopUp isHidden] == true )
559 [[fX264optBAdaptPopUp animator] setHidden:NO];
560 [[fX264optBAdaptLabel animator] setHidden:NO];
565 if( sender == fX264optCabacSwitch || sender == nil || sender == fDisplayX264Options )
567 if ( [fX264optCabacSwitch state] == false)
569 if( [fX264optTrellisPopUp isHidden] == false )
571 /* Without CABAC entropy coding, trellis doesn't run. */
572 [[fX264optTrellisPopUp animator] setHidden:YES];
573 [[fX264optTrellisLabel animator] setHidden:YES];
574 [fX264optTrellisPopUp selectItemAtIndex:0];
575 [[fX264optTrellisPopUp cell] performClick:self];
577 if( [fX264optPsyTrellisSlider isHidden] == false)
579 [[fX264optPsyTrellisSlider animator] setHidden:YES];
580 [[fX264optPsyTrellisLabel animator] setHidden:YES];
581 if ( [fX264optPsyTrellisSlider floatValue] > 0.0 )
583 [fX264optPsyTrellisSlider setFloatValue:0.0];
584 [[fX264optPsyTrellisSlider cell] performClick:self];
589 else if( [fX264optTrellisPopUp isHidden] == true)
591 [[fX264optTrellisPopUp animator] setHidden:NO];
592 [[fX264optTrellisLabel animator] setHidden:NO];
594 if( [fX264optPsyTrellisSlider isHidden] == true)
596 [[fX264optPsyTrellisSlider animator] setHidden:NO];
597 [[fX264optPsyTrellisLabel animator] setHidden:NO];
603 if( sender == fX264optMotionEstPopUp || sender == nil || sender == fDisplayX264Options )
605 if ( [fX264optMotionEstPopUp indexOfSelectedItem] < 3 )
607 /* ME-range can only be above 16 if me >= umh
608 and changing it to < 16 is idiotic so hide it . */
609 if( [fX264optMERangePopUp isHidden] == false )
611 [[fX264optMERangePopUp animator] setHidden:YES];
612 [[fX264optMERangeLabel animator] setHidden:YES];
613 if ( [fX264optMERangePopUp indexOfSelectedItem] > 0 )
615 [fX264optMERangePopUp selectItemAtIndex:0];
616 [[fX264optMERangePopUp cell] performClick:self];
622 if( [fX264optMERangePopUp isHidden] == true )
624 [[fX264optMERangePopUp animator] setHidden:NO];
625 [[fX264optMERangeLabel animator] setHidden:NO];
630 if( sender == fX264optSubmePopUp || sender == nil || sender == fDisplayX264Options )
632 if( [fX264optSubmePopUp indexOfSelectedItem] != 0 && [fX264optSubmePopUp indexOfSelectedItem] < 7 )
634 /* No Psy-RDO or Psy=trel if subme < 6. */
635 if( [fX264optPsyRDSlider isHidden] == false )
637 [[fX264optPsyRDSlider animator] setHidden:YES];
638 [[fX264optPsyRDLabel animator] setHidden:YES];
639 if ( [fX264optPsyRDSlider floatValue] < 1.0 )
641 [fX264optPsyRDSlider setFloatValue:1.0];
642 [[fX264optPsyRDSlider cell] performClick:self];
646 if( [fX264optPsyTrellisSlider isHidden] == false)
648 [[fX264optPsyTrellisSlider animator] setHidden:YES];
649 [[fX264optPsyTrellisLabel animator] setHidden:YES];
650 if ( [fX264optPsyTrellisSlider floatValue] > 0.0 )
652 [fX264optPsyTrellisSlider setFloatValue:0.0];
653 [[fX264optPsyTrellisSlider cell] performClick:self];
659 if( [fX264optPsyRDSlider isHidden] == true )
661 [[fX264optPsyRDSlider animator] setHidden:NO];
662 [[fX264optPsyRDLabel animator] setHidden:NO];
665 if( ( [fX264optTrellisPopUp indexOfSelectedItem] == 0 || [fX264optTrellisPopUp indexOfSelectedItem] >= 2 ) && [fX264optCabacSwitch state] == true && [fX264optPsyTrellisSlider isHidden] == true )
667 [[fX264optPsyTrellisSlider animator] setHidden:NO];
668 [[fX264optPsyTrellisLabel animator] setHidden:NO];
673 if( sender == fX264optTrellisPopUp || sender == nil || sender == fDisplayX264Options )
675 if( [fX264optTrellisPopUp indexOfSelectedItem] > 0 && [fX264optTrellisPopUp indexOfSelectedItem] < 2 )
677 if( [fX264optPsyTrellisSlider isHidden] == false )
679 /* No Psy-trellis without trellis. */
680 [[fX264optPsyTrellisSlider animator] setHidden:YES];
681 [[fX264optPsyTrellisLabel animator] setHidden:YES];
682 [[fX264optPsyTrellisSlider animator] setFloatValue:0.0];
683 [[fX264optPsyTrellisSlider cell] performClick:self];
688 if( ( [fX264optSubmePopUp indexOfSelectedItem] == 0 || [fX264optSubmePopUp indexOfSelectedItem] >= 7 ) && [fX264optCabacSwitch state] == true && [fX264optPsyTrellisSlider isHidden] == true )
690 [[fX264optPsyTrellisSlider animator] setHidden:NO];
691 [[fX264optPsyTrellisLabel animator] setHidden:NO];
698 * Resets the GUI widgets to the contents of the option string.
700 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
702 /* Set widgets depending on the opt string in field */
703 NSString * thisOpt; // The separated option such as "bframes=3"
704 NSString * optName = @""; // The option name such as "bframes"
705 NSString * optValue = @"";// The option value such as "3"
706 NSArray *currentOptsArray;
708 /*First, we get an opt string to process */
709 NSString *currentOptString = [fDisplayX264Options stringValue];
711 /* Verify there is an opt string to process by making sure an
712 option is getting its value set. If so, start to process it. */
713 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
714 if (currentOptRange.location != NSNotFound)
716 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
717 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
719 /*iterate through the array and get <opts> and <values*/
721 int currentOptsArrayCount = [currentOptsArray count];
722 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
724 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
726 /* Verify the option sets a value */
727 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
728 if (splitOptRange.location != NSNotFound)
730 /* Split thisOpt into an optName setting an optValue. */
731 optName = [thisOpt substringToIndex:splitOptRange.location];
732 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
734 /*Run through the available widgets for x264 opts and set them, as you add widgets,
735 they need to be added here. This should be moved to its own method probably*/
737 /*bframes NSPopUpButton*/
738 if ([optName isEqualToString:@"bframes"])
740 [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
742 /*ref NSPopUpButton*/
743 if ([optName isEqualToString:@"ref"])
745 // Clamp values to a minimum of 1 and a maximum of 16
746 if ( [optValue intValue] < 1 )
748 [fX264optRefPopUp selectItemAtIndex:1];
749 [ self X264AdvancedOptionsChanged: fX264optRefPopUp];
751 else if ( [optValue intValue] > 16 )
753 [fX264optRefPopUp selectItemAtIndex:16];
754 [ self X264AdvancedOptionsChanged: fX264optRefPopUp];
758 [fX264optRefPopUp selectItemAtIndex:[optValue intValue]];
762 if ([optName isEqualToString:@"weightp"])
764 if ([optValue intValue] < 1)
765 [fX264optWeightPSwitch setState:0];
767 [fX264optWeightPSwitch setState:1];
769 /*No Dict Decimate NSButton*/
770 if ([optName isEqualToString:@"no-dct-decimate"])
772 [fX264optNodctdcmtSwitch setState:[optValue intValue]];
774 /*Sub Me NSPopUpButton*/
775 if ([optName isEqualToString:@"subq"])
777 [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
779 /*Trellis NSPopUpButton*/
780 if ([optName isEqualToString:@"trellis"])
782 [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
784 /*Motion Estimation NSPopUpButton*/
785 if ([optName isEqualToString:@"me"])
787 if ([optValue isEqualToString:@"dia"])
788 [fX264optMotionEstPopUp selectItemAtIndex:1];
789 else if ([optValue isEqualToString:@"hex"])
790 [fX264optMotionEstPopUp selectItemAtIndex:2];
791 else if ([optValue isEqualToString:@"umh"])
792 [fX264optMotionEstPopUp selectItemAtIndex:3];
793 else if ([optValue isEqualToString:@"esa"])
794 [fX264optMotionEstPopUp selectItemAtIndex:4];
795 else if ([optValue isEqualToString:@"tesa"])
796 [fX264optMotionEstPopUp selectItemAtIndex:5];
798 /*ME Range NSPopUpButton*/
799 if ([optName isEqualToString:@"merange"])
801 [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
803 /* Adaptive B-Frames NSPopUpButton*/
804 if ([optName isEqualToString:@"b-adapt"])
806 [fX264optBAdaptPopUp selectItemAtIndex:[optValue intValue]+1];
808 /*B Pyramid NSPButton*/
809 if ([optName isEqualToString:@"b-pyramid"])
812 if( [optValue isEqualToString:@"normal"] )
814 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
815 [fX264optBPyramidPopUp selectItemAtIndex:0];
817 else if( [optValue isEqualToString:@"2"] )
819 [fX264optBPyramidPopUp selectItemAtIndex:0];
820 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
822 if( [optValue isEqualToString:@"strict"] )
824 [fX264optBPyramidPopUp selectItemAtIndex:2];
826 else if( [optValue isEqualToString:@"1"] )
828 [fX264optBPyramidPopUp selectItemAtIndex:2];
829 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
831 if( [optValue isEqualToString:@"none"] )
833 [fX264optBPyramidPopUp selectItemAtIndex:1];
835 else if( [optValue isEqualToString:@"0"] )
837 [fX264optBPyramidPopUp selectItemAtIndex:1];
838 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
841 /*Direct B-frame Prediction NSPopUpButton*/
842 if ([optName isEqualToString:@"direct"])
844 if ([optValue isEqualToString:@"none"])
845 [fX264optDirectPredPopUp selectItemAtIndex:1];
846 else if ([optValue isEqualToString:@"spatial"])
847 [fX264optDirectPredPopUp selectItemAtIndex:2];
848 else if ([optValue isEqualToString:@"temporal"])
849 [fX264optDirectPredPopUp selectItemAtIndex:3];
850 else if ([optValue isEqualToString:@"auto"])
851 [fX264optDirectPredPopUp selectItemAtIndex:4];
853 /*Deblocking NSPopUpButtons*/
854 if ([optName isEqualToString:@"deblock"])
856 NSString * alphaDeblock = @"";
857 NSString * betaDeblock = @"";
859 NSRange splitDeblock = [optValue rangeOfString:@","];
860 alphaDeblock = [optValue substringToIndex:splitDeblock.location];
861 betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
863 if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
865 /* When both filters are at 0, default */
866 [fX264optAlphaDeblockPopUp selectItemAtIndex:0];
867 [fX264optBetaDeblockPopUp selectItemAtIndex:0];
871 if (![alphaDeblock isEqualToString:@"0"])
873 /* Alpha isn't 0, so set it. The offset of 7 is
874 because filters start at -6 instead of at 0. */
875 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
879 /* Set alpha filter to 0, which is 7 up
880 because filters start at -6, not 0. */
881 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];
884 if (![betaDeblock isEqualToString:@"0"])
886 /* Beta isn't 0, so set it. */
887 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
891 /* Set beta filter to 0. */
892 [fX264optBetaDeblockPopUp selectItemAtIndex:7];
896 /* Analysis NSPopUpButton */
897 if ([optName isEqualToString:@"analyse"])
899 if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
901 /* Default ("most") */
902 [fX264optAnalysePopUp selectItemAtIndex:0];
904 else if ([optValue isEqualToString:@"i4x4,i8x8"] ||
905 [optValue isEqualToString:@"i8x8,i4x4"] )
908 [fX264optAnalysePopUp selectItemAtIndex:2];
910 else if ([optValue isEqualToString:@"none"])
912 [fX264optAnalysePopUp selectItemAtIndex:1];
914 else if ([optValue isEqualToString:@"all"])
916 [fX264optAnalysePopUp selectItemAtIndex:3];
920 /* 8x8 DCT NSButton */
921 if ([optName isEqualToString:@"8x8dct"])
923 [fX264opt8x8dctSwitch setState:[optValue intValue]];
926 if ([optName isEqualToString:@"cabac"])
928 [fX264optCabacSwitch setState:[optValue intValue]];
930 /* Adaptive Quantization Strength NSSlider */
931 if ([optName isEqualToString:@"aq-strength"])
933 [fX264optAqSlider setFloatValue:[optValue floatValue]];
935 /* Psy-RD and Psy-Trellis NSSliders */
936 if ([optName isEqualToString:@"psy-rd"])
938 NSString * rdOpt = @"";
939 NSString * trellisOpt = @"";
941 NSRange splitRD = [optValue rangeOfString:@","];
942 rdOpt = [optValue substringToIndex:splitRD.location];
943 trellisOpt = [optValue substringFromIndex:splitRD.location + 1];
945 [fX264optPsyRDSlider setFloatValue:[rdOpt floatValue]];
946 [fX264optPsyTrellisSlider setFloatValue:[trellisOpt floatValue]];
953 - (NSString *) X264AdvancedOptionsOptIDToString: (id) widget
955 /*Determine which outlet is being used and set optName to process accordingly */
956 NSString * optNameToChange = @""; // The option name such as "bframes"
958 if (widget == fX264optBframesPopUp)
960 optNameToChange = @"bframes";
962 if (widget == fX264optRefPopUp)
964 optNameToChange = @"ref";
966 if (widget == fX264optWeightPSwitch)
968 optNameToChange = @"weightp";
970 if (widget == fX264optNodctdcmtSwitch)
972 optNameToChange = @"no-dct-decimate";
974 if (widget == fX264optSubmePopUp)
976 optNameToChange = @"subq";
978 if (widget == fX264optTrellisPopUp)
980 optNameToChange = @"trellis";
982 if (widget == fX264optMotionEstPopUp)
984 optNameToChange = @"me";
986 if (widget == fX264optMERangePopUp)
988 optNameToChange = @"merange";
990 if (widget == fX264optBAdaptPopUp)
992 optNameToChange = @"b-adapt";
994 if (widget == fX264optBPyramidPopUp)
996 optNameToChange = @"b-pyramid";
998 if (widget == fX264optDirectPredPopUp)
1000 optNameToChange = @"direct";
1002 if (widget == fX264optAlphaDeblockPopUp)
1004 optNameToChange = @"deblock";
1006 if (widget == fX264optBetaDeblockPopUp)
1008 optNameToChange = @"deblock";
1010 if (widget == fX264optAnalysePopUp)
1012 optNameToChange = @"analyse";
1014 if (widget == fX264opt8x8dctSwitch)
1016 optNameToChange = @"8x8dct";
1018 if (widget == fX264optCabacSwitch)
1020 optNameToChange = @"cabac";
1022 if( widget == fX264optAqSlider)
1024 optNameToChange = @"aq-strength";
1026 if( widget == fX264optPsyRDSlider)
1028 optNameToChange = @"psy-rd";
1030 if( widget == fX264optPsyTrellisSlider)
1032 optNameToChange = @"psy-rd";
1035 return optNameToChange;
1038 - (NSString *) X264AdvancedOptionsWidgetToString: (NSString *) optName withID: (id) sender
1040 NSString * thisOpt = @""; // The option=value string the method will return
1042 if ([optName isEqualToString:@"deblock"])
1044 if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
1046 /* When both deblock widgets are 0 or default or a mix of the two,
1047 use a blank string, since deblocking defaults to 0,0. */
1052 /* Otherwise the format is deblock=a,b, where a and b both have an array
1053 offset of 7 because deblocking values start at -6 instead of at zero. */
1054 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
1058 else if ([optName isEqualToString:@"aq-strength"])
1060 if( [fX264optAqSlider floatValue] == 1.0 )
1062 /* When Aq is 1 it's the default value and can be ignored. */
1067 thisOpt = [NSString stringWithFormat:@"%@=%0.1f", optName, [fX264optAqSlider floatValue] ];
1071 else if ([optName isEqualToString:@"psy-rd"])
1073 if( [fX264optPsyRDSlider floatValue] == 1.0 && [fX264optPsyTrellisSlider floatValue] == 0.0 )
1075 /* When PsyRD is 1 and PsyTrel is 0 they're default values and can be ignored. */
1080 /* Otherwise the format is deblock=a,b, where a and b both have an array
1081 offset of 7 because deblocking values start at -6 instead of at zero. */
1082 thisOpt = [NSString stringWithFormat:@"%@=%0.1f,%0.2f", optName, [fX264optPsyRDSlider floatValue], [fX264optPsyTrellisSlider floatValue] ];
1086 else if /*Boolean Switches*/ ( [optName isEqualToString:@"no-dct-decimate"] )
1088 /* Here is where we take care of the boolean options that work overtly:
1089 no-dct-decimate being on means no-dct-decimate=1, etc. Some options
1090 require the inverse, but those will be handled a couple lines down. */
1091 if ([sender state] == 0)
1093 /* When these options are false, don't include them. They all default
1094 to being set off, so they don't need to be mentioned at all. */
1099 /* Otherwise, include them as optioname=1 */
1100 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
1104 else if ( [optName isEqualToString:@"8x8dct"] || [optName isEqualToString:@"cabac"] || [optName isEqualToString:@"weightp"] )
1106 /* These options default to being on. That means they
1107 only need to be included in the string when turned off. */
1108 if ([sender state] == 1)
1110 /* It's true so don't include it. */
1115 /* Otherwise, include cabac=0, etc, in the string. */
1116 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
1120 else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
1122 /* When a widget is at index 0, it's default. Default means don't add to the string.
1123 The exception for deblocking is because for those, *both* need to at index 0
1124 for it to default, so it's handled separately, above this section. */
1128 else if ([optName isEqualToString:@"me"])
1130 /* Motion estimation uses string values, so this switch
1131 pairs the widget index with the right value string. */
1132 switch ([sender indexOfSelectedItem])
1135 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
1139 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
1143 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
1147 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
1151 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"tesa"];
1158 else if ([optName isEqualToString:@"direct"])
1160 /* Direct prediction uses string values, so this switch
1161 pairs the right string value with the right widget index. */
1162 switch ([sender indexOfSelectedItem])
1165 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1169 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
1173 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
1177 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
1185 else if ([optName isEqualToString:@"analyse"])
1187 /* Analysis uses string values as well. */
1188 switch ([sender indexOfSelectedItem])
1191 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1194 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"i4x4,i8x8"];
1197 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
1205 else if ([optName isEqualToString:@"b-pyramid"])
1207 /* B-pyramid uses string values too. */
1208 switch ([sender indexOfSelectedItem])
1211 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1214 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"strict"];
1225 else if ([optName isEqualToString:@"merange"])
1227 /* Motion estimation range uses an odd array offset because in addition
1228 to starting with index 0 as default, index 1 starts at 4 instead of 1,
1229 because merange can't go below 4. So it has to be handled separately. */
1230 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
1233 else if ([optName isEqualToString:@"b-adapt"])
1235 /* B-adapt starts at index 0 with default then goes 0, 1, 2)*/
1236 thisOpt = [NSString stringWithFormat:@"%@=%d", optName, [sender indexOfSelectedItem]-1];
1239 else if ([optName isEqualToString:@"ref"])
1241 /* Refs use actual index numbers */
1242 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]];
1245 else // we have a valid value to change, so change it
1247 if ( [sender indexOfSelectedItem] != 0 )
1248 /* Here's our general case, that catches things like b-frames.
1249 Basically, any options that are PopUp menus with index 0 as default and
1250 index 1 as 0, with numerical values, are all handled right here. All of
1251 the above stuff is for the exceptions to the general case. */
1252 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
1258 - (BOOL) X264AdvancedOptionsIsOpt: (NSString *) optNameToChange inString: (NSString *) currentOptString
1260 /* If the option is in the string but not the beginning of it,
1261 it will be in the form of ":optName=value" so we really want
1262 to be looking for ":optNameToChange=" rather than "optNameToChange". */
1263 NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
1265 /* Now we store the part of the string up through the option name in currentOptRange. */
1266 NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
1268 /* We need to know if the option is at the beginning of the string.
1269 If it is at the start, it won't be preceded by a colon.
1270 To figure this out, we'll use the rangeOfString method. First,
1271 store what the option name would be if if it was at the beginning,
1272 in checkOptNameToChangeBeginning. Then, find its range in the string.
1273 If the range is 0, it's the first option listed in the string. */
1274 NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
1275 NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
1277 if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
1284 * Resets the option string to mirror the GUI widgets.
1286 - (IBAction) X264AdvancedOptionsChanged: (id) sender
1288 /* Look up the equivalent string option name of the calling widget. */
1289 NSString * optNameToChange = [self X264AdvancedOptionsOptIDToString: sender];
1291 NSString * thisOpt = @""; // The separated option such as "bframes=3"
1292 NSString * optName = @""; // The option name such as "bframes"
1293 NSString * optValue = @""; // The option value such as "3"
1294 NSArray *currentOptsArray;
1296 /* Get the current opt string being displayed. */
1297 NSString *currentOptString = [fDisplayX264Options stringValue];
1299 /* There are going to be a few possibilities.
1300 - The option might start off the string.
1301 - The option might be in the middle of the string.
1302 - The option might not be in the string at all yet.
1303 - The string itself might not yet exist. */
1305 if( [self X264AdvancedOptionsIsOpt: optNameToChange inString: currentOptString] )
1307 /* If the option is in the string wth a semicolon, or starts the string, it's time to edit.
1308 This means parsing the whole string into an array of options and values. From there,
1309 iterate through the options, and when you reach the one that's been changed, edit it. */
1311 /* Create new empty opt string*/
1312 NSString *changedOptString = @"";
1314 /* Put individual options into an array based on the ":"
1315 separator for processing, result is "<opt>=<value>" */
1316 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
1318 /* Iterate through the array and get <opts> and <values*/
1320 int currentOptsArrayCount = [currentOptsArray count];
1321 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
1323 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
1324 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
1326 if (splitOptRange.location != NSNotFound)
1328 /* First off, it's time to handle option strings that
1329 already have at least one option=value pair in them. */
1331 optName = [thisOpt substringToIndex:splitOptRange.location];
1332 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
1334 /*If the optNameToChange is found, appropriately change the value or delete it if
1335 "Unspecified" is set.*/
1336 if ([optName isEqualToString:optNameToChange])
1338 thisOpt = [self X264AdvancedOptionsWidgetToString: optName withID: sender];
1342 /* Construct New String for opts here */
1343 if ([thisOpt isEqualToString:@""])
1345 /* Blank option, so just add it to the string. (Why?) */
1346 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
1350 if ([changedOptString isEqualToString:@""])
1352 /* No existing string, make the string this option. */
1353 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
1357 /* Existing string, existing option. Append the
1358 option to the string, preceding it with a colon. */
1359 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
1364 /* Change the dislayed option string to reflect the new modified settings */
1365 [fDisplayX264Options setStringValue:changedOptString];
1367 else // if none exists, add it to the string
1369 /* This is where options that aren't already in the string are handled. */
1370 if ([[fDisplayX264Options stringValue] isEqualToString: @""])
1373 [fDisplayX264Options setStringValue:
1374 [self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender]];
1378 /* The string isn't empty, and the option isn't already in it, so
1379 it will need to be appended to the current string with a colon,
1380 as long as the string to be appended isn't just blank (default). */
1381 if( [[self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender] isEqualToString: @""] == false )
1383 [fDisplayX264Options setStringValue:
1384 [NSString stringWithFormat:@"%@:%@",
1386 [self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender] ]];
1391 /* We now need to reset the opt widgets since we changed some stuff */
1392 [self X264AdvancedOptionsSet:sender];