AVAsset视频大小(宽*高)

时间:2016-11-07 06:48:05

标签: objective-c macos avfoundation avasset

我捕获屏幕记录并将其输出到文件中。我的mac是视网膜。

我通过以下方式获取文件大小:

self.asset = [AVAsset assetWithURL:_assetURL];

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

但是这个尺寸是以像素为单位的,我希望得到这个尺寸。

当我在QuickTime中播放视频时,我发现初始窗口大小不在像素中,但我只能以像素为单位获得大小。

非常感谢有人知道这种做法。

1 个答案:

答案 0 :(得分: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;
}