Retrieving movie codec under iOS?

前端 未结 4 1802
别那么骄傲
别那么骄傲 2020-12-31 21:18

I am trying to find the codec used to compress a movie. I am sure if I need to somehow use CMFormatDescription and get a CMVideoCodecType key. I am stuck as to how to get pa

4条回答
  •  余生分开走
    2020-12-31 22:20

    I think it's definitely harder than it should be

        #define FourCC2Str(code) (char[5]){(code >> 24) & 0xFF, (code >> 16) & 0xFF, (code >> 8) & 0xFF, code & 0xFF, 0}
    
        if ([assetTrack.mediaType isEqualToString:AVMediaTypeVideo])
        {
            for (id formatDescription in assetTrack.formatDescriptions)
            {
                NSLog(@"formatDescription:  %@", formatDescription);
    
                CMFormatDescriptionRef desc = (__bridge CMFormatDescriptionRef)formatDescription;
                //CMMediaType mediaType = CMFormatDescriptionGetMediaType(desc);
    
                // CMVideoCodecType is typedefed to CMVideoCodecType
    
                CMVideoCodecType codec = CMFormatDescriptionGetMediaSubType(desc);
    
                NSString* codecString = [NSString stringWithCString:(const char *)FourCC2Str(codec) encoding:NSUTF8StringEncoding];
                NSLog(@"%@", codecString);
    
            }
        }
    

提交回复
热议问题