简体   繁体   English

将SCC(两字节十六进制字)转换为字符串

[英]Convert SCC (two-byte hexadecimal words) to string

Given the following string: 给定以下字符串:

00:00:03:13 9420 9454 5bcb 45d9 c24f c152 c449 cec7 94f2 c1ce c420 434f cdd0 d554 4552 20ce 4f49 d345 d35d

How would I convert this to text? 我如何将其转换为文本?

pycaption is a library I found. pycaption是我发现的一个库。 pip install pycaption and try to parse your sample: pip install pycaption并尝试解析您的示例:

from pycaption import SCCReader
input = '00:00:03:13 9420 9454 5bcb 45d9 c24f c152 c449 cec7 94f2 c1ce c420 434f cdd0 d554 4552 20ce 4f49 d345 d35d'
contents = SCCReader().read(input.decode('utf-8'))
contents.get_captions('en-US')

You will get errors: 您将得到错误:

pycaption.exceptions.CaptionReadNoCaptions: CaptionReadNoCaptions((u'empty caption file',))

That's because SCC doesn't only contain encoded text, it also has commands inside. 这是因为SCC不仅包含编码的文本,而且内部还包含命令。 The first 2 bytes 9420 means "start pop-on caption". 前两个字节9420表示“开始弹出字幕”。 A tailing 942f (End Of Caption) is expected in order to show the text properly. 为了正确显示文本,应使用942f (字幕结尾)。 But it's missing in your sample. 但是您的样本中没有。 I think it's in following parts that you didn't paste. 我认为您没有粘贴以下部分。 Meanwhile, first line of SCC file should be version format. 同时,SCC文件的第一行应为版本格式。 Let's add 2 lines into your sample: 让我们在示例中添加2行:

input = '''Scenarist_SCC V1.0

00:00:03:13 9420 9454 5bcb 45d9 c24f c152 c449 cec7 94f2 c1ce c420 434f cdd0 d554 4552 20ce 4f49 d345 d35d

00:00:04:00 942f
'''

Then the output would be: 那么输出将是:

[u'00:00:04.037 --> 00:00:00.000\n[KEYBOARDING\nAND COMPUTER NOISES]']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM