2016-02-19 96 views
1

我想看看用戶選擇的視頻文件是隔行/逐行的,然後根據它進行一些操作。閱讀目標中的視頻元數據c

我試圖檢查我提取的cmsamplebuffer是否定義爲頂部字段第一或底部字段第一,但是這將返回所有輸入爲空。

NSMutableDictionary *pixBuffAttributes = [[NSMutableDictionary alloc] init]; 
[pixBuffAttributes setObject: 
[NSNumber numberWithInt:kCVPixelFormatType_422YpCbCr8] 
forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey]; 
myAsset = [[AVURLAsset alloc] initWithURL:urlpath options:pixBuffAttributes]; 
myAssetReader = [[AVAssetReader alloc] initWithAsset:myAsset error:nil]; 
myAssetOutput = [[AVAssetReaderTrackOutput alloc]initWithTrack: 
       [[myAsset tracksWithMediaType:AVMediaTypeVideo] 
       objectAtIndex: 0] 
       outputSettings:pixBuffAttributes]; 
[myAssetReader addOutput:myAssetOutput]; 
[myAssetReader startReading]; 
CMSampleBufferRef ref = [myAssetOutput copyNextSampleBuffer]; 
if(CVBufferGetAttachments(ref, kCVImageBufferFieldDetailKey, nil) == nil) 
{ 
    //always the case 
} 
else 
{ 
    //never happens 
} 

無論輸入文件的隔行掃描以上總是返回nil。我可能試圖在完全錯誤的莊園中進行測試,所以非常感謝所有幫助!

回答

0

感謝jeschot蘋果開發者爲回答這個問題,https://forums.developer.apple.com/thread/39029 如果其他人試圖做同樣的事情的propper方式從視頻獲得大部分的元數據:

CGSize inputsize = [[myAsset tracksWithMediaType:AVMediaTypeVideo][0] naturalSize]; 

    properties->m_frame_rows = inputsize.height; 
    properties->m_pixel_cols = inputsize.width; 

    CFNumberRef fieldCount = CMFormatDescriptionGetExtension((CMFormatDescriptionRef)[myAsset tracksWithMediaType:AVMediaTypeVideo][0].formatDescriptions[0], kCMFormatDescriptionExtension_FieldCount); 

    if([(NSNumber*) fieldCount integerValue] == 1) 
    { 
     properties->m_interlaced = false; 
     properties->m_fld2_upper = false; 
    } 
    else 
    { 
     properties->m_interlaced = true; 

     CFPropertyListRef interlace = CMFormatDescriptionGetExtension((CMFormatDescriptionRef)[myAsset tracksWithMediaType:AVMediaTypeVideo][0].formatDescriptions[0], kCMFormatDescriptionExtension_FieldDetail); 

     if(interlace == kCMFormatDescriptionFieldDetail_SpatialFirstLineEarly) 
     { 
      properties->m_fld2_upper = false; 
     } 

     if(interlace == kCMFormatDescriptionFieldDetail_SpatialFirstLineLate) 
     { 
      properties->m_fld2_upper = true; 
     } 

     if(interlace == kCMFormatDescriptionFieldDetail_TemporalBottomFirst) 
     { 
      properties->m_fld2_upper = true; 
     } 

     if(interlace == kCMFormatDescriptionFieldDetail_TemporalTopFirst) 
     { 
      properties->m_fld2_upper = false; 
     } 
    } 

    CMTime minDuration = [myAsset tracksWithMediaType:AVMediaTypeVideo][0].minFrameDuration; 

    int64_t fpsNumerator = minDuration.value; 
    int32_t fpsDenominator = minDuration.timescale; 

    properties->m_ticks_duration = (unsigned int) fpsNumerator; 
    if (properties->m_interlaced) 
    { 
     properties->m_ticks_per_second = fpsDenominator * 2; 
    } 
    else 
    { 
     properties->m_ticks_per_second = fpsDenominator; 
    } 

和快速記了任何其他人都會因此而感到困惑,如果容器的元數據(例如清潔度低於全分辨率),自然大小並不總是圖像的完整分辨率。目前正試圖解決這個問題,但這是一個不同的問題!

UPDATE:

我發現,這種天然的大小是顯示分辨率。找到您需要解碼第一幀的編碼分辨率並檢查您獲得的緩衝區對象的分辨率。這些可以在像素縱橫比!= 1或(如上所述)乾淨貼圖的情況下有所不同。