2016-11-07 59 views
0

我捕獲屏幕記錄並將其輸出到文件。而我的mac是視網膜。AVAsset視頻大小(寬*高)

我通過獲取文件大小:

self.asset = [AVAsset assetWithURL:_assetURL]; 

AVAssetTrack *track = [[self.asset tracksWithMediaType:AVMediaTypeVideo] firstObject]; 
self.vedioNaturalSize = CGSizeApplyAffineTransform(track.naturalSize, track.preferredTransform); 

,但是這個尺寸的像素,我想在點的大小。

當我在QuickTime中播放視頻時,我發現初始窗口大小不是以像素爲單位,而是我只能以像素爲單位獲取大小。

有沒有人知道這個方法,非常感謝。

回答

0

試試這個代碼轉換pixelToPoints

+(CGFloat)pixelToPoints:(CGFloat)px { 
CGFloat pointsPerInch = 72.0; // see: http://en.wikipedia.org/wiki/Point%5Fsize#Current%5FDTP%5Fpoint%5Fsystem 
CGFloat scale = 1; // We dont't use [[UIScreen mainScreen] scale] as we don't want the native pixel, we want pixels for UIFont - it does the retina scaling for us 
float pixelPerInch; // aka dpi 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    pixelPerInch = 132 * scale; 
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 
    pixelPerInch = 163 * scale; 
} else { 
    pixelPerInch = 160 * scale; 
} 
CGFloat result = px * pointsPerInch/pixelPerInch; 
return result; 
} 
+0

感謝您的幫助,我會嘗試。但我實際上想知道它是否存在API來獲取資產的重點。 – melody5417