avsubtitleWriter demo解析(三):SubtitlesTextReader

前面两篇 我们已经完成了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是个难点,你需要去了解下这部分常量的意思。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值