为AVAssetExportSession创建时间范围 [英] Creating a time range for AVAssetExportSession

查看:163
本文介绍了为AVAssetExportSession创建时间范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从时间戳中为 AVAssetExportSession 设定时间范围,例如:

I was wondering how to make a time range for AVAssetExportSession from time stamps such as:

NSTimeInterval start = [[NSDate date] timeIntervalSince1970];
NSTimeInterval end = [[NSDate date] timeIntervalSince1970];

我用于导出会话的代码如下:

The code that I am using for my export session is as follows:

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];

exportSession.outputURL = videoURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.timeRange = CMTimeRangeFromTimeToTime(start, end);

感谢您的帮助!

推荐答案

AVAssetExportSession <中的属性 timeRange / code>允许您对资产进行部分导出,指定从哪里开始和持续时间。如果没有指定它将导出整个视频,换句话说,它将从零开始并将导出总持续时间。

The property timeRange in AVAssetExportSession allows you to do a partial export of an asset specifying where to start and which duration. If not specified it'll export the whole video, in other words, it'll start at zero and will export the total duration.

应该表示开始和持续时间as CMTime

Both start and duration should be expressed as CMTime.

例如,如果您想要导出资产的前半部分:

For instance, if you want to export the first half of the asset:

CMTime half = CMTimeMultiplyByFloat64(exportSession.asset.duration, 0.5);
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, half);

或下半年:

exportSession.timeRange = CMTimeRangeMake(half, half);

或最后10秒:

CMTime _10 = CMTimeMakeWithSeconds(10, 600);
CMTime tMinus10 = CMTimeSubtract(exportSession.asset.duration, _10);
exportSession.timeRange = CMTimeRangeMake(tMinus10, _10);

检查 CMTime 其他计算方法的参考你需要的确切时间。

Check CMTime reference for other ways to calculate the exact timing you need.

这篇关于为AVAssetExportSession创建时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆