Skip to content

Commit

Permalink
encvt: add a new 'gpu-registryid' advanced option to force the usage …
Browse files Browse the repository at this point in the history
…of a specific gpu encoder.
  • Loading branch information
galad87 committed Dec 27, 2021
1 parent 0d44c5f commit 87aec08
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions libhb/platform/macosx/encvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct hb_work_private_s
struct hb_vt_param
{
CMVideoCodecType codec;
uint64_t registryID;

OSType pixelFormat;
int32_t timescale;

Expand Down Expand Up @@ -656,6 +658,15 @@ static int hb_vt_parse_options(hb_work_private_t *pv, hb_job_t *job)
pv->settings.maxFrameDelayCount = maxdelay;
}
}
else if (!strcmp(key, "gpu-registryid"))
{
uint64_t registryID = hb_value_get_int(value);
if (registryID > 0)
{
pv->settings.registryID = registryID;
}
}

}
hb_dict_free(&opts);

Expand Down Expand Up @@ -760,15 +771,27 @@ void hb_vt_compression_output_callback(
static OSStatus init_vtsession(hb_work_object_t *w, hb_job_t *job, hb_work_private_t *pv, int cookieOnly)
{
OSStatus err = noErr;
CFNumberRef cfValue = NULL;

CFMutableDictionaryRef encoderSpecifications = CFDictionaryCreateMutable(
kCFAllocatorDefault,
1,
2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);

CFDictionaryAddValue(encoderSpecifications, kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder, kCFBooleanTrue);

if (pv->settings.registryID > 0)
{
cfValue = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType,
&pv->settings.registryID);
if (__builtin_available(macOS 10.14, *))
{
CFDictionaryAddValue(encoderSpecifications, kVTVideoEncoderSpecification_RequiredEncoderGPURegistryID, cfValue);
}
CFRelease(cfValue);
}

CMSimpleQueueCreate(kCFAllocatorDefault, 200, &pv->queue);

err = VTCompressionSessionCreate(
Expand Down Expand Up @@ -833,8 +856,6 @@ static OSStatus init_vtsession(hb_work_object_t *w, hb_job_t *job, hb_work_priva

CFRelease(encoderSpecifications);

CFNumberRef cfValue = NULL;

// Offline encoders (such as Handbrake) should set RealTime property to False, as it disconnects the relationship
// between encoder speed and target video frame rate, explicitly setting RealTime to false encourages VideoToolbox
// to use the fastest mode, while adhering to the required output quality/bitrate and favorQualityOverSpeed settings
Expand Down

0 comments on commit 87aec08

Please sign in to comment.