From a0ae27ea704a01f788c2137a45c5732081604d6a Mon Sep 17 00:00:00 2001 From: dynaflash Date: Tue, 10 Feb 2009 22:31:26 +0000 Subject: [PATCH] MacGui: Constant Quality Slider now QP/RF based. - Constant Quality Slider now uses QP/RF values instead of the long maligned % scale. - Nearest percentage is also shown for reference. -- For reference, PercentRFConversion on the wiki is a table of corresponding values for the old and new scales. - Slider changes scale base on the chosen encoder. -- x264: 0-51 -- FFmpeg and Xvid: 1-31 -- Theora: 0-63 - x264 Specific - Slider allows for fractional granularity (other encoders just whole ints). -- Advanced Preference to adjust the granularity from 1.0,0.50,0.33,0.25,0.20 with a default of 0.25. - Existing presets using the % based values converted to the nearest QP/RF value (within the granularity of the slider). -- Example: A current preset using x264 at 62% will now actually use 61.76% since the nearest RF value converted to 62% is 19.50 with the slider set to 0.25 granularity. -- New presets created will store the QP/RF value instead of the % value. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2135 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/Controller.h | 4 + macosx/Controller.mm | 102 ++++++++++- macosx/English.lproj/MainMenu.xib | 168 +++++++++++++----- macosx/English.lproj/Preferences.xib | 248 +++++++++++++++++++++++++-- macosx/HBPreferencesController.m | 1 + macosx/HBQueueController.mm | 2 +- 6 files changed, 459 insertions(+), 66 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index e77aa9ad1..c9118c023 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -99,6 +99,8 @@ BOOL fIsDragging; IBOutlet NSTextField * fVidEncoderField; IBOutlet NSPopUpButton * fVidEncoderPopUp; IBOutlet NSTextField * fVidQualityField; + IBOutlet NSTextField * fVidQualityRFLabel; + IBOutlet NSTextField * fVidQualityRFField; IBOutlet NSMatrix * fVidQualityMatrix; IBOutlet NSButtonCell * fVidTargetCell; IBOutlet NSTextField * fVidTargetSizeField; @@ -288,6 +290,8 @@ BOOL fIsDragging; - (IBAction) videoMatrixChanged: (id) sender; - (IBAction) qualitySliderChanged: (id) sender; +- (void) setupQualitySlider; + - (IBAction) audioDRCSliderChanged: (id) sender; - (IBAction) showPicturePanel: (id) sender; diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 7ab9aac22..13cc8745b 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -433,7 +433,7 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField, fQueueStatus,fPresetsAdd,fPresetsDelete, fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fSubForcedCheck,fPresetsOutlineView, - fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck}; + fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck,fVidQualityRFField,fVidQualityRFLabel}; for( unsigned i = 0; i < sizeof( controls ) / sizeof( NSControl * ); i++ ) @@ -1888,7 +1888,7 @@ fWorkingCount = 0; [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"]; [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"]; [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"]; - [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"]; + [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"]; /* Framerate */ [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"]; @@ -2686,7 +2686,7 @@ fWorkingCount = 0; job->vbitrate = [fVidBitrateField intValue]; break; case 2: - job->vquality = [fVidQualitySlider floatValue]; + job->vquality = [fVidQualityRFField floatValue]; job->vbitrate = 0; break; } @@ -3942,7 +3942,7 @@ the user is using "Custom" settings by determining the sender*/ [fPictureController setAllowLooseAnamorphic:YES]; [fDstMp4iPodFileCheck setEnabled: YES]; } - + [self setupQualitySlider]; [self calculatePictureSizing: sender]; [self twoPassCheckboxChanged: sender]; } @@ -4009,6 +4009,8 @@ the user is using "Custom" settings by determining the sender*/ [fVidTargetSizeField setEnabled: target]; [fVidBitrateField setEnabled: bitrate]; [fVidQualitySlider setEnabled: quality]; + [fVidQualityRFField setEnabled: quality]; + [fVidQualityRFLabel setEnabled: quality]; [fVidTwoPassCheck setEnabled: !quality && [fVidQualityMatrix isEnabled]]; if( quality ) @@ -4023,11 +4025,77 @@ the user is using "Custom" settings by determining the sender*/ [self customSettingUsed: sender]; } +/* Use this method to setup the quality slider for cq/rf values depending on + * the video encoder selected. + */ +- (void) setupQualitySlider +{ + /* Get the current slider maxValue to check for a change in slider scale later + * so that we can choose a new similar value on the new slider scale */ + float previousMaxValue = [fVidQualitySlider maxValue]; + float previousPercentOfSliderScale = [fVidQualitySlider floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1); + NSString * qpRFLabelString = @"QP:"; + /* x264 0-51 */ + if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264) + { + [fVidQualitySlider setMinValue:0.0]; + [fVidQualitySlider setMaxValue:51.0]; + /* As x264 allows for qp/rf values that are fractional, we get the value from the preferences */ + int fractionalGranularity = 1 / [[NSUserDefaults standardUserDefaults] floatForKey:@"x264CqSliderFractional"]; + [fVidQualitySlider setNumberOfTickMarks:(([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * fractionalGranularity) + 1]; + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0) + { + qpRFLabelString = @"RF:"; + } + } + /* ffmpeg and xvid 1-31 */ + if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_FFMPEG || [[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_XVID) + { + [fVidQualitySlider setMinValue:1.0]; + [fVidQualitySlider setMaxValue:31.0]; + [fVidQualitySlider setNumberOfTickMarks:31]; + } + /* Theora 0-63 */ + if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA) + { + [fVidQualitySlider setMinValue:0.0]; + [fVidQualitySlider setMaxValue:63.0]; + [fVidQualitySlider setNumberOfTickMarks:64]; + } + [fVidQualityRFLabel setStringValue:qpRFLabelString]; + + /* check to see if we have changed slider scales */ + if (previousMaxValue != [fVidQualitySlider maxValue]) + { + /* if so, convert the old setting to the new scale as close as possible based on percentages */ + float rf = ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1) * previousPercentOfSliderScale; + [fVidQualitySlider setFloatValue:rf]; + } + + [self qualitySliderChanged:nil]; +} + - (IBAction) qualitySliderChanged: (id) sender { - [fVidConstantCell setTitle: [NSString stringWithFormat: - NSLocalizedString( @"Constant quality: %.0f %%", @"" ), 100.0 * - [fVidQualitySlider floatValue]]]; + /* Our constant quality slider is in a range based + * on each encoders qp/rf values. The range depends + * on the encoder. Also, the range is inverse of quality + * (ie. as the "quality" goes up, the cq or rf value + * actually goes down). Since the IB sliders always set + * their max value at the right end of the slider, we + * will calculate the inverse, so as the slider floatValue + * goes up, we will show the inverse in the rf field + * so, the floatValue at the right for x264 would be 51 + * and our rf field needs to show 0 and vice versa. + */ + + float sliderRfInverse = ([fVidQualitySlider maxValue] - [fVidQualitySlider floatValue]) + [fVidQualitySlider minValue]; + [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", sliderRfInverse]]; + + float sliderRfToPercent = ( [fVidQualitySlider maxValue] - sliderRfInverse ) / [fVidQualitySlider maxValue]; + [fVidConstantCell setTitle: [NSString stringWithFormat: + NSLocalizedString( @"Constant quality: %.2f %%", @"" ), 100 * sliderRfToPercent]]; + [self customSettingUsed: sender]; } @@ -5603,7 +5671,23 @@ return YES; [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]]; [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]]; - [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]]; + + /* Since we are now using RF Values for the slider, we detect if the preset uses an old quality float. + * So, check to see if the quality value is less than 1.0 which should indicate the old ".062" type + * quality preset. Caveat: in the case of x264, where the RF scale starts at 0, it would misinterpret + * a preset that uses 0.0 - 0.99 for RF as an old style preset. Not sure how to get around that one yet, + * though it should be a corner case since it would pretty much be a preset for lossless encoding. */ + if ([[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue] < 1.0) + { + /* For the quality slider we need to convert the old percent's to the new rf scales */ + float rf = (([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]); + [fVidQualitySlider setFloatValue:rf]; + + } + else + { + [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) - [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]]; + } [self videoMatrixChanged:nil]; @@ -6097,7 +6181,7 @@ return YES; [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"]; [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"]; [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"]; - [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"]; + [preset setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"]; /* Video framerate */ if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index 79a4a784b..079399ebc 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -108,14 +108,14 @@ 1 - + 256 YES 256 - {{357, 259}, {46, 14}} + {{289, 259}, {46, 14}} YES @@ -131,7 +131,7 @@ 256 - {{411, 211}, {146, 63}} + {{343, 211}, {167, 63}} YES 3 @@ -186,7 +186,7 @@ 75 - {146, 15} + {167, 15} {4, 9} 1143472128 NSActionCell @@ -216,7 +216,7 @@ 256 - {{562, 257}, {84, 19}} + {{512, 257}, {84, 19}} YES @@ -243,7 +243,7 @@ 256 - {{562, 233}, {84, 19}} + {{512, 233}, {84, 19}} YES @@ -260,26 +260,26 @@ 256 - {{433, 185}, {213, 18}} + {{292, 186}, {405, 16}} YES 67501824 - 131072 + 262144 - - Helvetica-Oblique - 1.200000e+01 - 16 + + LucidaGrande + 9.000000e+00 + 3614 - 1.000000e+00 + 5.100000e+01 0.000000e+00 - 5.400000e-01 + 1.900000e+01 0.000000e+00 - 101 + 205 1 YES NO @@ -301,6 +301,38 @@ + + + 256 + {{538, 211}, {38, 14}} + + YES + + 67239424 + 4325376 + + + + + + + + + + 256 + {{509, 211}, {28, 14}} + + YES + + 67239424 + 71434240 + RF: + + + + + + 256 @@ -336,7 +368,7 @@ 256 - {{123, 229}, {168, 22}} + {{106, 229}, {149, 22}} YES @@ -390,7 +422,7 @@ 256 - {{123, 208}, {124, 18}} + {{106, 208}, {124, 18}} YES @@ -413,7 +445,7 @@ 256 - {{140, 190}, {107, 16}} + {{123, 190}, {107, 16}} YES @@ -438,7 +470,7 @@ 256 - {{123, 254}, {168, 22}} + {{106, 254}, {149, 22}} YES @@ -486,7 +518,7 @@ 256 - {{11, 231}, {107, 17}} + {{9, 231}, {92, 17}} YES @@ -502,7 +534,7 @@ 256 - {{11, 256}, {107, 17}} + {{14, 256}, {87, 17}} YES @@ -517,6 +549,7 @@ {{10, 25}, {714, 305}} + Video @@ -525,7 +558,7 @@ 2 - + 256 YES @@ -628,11 +661,7 @@ 67239424 138674176 Bitrate (kbps) - - LucidaGrande - 9.000000e+00 - 3614 - + @@ -2013,7 +2042,6 @@ {{10, 25}, {714, 305}} - QXVkaW8gJiBTdWJ0aXRsZXM @@ -2280,14 +2308,14 @@ - + 134217728 YES YES YES - + @@ -6052,6 +6080,22 @@ 5173 + + + fVidQualityRFField + + + + 5176 + + + + fVidQualityRFLabel + + + + 5179 + @@ -6394,11 +6438,6 @@ YES - - - - - @@ -6408,6 +6447,13 @@ + + + + + + + @@ -9152,6 +9198,34 @@ + + 5174 + + + YES + + + + + + 5175 + + + + + 5177 + + + YES + + + + + + 5178 + + + @@ -9883,6 +9957,12 @@ 5171.IBPluginDependency 5171.ImportedFromIB2 5172.IBPluginDependency + 5174.IBPluginDependency + 5174.ImportedFromIB2 + 5175.IBPluginDependency + 5177.IBPluginDependency + 5177.ImportedFromIB2 + 5178.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBPluginDependency @@ -10238,9 +10318,9 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{255, 306}, {760, 550}} + {{248, 306}, {760, 550}} - {{255, 306}, {760, 550}} + {{248, 306}, {760, 550}} {{65, 541}, {760, 550}} @@ -10655,6 +10735,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin {{75, 683}, {235, 153}} com.apple.InterfaceBuilder.CocoaPlugin @@ -10687,7 +10773,7 @@ - 5173 + 5179 @@ -10904,6 +10990,8 @@ fVidEncoderPopUp fVidQualityField fVidQualityMatrix + fVidQualityRFField + fVidQualityRFLabel fVidQualitySlider fVidRateField fVidRatePopUp @@ -11008,6 +11096,8 @@ NSPopUpButton NSTextField NSMatrix + NSTextField + NSTextField NSSlider NSTextField NSPopUpButton diff --git a/macosx/English.lproj/Preferences.xib b/macosx/English.lproj/Preferences.xib index d96c12561..5359deeac 100644 --- a/macosx/English.lproj/Preferences.xib +++ b/macosx/English.lproj/Preferences.xib @@ -9,7 +9,7 @@ YES - + YES @@ -61,7 +61,7 @@ YES - + 256 YES @@ -447,7 +447,6 @@ {492, 231} - NSView NSControl @@ -796,14 +795,14 @@ NSResponder - + 256 YES 256 - {{84, 118}, {367, 18}} + {{84, 156}, {367, 18}} YES @@ -824,7 +823,7 @@ 256 - {{40, 119}, {41, 17}} + {{40, 157}, {41, 17}} YES @@ -837,10 +836,26 @@ + + + 256 + {{83, 134}, {301, 17}} + + YES + + 67239424 + 71303168 + Constant Quality fractional granularity: + + + + + + 256 - {{37, 87}, {239, 17}} + {{37, 101}, {239, 17}} YES @@ -856,7 +871,7 @@ 256 - {{71, 27}, {184, 17}} + {{71, 41}, {184, 17}} YES @@ -872,7 +887,7 @@ 256 - {{37, 51}, {32, 17}} + {{37, 65}, {32, 17}} YES @@ -888,7 +903,7 @@ 256 - {{72, 49}, {367, 18}} + {{72, 63}, {367, 18}} YES @@ -909,7 +924,7 @@ 268 - {{276, 82}, {66, 22}} + {{276, 96}, {66, 22}} YES @@ -995,10 +1010,96 @@ 2 + + + 268 + {{386, 129}, {66, 22}} + + YES + + -2076049856 + 133120 + + + 109199615 + 129 + + + 400 + 75 + + + 0.25 + + 2147483647 + 1 + + + _popUpItemAction: + + + YES + + OtherViews + + YES + + + 1.0 + + 1048576 + 2147483647 + + + _popUpItemAction: + + + + + 0.50 + + 1048576 + 2147483647 + + + _popUpItemAction: + + + + + 0.33 + + 1048576 + 2147483647 + + + _popUpItemAction: + + + + + + 0.20 + + 2147483647 + + + _popUpItemAction: + + + + + 3 + 1 + YES + YES + 2 + + 268 - {{255, 22}, {66, 22}} + {{255, 36}, {66, 22}} YES @@ -1062,7 +1163,8 @@ - {482, 156} + {481, 194} + NSView @@ -1328,6 +1430,22 @@ 386 + + + selectedValue: values.x264CqSliderFractional + + + + + + selectedValue: values.x264CqSliderFractional + selectedValue + values.x264CqSliderFractional + 2 + + + 397 + @@ -1536,6 +1654,8 @@ + + Advanced @@ -1910,6 +2030,76 @@ + + 387 + + + YES + + + + + + 388 + + + YES + + + + + + 389 + + + YES + + + + + + + + + + 390 + + + + + 391 + + + + + 392 + + + + + 393 + + + + + 394 + + + + + 395 + + + YES + + + + + + 396 + + + @@ -2036,6 +2226,18 @@ 383.IBPluginDependency 383.ImportedFromIB2 384.IBPluginDependency + 387.IBPluginDependency + 388.IBPluginDependency + 389.IBEditorWindowLastContentRect + 389.IBPluginDependency + 390.IBPluginDependency + 391.IBPluginDependency + 392.IBPluginDependency + 393.IBPluginDependency + 394.IBPluginDependency + 395.IBPluginDependency + 395.ImportedFromIB2 + 396.IBPluginDependency 5.IBEditorWindowLastContentRect 5.IBWindowTemplateEditedContentRect 5.ImportedFromIB2 @@ -2064,7 +2266,7 @@ {{73, 774}, {500, 82}} com.apple.InterfaceBuilder.CocoaPlugin - {{349, 493}, {482, 156}} + {{404, 579}, {481, 194}} com.apple.InterfaceBuilder.CocoaPlugin {{0, 650}, {500, 184}} @@ -2170,8 +2372,20 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{69, 784}, {500, 200}} - {{69, 784}, {500, 200}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{779, 642}, {88, 88}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + {{69, 656}, {500, 200}} + {{69, 656}, {500, 200}} @@ -2203,7 +2417,7 @@ - 386 + 397 diff --git a/macosx/HBPreferencesController.m b/macosx/HBPreferencesController.m index ca80223c8..e82bfd0ab 100644 --- a/macosx/HBPreferencesController.m +++ b/macosx/HBPreferencesController.m @@ -58,6 +58,7 @@ @"NO", @"EncodeLogLocation", @"10", @"PreviewsNumber", @"", @"Drawer Size", + @"0.25", @"x264CqSliderFractional", nil]]; } diff --git a/macosx/HBQueueController.mm b/macosx/HBQueueController.mm index e530180b3..822c3124f 100644 --- a/macosx/HBQueueController.mm +++ b/macosx/HBQueueController.mm @@ -1166,7 +1166,7 @@ return ![(HBQueueOutlineView*)outlineView isDragging]; } else // CRF { - videoInfo = [NSString stringWithFormat:@"%@ Constant Quality: %.0f %%", videoInfo ,[[item objectForKey:@"VideoQualitySlider"] floatValue] * 100]; + videoInfo = [NSString stringWithFormat:@"%@ Constant Quality: %.2f", videoInfo ,[[item objectForKey:@"VideoQualitySlider"] floatValue]]; } [finalString appendString: @"Video: " withAttributes:detailBoldAttr]; -- 2.40.0