首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AVAsset和AVAssetTrack -IOS4.0中的跟踪管理

AVAsset和AVAssetTrack -IOS4.0中的跟踪管理
EN

Stack Overflow用户
提问于 2010-07-21 10:35:07
回答 1查看 12.9K关注 0票数 6

IOS 4.0的新功能列表显示,AV基金会框架已经实现了媒体资产管理、跟踪管理、媒体编辑和媒体项目元数据管理。这是什么意思?

使用跟踪管理和媒体资产管理的

  1. 可以访问照片应用程序中的媒体文件吗?
  2. 我可以使用AVComposition制作定制的组合并导出并发送到服务器?
  3. 可以重命名、移动和编辑资产的元数据信息吗?

我试图在这方面得到一些帮助/文件,却找不到任何东西..

谢谢,

托尼

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-24 16:32:55

是的,你可以做你提到的大部分事情。我认为访问你手机的媒体文件并不是那么简单。但是你可以从网络中读取数据,如果你愿意的话,你可以把它导出到你的相机上。

首先,您必须导入您的视频或音频文件。

您需要开始的是您自己的视频播放器,您在您自己的观点创建。如果你不喜欢播放你的视频,而只是简单地写你的东西,你可以简单地去没有一个视图。

这很简单: 1.创建一个可变的组合:

代码语言:javascript
运行
复制
AVMutableComposition *composition = [AVMutableComposition composition];

这会保存你的视频。现在你有了一个空的组合--资产。从您的目录或web添加一些文件:

代码语言:javascript
运行
复制
NSURL* sourceMovieURL = [NSURL fileURLWithPath:moviePath];
AVURLAsset* sourceAsset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil];

然后将你的视频添加到你的作文中

代码语言:javascript
运行
复制
// calculate time
CMTimeRange editRange = CMTimeRangeMake(CMTimeMake(0, 600), CMTimeMake(sourceAsset.duration.value, sourceAsset.duration.timescale));

// and add into your composition 
BOOL result = [composition insertTimeRange:editRange ofAsset:sourceAsset atTime:composition.duration error:&editError];

如果您想要添加更多的视频到您的作文,您可以添加另一个资产,并再次设置到您的作文使用您的时间范围。现在您可以使用如下代码导出您的新组合:

代码语言:javascript
运行
复制
NSError *exportError = nil;

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

NSURL *exportURL = [NSURL fileURLWithPath:exportVideoPath];
exportSession.outputURL = exportURL;
exportSession.outputFileType = @"com.apple.quicktime-movie";
[exportSession exportAsynchronouslyWithCompletionHandler:^{
    switch (exportSession.status) {
        case AVAssetExportSessionStatusFailed:{
            NSLog (@"FAIL");
            [self performSelectorOnMainThread:@selector (doPostExportFailed:)
                                        withObject:nil
                                                    waitUntilDone:NO];
            break;
        }
        case AVAssetExportSessionStatusCompleted: {
            NSLog (@"SUCCESS");
            [self performSelectorOnMainThread:@selector (doPostExportSuccess:)
                        withObject:nil
                        waitUntilDone:NO];
            break;
        }
    };
}];

如果您想播放视频,请使用这样的代码(我想,您可以访问您的视图):

代码语言:javascript
运行
复制
// create an AVPlayer with your composition
AVPlayer* mp = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:composition]];

// Add the player to your UserInterface
// Create a PlayerLayer:
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:mp];

// integrate it to your view. Here you can customize your player (Fullscreen, or a small preview)
[[self view].layer insertSublayer:playerLayer atIndex:0];
playerLayer.frame = [self view].layer.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;  

最后播放你的视频:

代码语言:javascript
运行
复制
[mp play];

输出到相机卷:

代码语言:javascript
运行
复制
NSString* exportVideoPath = >>your local path to your exported file<<
UISaveVideoAtPathToSavedPhotosAlbum (exportVideoPath, self, @selector(video:didFinishSavingWithError: contextInfo:), nil);

如果完成通知(回调方法),则获取通知。

代码语言:javascript
运行
复制
- (void) video: (NSString *) videoPath didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {
    // Error is nil, if succeeded
    NSLog(@"Finished saving video with error: %@", error);
    // do postprocessing here, i.e. notifications or UI stuff

}

不幸的是,我没有找到任何“合法”的解决方案,从摄影师阅读。

一开始的一个很好的来源是:

http://www.subfurther.com/blog/?cat=51

请下载VTM_Player.zip、VTM_AVRecPlay.zip或VTM_AVEditor.zip,以便对此进行很好的介绍。

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3298290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档