Skip to content

Instantly share code, notes, and snippets.

@hisui
Created May 22, 2015 00:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisui/c93ab3d943fe38268bc3 to your computer and use it in GitHub Desktop.
Save hisui/c93ab3d943fe38268bc3 to your computer and use it in GitHub Desktop.
Checking if a given frame is a key frame.
static BOOL isKeyFrame(CMSampleBufferRef sample)
{
auto a = CMSampleBufferGetSampleAttachmentsArray(sample, 0);
if (CFArrayGetCount(a) > 0) {
CFBooleanRef value;
auto b = CFDictionaryGetValueIfPresent
((CFDictionaryRef) CFArrayGetValueAtIndex(a, 0)
, kCMSampleAttachmentKey_NotSync
, reinterpret_cast<const void **>(&value))
;
return !b || !CFBooleanGetValue(value);
}
return false;
}
@macfanr
Copy link

macfanr commented Apr 2, 2022

ObjC:

static BOOL isKeyFrame(CMSampleBufferRef sample)
{
CFArrayRef a = CMSampleBufferGetSampleAttachmentsArray(sample, 0);
if (a && CFArrayGetCount(a) > 0) {
CFBooleanRef value;
Boolean b = CFDictionaryGetValueIfPresent((CFDictionaryRef) CFArrayGetValueAtIndex(a, 0), kCMSampleAttachmentKey_NotSync, (const void **)(&value));

    return !b || !CFBooleanGetValue(value);
}
return false;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment