avsubtitleWriter demo解析(三):SubtitlesTextReader
来源:互联网 发布:知乎 let it go 编辑:程序博客网 时间:2024/05/22 11:56
前面两篇 我们已经完成了subtitle类的几个方法的说明,现在我们回过头来了解SubtitlesTextReader。这当然我们前面已经结合subtitle的初始化讲到了SubtitlesTextReader的初始化。除了实例初始化方法initWithText外,还有一个便捷初始化方法subtitlesTextReaderWithText。
这部分我们只介绍剩余的工作。
第一个方法copyFormatDescription,这是每个字幕的结构描述,因为都是一样的,所以只需要返回字幕数组中第一个元素的结构描述就行。这个结构描述不是字幕的一个属性,是一个方法,在前面一篇我们已经讲过了。
- (CMFormatDescriptionRef)copyFormatDescription{// Take the format description from the first object. They are all the same since the display flag are all the same.return [[_subtitles firstObject] copyFormatDescription];}
第二个方法是metadata
- (NSArray *)metadata{NSMutableArray *mutableMetadata = [NSMutableArray array];// All subtitles must have the AVMediaCharacteristicTranscribesSpokenDialogForAccessibility characteristic.AVMutableMetadataItem *spokenItem = [AVMutableMetadataItem metadataItem];[spokenItem setKey:AVMetadataQuickTimeUserDataKeyTaggedCharacteristic];[spokenItem setKeySpace:AVMetadataKeySpaceQuickTimeUserData];[spokenItem setValue:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility];[mutableMetadata addObject:spokenItem];if (_wantsSDH){// SDH subtitles must also have the AVMediaCharacteristicDescribesMusicAndSoundForAccessibility characteristic.AVMutableMetadataItem *describesItem = [AVMutableMetadataItem metadataItem];[describesItem setKey:AVMetadataQuickTimeUserDataKeyTaggedCharacteristic];[describesItem setKeySpace:AVMetadataKeySpaceQuickTimeUserData];[describesItem setValue:AVMediaCharacteristicDescribesMusicAndSoundForAccessibility];[mutableMetadata addObject:describesItem];}return [mutableMetadata copy];}
这边设置QuickTime Metadata,这部分可以参看文档AV Foundation QuickTime Constants,AV Foundation Constants Reference(QuickTime User Data Keys,QuickTime User Data,QuickTime Metadata Keys,AVMediaSelectionOption Constants)
The key property contains the true key used to identify the contents of the metadata item. This value is specific to the key space of the metadata item.
The key space specified by this property is typically the default key space for the metadata container in which the metadata item is stored.
AV Foundation uses key spaces to group related sets of keys. For example, the framework defines different key spaces for common keys, iTunes keys, ID3 keys, and QuickTime keys. Key spaces aid in filtering arrays of metadata items.
desirable characteristics of legible media may include AVMediaCharacteristicTranscribesSpokenDialogForAccessibility and AVMediaCharacteristicDescribesMusicAndSoundForAccessibility.
第三个方法是copyNextSampleBuffer,你可以预见我们要连续copy buffer,因此需要这么一个方法来指示进度。
- (CMSampleBufferRef)copyNextSampleBuffer{CMSampleBufferRef sampleBuffer = NULL;if (_index < _subtitles.count){sampleBuffer = [(Subtitle *)_subtitles[_index] copySampleBuffer];_index++;}return sampleBuffer;}
至此我们完成了前期的准备工作。当然接下去是调用SubtitlesTextReader来创建input。下面的的确也繁琐。
本篇中设置metaData是个难点,你需要去了解下这部分常量的意思。
- avsubtitleWriter demo解析(三):SubtitlesTextReader
- avsubtitleWriter demo解析(一):字幕解析
- avsubtitleWriter demo解析(二):创建CMSampleBufferRef
- avsubtitleWriter demo解析(四):writeSubtitles上篇
- avsubtitleWriter demo解析(四):writeSubtitles下篇
- 冒泡,选择,插入三大基本排序解析以及Demo
- Android之解析XML的三种Demo!
- Android解析自定义xml文件--Pull解析xml文件,测试demo(方案三)
- IOS CoreData 多表查询demo解析(三)--查询
- IOS CoreData 多表查询demo解析(三)--查询
- WebSocket使用(C++环境)(三) --- 自己解析websocket协议及websocket聊天demo
- 背景 - JasperReports Demo解析
- linux socket 解析 & demo
- Jsoup解析HTML Demo
- android api demo 解析
- ActivityLifeCycle官方demo解析
- OKhttp源码解析---demo
- java国际化demo解析
- sencha touch实例:微博设置界面
- apache commons组件学习之FileUpload
- ASP.NET AJAX(开发代号Atlas)重要参考资源大收集
- apache commons学习系列记录之IO组件version2.4之一
- matlab 2010a linux 安装过程
- avsubtitleWriter demo解析(三):SubtitlesTextReader
- ASP.NET 服务器控件对应HTML标签
- apache commons学习系列记录之IO组件version2.4之二
- 如何处理海量数据(转)
- Openstack压力测试(二) -- 结果还不错!
- apache commons组件学习系列记录之lang3
- 博客发外链的注意事项
- 敌兵布阵-树状数组
- 一个SEOER要具备的素质