【问题标题】:Creating a time range for AVAssetExportSession为 AVAssetExportSession 创建时间范围
【发布时间】:2012-05-27 09:36:53
【问题描述】:

我想知道如何根据以下时间戳为AVAssetExportSession 创建一个时间范围:

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

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

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

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

感谢您的帮助!

【问题讨论】:

    标签: iphone ios time avassetexportsession cmtime


    【解决方案1】:

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

    开始和持续时间都应表示为CMTime

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

    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 参考,了解计算所需确切时间的其他方法。

    【讨论】:

    • 非常感谢!都整理好了。唯一的问题是 CMTimeMakeWithSeconds 需要有两个参数。所以第二个参数必须是首选的时间尺度。
    • Opps,已修复。这发生在没有实时语法检查的文本区域中编写代码:)
    猜你喜欢
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    • 2021-10-19
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多