使用AVFoundation将章节信息添加到现有视频中 [英] Add chapter information to existing video with AVFoundation

查看:201
本文介绍了使用AVFoundation将章节信息添加到现有视频中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将章节标记(文本和图像)添加到iOS中的现有视频中.借助内置函数,阅读它们非常容易:

I am trying to add chapter markers (text + images) to an existing video in iOS. Reading them is trivially easy with builtin functions:

NSLocale * locale = [chapterLocalications lastObject];
NSLog(@"Locale: %@", [locale localeIdentifier]);
NSArray *keys = @[AVMetadataCommonKeyTitle, AVMetadataCommonKeyArtwork];
NSArray *chapters = [asset chapterMetadataGroupsWithTitleLocale:locale containingItemsWithCommonKeys:keys];
for (AVTimedMetadataGroup * metadataGroup in chapters) {
    NSArray * items = metadataGroup.items;
    CMTimeRange timeRange = metadataGroup.timeRange;
    NSLog(@"time: %@", CMTimeCopyDescription(NULL, timeRange.start));
    for (AVMetadataItem * metadataItem in items) {
        NSLog(@"key: %@", metadataItem.commonKey);
        NSLog(@"value: %@", metadataItem.value);
    }
}

到目前为止,我还没有找到一种将定时元数据写入文件的方法.我可以使用AVAssetExportSession和AVMutableMetadataItem轻松编写普通的元数据(如标题文本或图片).有一个AVMutableTimedMetadataGroup,但令人沮丧的是,似乎没有一种将它们实际写入轨道的方法.

So far I have not found a way to write timed metadata to a file. I can easily write normal metadata (like title text or pictures) using AVAssetExportSession and AVMutableMetadataItem. There is a AVMutableTimedMetadataGroup, but frustratingly there doesn't seem to be a way to actually write these to a track.

我目前的想法是,我需要将章节信息写入一个临时文件,然后使用AVMutableComposition将章节轨道合并到现有视频中.当然,这留下了编写章节信息的问题.我可以手动或使用第三方库(我想避免)编写MP4容器,或者我可以尝试说服AVAssetWriter以某种方式编写定时的元数据轨道,尽管也没有记录.然后我仍然不知道AVMutableComposition是否能够合并章节轨道.

My current thinking is that I need to write chapter information into a temporary file and then use AVMutableComposition to merge the chapter track into the existing video. Of course, that leaves the problem of writing the chapter information. I could write an MP4 container manually or with a third party library (which I'd like to avoid), or I could try to convince AVAssetWriter to somehow write timed metadata tracks, though that is not documented, either. And then I still don't know if AVMutableComposition is able to merge chapter tracks.

在我发疯之前,有没有人找到一种方法来做到这一点?我很想放弃整个章节的想法,只保存引用视频的特定于应用程序的文件.

Has anyone found a way to do this, before I go mad? I'm tempted to drop this whole chapter idea and just save an application-specific file that references the video.

推荐答案

Apple的WWDC 2014有一期名为利用视听媒体中的元数据"的会议.在此处查看视频: https://developer.apple.com/videos/wwdc/2014/

There is a session from Apple's WWDC 2014 called Harnessing Metadata in Audiovisual Media. Check out the video here: https://developer.apple.com/videos/wwdc/2014/

还,请检出名为AVTimedAnnotationWriter的示例代码

这篇关于使用AVFoundation将章节信息添加到现有视频中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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