2012-06-25 32 views
5

मैं एक फिल्म को संपीड़ित करने के लिए इस्तेमाल कोडेक खोजने की कोशिश कर रहा हूं। मुझे यकीन है कि अगर मुझे किसी भी तरह से CMFormatDescription का उपयोग करने की आवश्यकता है और एक CMVideoCodecType कुंजी प्राप्त करें। मैं मेटाडाटा सरणी को कैसे प्राप्त करना है, इस बारे में अटक गया हूं। कोडेक को पुनः प्राप्त करने के तरीके पर कोई विचार?आईओएस के तहत मूवी कोडेक पुनर्प्राप्त करना?

AVURLAsset* movieAsset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil]; 
NSArray *tracks = [movieAsset tracksWithMediaType:AVMediaTypeVideo]; 

if ([tracks count] != 0) { 
    AVAssetTrack *videoTrack = [tracks objectAtIndex:0]; 

    // 
    // Let's get the movie's meta data 
    // 

    // Find the codec 
    NSArray *metadata = [movieAsset commonMetadata]; 
} 
+0

आप इस एक के लिए एक समाधान मिल गया है? – vale4674

उत्तर

3

मुझे लगता है कि यह निश्चित रूप से कठिन है की तुलना में यह

#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); 

     } 
    } 
3

एक से थोड़ा अधिक पठनीय @ jbat100 के जवाब का संस्करण होना चाहिए (जो उन लोगों के रूप में उलझन में के रूप में मुझे लगता है कि #define FourCC2Str साथ थे के लिए, हां)

// Get your format description from whichever track you want 
CMFormatDescriptionRef formatHint; 

// Get the codec and correct endianness 
CMVideoCodecType formatCodec = CFSwapInt32BigToHost(CMFormatDescriptionGetMediaSubType(formatHint)); 

// add 1 for null terminator 
char formatCodecBuf[sizeof(CMVideoCodecType) + 1] = {0}; 
memcpy(formatCodecBuf, &formatCodec, sizeof(CMVideoCodecType)); 

NSString *formatCodecString = @(formatCodecBuf); 
1

पुन: प्राप्त करने के लिए एक फिल्म के साथ जुड़े ऑडियो और वीडियो कोडेक के एक स्विफ्ट दृष्टिकोण:

func codecForVideoAsset(asset: AVURLAsset, mediaType: CMMediaType) -> String? { 
    let formatDescriptions = asset.tracks.flatMap { $0.formatDescriptions } 
    let mediaSubtypes = formatDescriptions 
     .filter { CMFormatDescriptionGetMediaType($0 as! CMFormatDescription) == mediaType } 
     .map { CMFormatDescriptionGetMediaSubType($0 as! CMFormatDescription).toString() } 
    return mediaSubtypes.first 
} 

आप फिल्म के AVURLAsset और kCMMediaType_Video या kCMMediaType_Audio क्रमशः वीडियो और ऑडियो कोडेक्स पुनर्प्राप्त करने के लिए पास कर सकते हैं।

toString() समारोह एक मानव पठनीय स्ट्रिंग में कोडेक प्रारूप का FourCharCode प्रतिनिधित्व बदल देता है, और FourCharCode पर एक विस्तार पद्धति के रूप में प्रदान किया जा सकता:

extension FourCharCode { 
    func toString() -> String { 
     let n = Int(self) 
     var s: String = String (UnicodeScalar((n >> 24) & 255)) 
     s.append(UnicodeScalar((n >> 16) & 255)) 
     s.append(UnicodeScalar((n >> 8) & 255)) 
     s.append(UnicodeScalar(n & 255)) 
     return s.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) 
    } 
}