diff options
author | Rodeo <[email protected]> | 2013-07-13 18:16:00 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2013-07-13 18:16:00 +0000 |
commit | 8228a6411ed3c76d521dc398ddb5329154786f43 (patch) | |
tree | f6314fa9a64726b5c5cd1c781d46725456145b27 | |
parent | 00b5d615c59958cb0078a6d3d8a126337335b734 (diff) |
Add hb_video_quality_get_limits and hb_video_quality_get_name to libhb API.
Includes a MacGui implementation.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5647 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/common.c | 49 | ||||
-rw-r--r-- | libhb/common.h | 3 | ||||
-rw-r--r-- | libhb/work.c | 5 | ||||
-rw-r--r-- | macosx/Controller.m | 125 |
4 files changed, 129 insertions, 53 deletions
diff --git a/libhb/common.c b/libhb/common.c index 18302e3b8..3eaa941b3 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -1087,6 +1087,55 @@ const hb_rate_t* hb_audio_bitrate_get_next(const hb_rate_t *last) // // direction says whether 'low' limit is highest or lowest // quality (direction 0 == lowest value is worst quality) +void hb_video_quality_get_limits(uint32_t codec, float *low, float *high, + float *granularity, int *direction) +{ + switch (codec) + { + case HB_VCODEC_X264: + *direction = 1; + *granularity = 0.1; + *low = 0.; + *high = 51.; + break; + + case HB_VCODEC_THEORA: + *direction = 0; + *granularity = 1.; + *low = 0.; + *high = 63.; + break; + + case HB_VCODEC_FFMPEG_MPEG2: + case HB_VCODEC_FFMPEG_MPEG4: + default: + *direction = 1; + *granularity = 1.; + *low = 1.; + *high = 31.; + break; + } +} + +const char* hb_video_quality_get_name(uint32_t codec) +{ + switch (codec) + { + case HB_VCODEC_X264: + return "RF"; + + default: + return "QP"; + } +} + +// Get limits and hints for the UIs. +// +// granularity sets the minimum step increments that should be used +// (it's ok to round up to some nice multiple if you like) +// +// direction says whether 'low' limit is highest or lowest +// quality (direction 0 == lowest value is worst quality) void hb_audio_quality_get_limits(uint32_t codec, float *low, float *high, float *granularity, int *direction) { diff --git a/libhb/common.h b/libhb/common.h index 2ce180034..5a21eab84 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -264,6 +264,9 @@ int hb_audio_bitrate_get_default(uint32_t codec, int samplerate, in void hb_audio_bitrate_get_limits(uint32_t codec, int samplerate, int mixdown, int *low, int *high); const hb_rate_t* hb_audio_bitrate_get_next(const hb_rate_t *last); +void hb_video_quality_get_limits(uint32_t codec, float *low, float *high, float *granularity, int *direction); +const char* hb_video_quality_get_name(uint32_t codec); + void hb_audio_quality_get_limits(uint32_t codec, float *low, float *high, float *granularity, int *direction); float hb_audio_quality_get_best(uint32_t codec, float quality); float hb_audio_quality_get_default(uint32_t codec); diff --git a/libhb/work.c b/libhb/work.c index 433e9c5c3..b23a3619a 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -318,9 +318,10 @@ void hb_display_job_info(hb_job_t *job) hb_log( " + h264 level: %s", job->h264_level ); } - if( job->vquality >= 0 ) + if (job->vquality >= 0) { - hb_log( " + quality: %.2f %s", job->vquality, job->vcodec == HB_VCODEC_X264 ? "(RF)" : "(QP)" ); + hb_log(" + quality: %.2f (%s)", job->vquality, + hb_video_quality_get_name(job->vcodec)); } else { diff --git a/macosx/Controller.m b/macosx/Controller.m index 80dba2a9d..ad2c61814 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -3062,15 +3062,23 @@ fWorkingCount = 0; [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]]; - if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA) + int direction; + float minValue, maxValue, granularity; + hb_video_quality_get_limits([[fVidEncoderPopUp selectedItem] tag], + &minValue, &maxValue, &granularity, &direction); + if (!direction) { - /* Since theora's qp value goes up from left to right, we can just set the slider float value */ [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]]; } else { - /* Since ffmpeg and x264 use an "inverted" slider (lower qp/rf values indicate a higher quality) we invert the value on the slider */ - [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] + [fVidQualitySlider minValue]) - [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]]; + /* + * Since ffmpeg and x264 use an "inverted" slider (lower values + * indicate a higher quality) we invert the value on the slider + */ + [fVidQualitySlider setFloatValue:([fVidQualitySlider minValue] + + [fVidQualitySlider maxValue] - + [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue])]; } [self videoMatrixChanged:nil]; @@ -5260,43 +5268,44 @@ the user is using "Custom" settings by determining the sender*/ */ - (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 */ + /* + * 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)); + [fVidQualityRFLabel setStringValue:[NSString stringWithFormat:@"%s", + hb_video_quality_get_name([[fVidEncoderPopUp + selectedItem] tag])]]; + int direction; + float minValue, maxValue, granularity; + hb_video_quality_get_limits([[fVidEncoderPopUp selectedItem] tag], + &minValue, &maxValue, &granularity, &direction); 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]; - qpRFLabelString = @"RF:"; - } - /* FFmpeg MPEG-2/4 1-31 */ - if ([[fVidEncoderPopUp selectedItem] tag] & HB_VCODEC_FFMPEG_MASK ) - { - [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]; + /* + * As x264 allows for qp/rf values that are fractional, + * we get the value from the preferences + */ + granularity = [[NSUserDefaults standardUserDefaults] + floatForKey:@"x264CqSliderFractional"]; } - [fVidQualityRFLabel setStringValue:qpRFLabelString]; + [fVidQualitySlider setMinValue:minValue]; + [fVidQualitySlider setMaxValue:maxValue]; + [fVidQualitySlider setNumberOfTickMarks:((maxValue - minValue) * + (1. / granularity)) + 1]; /* check to see if we have changed slider scales */ - if (previousMaxValue != [fVidQualitySlider maxValue]) + if (previousMaxValue != 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]; + /* + * if so, convert the old setting to the new scale as close as possible + * based on percentages + */ + [fVidQualitySlider setFloatValue:((maxValue - minValue + 1.) * + (previousPercentOfSliderScale))]; } [self qualitySliderChanged:nil]; @@ -5304,8 +5313,8 @@ the user is using "Custom" settings by determining the sender*/ - (IBAction) qualitySliderChanged: (id) sender { - - /* Our constant quality slider is in a range based + /* + * 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 * for all of the encoders *except* for theora @@ -5317,22 +5326,28 @@ the user is using "Custom" settings by determining the sender*/ * 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]; - /* If the encoder is theora, use the float, otherwise use the inverse float*/ - //float sliderRfToPercent; - if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA) - { - [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", [fVidQualitySlider floatValue]]]; + int direction; + float minValue, maxValue, granularity; + float inverseValue = ([fVidQualitySlider minValue] + + [fVidQualitySlider maxValue] - + [fVidQualitySlider floatValue]); + hb_video_quality_get_limits([[fVidEncoderPopUp selectedItem] tag], + &minValue, &maxValue, &granularity, &direction); + if (!direction) + { + [fVidQualityRFField setStringValue:[NSString stringWithFormat:@"%.2f", + [fVidQualitySlider floatValue]]]; } else { - [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", sliderRfInverse]]; + [fVidQualityRFField setStringValue:[NSString stringWithFormat:@"%.2f", + inverseValue]]; } /* Show a warning if x264 and rf 0 which is lossless */ - if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264 && sliderRfInverse == 0.0) + if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264 && inverseValue == 0.0) { - [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f (Warning: Lossless)", sliderRfInverse]]; + [fVidQualityRFField setStringValue:[NSString stringWithFormat:@"%.2f (Warning: Lossless)", + inverseValue]]; } [self customSettingUsed: sender]; @@ -6544,15 +6559,23 @@ return YES; [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]]; - if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA) + int direction; + float minValue, maxValue, granularity; + hb_video_quality_get_limits([[fVidEncoderPopUp selectedItem] tag], + &minValue, &maxValue, &granularity, &direction); + if (!direction) { - /* Since theora's qp value goes up from left to right, we can just set the slider float value */ [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]]; } else { - /* Since ffmpeg and x264 use an "inverted" slider (lower qp/rf values indicate a higher quality) we invert the value on the slider */ - [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] + [fVidQualitySlider minValue]) - [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]]; + /* + * Since ffmpeg and x264 use an "inverted" slider (lower values + * indicate a higher quality) we invert the value on the slider + */ + [fVidQualitySlider setFloatValue:([fVidQualitySlider minValue] + + [fVidQualitySlider maxValue] - + [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue])]; } [self videoMatrixChanged:nil]; |