mpoullet icon

CMVideoFormatDescriptionCreateFromH264ParameterSets

mpoullet | PRO | 03/03/17 12:58:54 PM UTC | 0 ⭐ | 7644 👁️ | Never ⏰ | []
Objective C |

0 B

|

None

|

0 👍

/

0 👎

// clang CMVideoFormatDescriptionCreateFromH264ParameterSets.m -std=c11 -Wall -Wextra -fobjc-arc -fmodules -o CMVideoFormatDescriptionCreateFromH264ParameterSets
 
@import CoreMedia;
 
#define PARAMETERSETCOUNT 2
#define SPSIDX 0
#define PPSIDX 1
 
OSStatus formatCreate(const uint8_t sps[], size_t sps_size, const uint8_t pps[], size_t pps_size, CMVideoFormatDescriptionRef *formatDescription)
{
    const uint8_t* parameterSetPointers[PARAMETERSETCOUNT];
    parameterSetPointers[SPSIDX] = sps;
    parameterSetPointers[PPSIDX] = pps;
    size_t parameterSetSizes[PARAMETERSETCOUNT];
    parameterSetSizes[SPSIDX] = sps_size;
    parameterSetSizes[PPSIDX] = pps_size;
 
    printf("SPS length = %zu\n", parameterSetSizes[SPSIDX]);
    for(size_t i=0;i<parameterSetSizes[SPSIDX];i++) printf("0x%02x\n", *(parameterSetPointers[SPSIDX] + i));
 
    printf("PPS length = %zu\n", parameterSetSizes[PPSIDX]);
    for(size_t i=0;i<parameterSetSizes[PPSIDX];i++) printf("0x%02x\n", *(parameterSetPointers[PPSIDX] + i));
 
    const size_t parameterSetCount = PARAMETERSETCOUNT;
    const int NALUnitHeaderLength = 4;
    return CMVideoFormatDescriptionCreateFromH264ParameterSets(NULL,
                                                               parameterSetCount,
                                                               parameterSetPointers,
                                                               parameterSetSizes,
                                                               NALUnitHeaderLength,
                                                               formatDescription);
}
 
void printFormatDescription(CMVideoFormatDescriptionRef formatDescription)
{
    CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
    CGRect cleanAperture = CMVideoFormatDescriptionGetCleanAperture(formatDescription, true);
    CGSize presentationDimensions = CMVideoFormatDescriptionGetPresentationDimensions(formatDescription, true, true);
    printf("dimensions=%dx%d\ncleanAperture=%fx%f\npresentationDimensions=%fx%f\n",
            dimensions.width,
            dimensions.height,
            cleanAperture.size.width,
            cleanAperture.size.height,
            presentationDimensions.width,
            presentationDimensions.height);
}
 
int main(void)
{
    // SD 576i
    const uint8_t sps_576i[] = {
                               0x67,
                               0x64,
                               0x00,
                               0x1e,
                               0xac,
                               0x34,
                               0xa5,
                               0x02,
                               0xd0,
                               0x91,
                               0x60,
                               0x88,
                               0x41,
                               0x41,
                               0x41,
                               0x50,
                               0x00,
                               0x00,
                               0x00,
                               0x10,
                               0x00,
                               0x00,
                               0x03,
                               0x29,
                               0xda,
                               0x1a,
                               0x2d,
                               0x96
    };
    const uint8_t pps_576i[] = {
                               0x68,
                               0xe8,
                               0x81,
                               0x17,
                               0x52,
                               0x50
    };
 
    // HD 720p
    const uint8_t sps_720p[] = {
                               0x67,
                               0x64,
                               0x00,
                               0x28,
                               0xac,
                               0x34,
                               0xa5,
                               0x01,
                               0x40,
                               0x16,
                               0xec,
                               0x05,
                               0x08,
                               0x08,
                               0x08,
                               0x0a,
                               0x00,
                               0x00,
                               0x00,
                               0x02,
                               0x00,
                               0x00,
                               0x00,
                               0xc9,
                               0x3b,
                               0x43,
                               0x86,
                               0x14,
                               0xb0
    };
    const uint8_t pps_720p[] = {
                               0x68,
                               0xe9,
                               0x09,
                               0x75,
                               0x25
    };
 
 
    CMVideoFormatDescriptionRef formatDescription720p;
    OSStatus formatCreateResult720p = formatCreate(sps_720p, sizeof(sps_720p), pps_720p, sizeof(pps_720p), &formatDescription720p);
    printf("formatCreateResult720p = %d\n", formatCreateResult720p);
    if (formatCreateResult720p == noErr) printFormatDescription(formatDescription720p);
 
    CMVideoFormatDescriptionRef formatDescription576i;
    OSStatus formatCreateResult576i = formatCreate(sps_576i, sizeof(sps_576i), pps_576i, sizeof(pps_576i), &formatDescription576i);
    printf("formatCreateResult576i = %d\n", formatCreateResult576i);
    if (formatCreateResult576i == noErr) printFormatDescription(formatDescription576i);
 
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎