媒体处理实用程序的集合。

pressurecooker的Python项目详细描述


压力锅

各种媒体处理功能和实用程序的库

设置您的环境

转换标题文件

pressurecooker库包含用于从几个不同的 格式化为首选的VTT格式。当前支持的格式包括:

Within pressurecooker, the term "captions" and "subtitles" are used interchangeably. All of the classes and functions handling conversion use the "subtitles" term.

语言代码

DFXPSAMITTML格式可以在一个文件中封装多种语言的标题内容。 SCCSRTVTT格式通常仅限于在 文件(这个规则的VTT可能是一个异常,但是我们的转换器没有检测到它的语言)。 因此,当转换这些文件时,我们无法知道我们使用的是什么语言 而必须使用常量LANGUAGE_CODE_UNKNOWN来提取转换后的字幕。

还要注意,字幕文件中使用的语言代码可能与 在le-utils中定义的le内部语言代码。

从文件创建转换器

要从本地文件路径创建字幕转换器,请使用以下命令:

frompressurecooker.subtitlesimportbuild_subtitle_converter_from_fileconverter=build_subtitle_converter_from_file('/path/to/file.srt')

从字符串创建转换器

如果已经将标题加载到字符串变量中, 您可以像这样创建转换器:

frompressurecooker.subtitlesimportbuild_subtitle_convertercaptions_str=''# In this example, `captions_str` holds the caption contentsconverter=build_subtitle_converter(captions_str)

转换字幕

对于不包含语言代码信息的SCCSRTVTT字幕格式, 在 提取转换字幕的时间:

frompressurecooker.subtitlesimportbuild_subtitle_converter_from_filefrompressurecooker.subtitlesimportLANGUAGE_CODE_UNKNOWNconverter=build_subtitle_converter_from_file('/path/to/file.srt')# Option A: Obtain the contents of the converted VTT file as a stringoutput_str=converter.convert(LANGUAGE_CODE_UNKNOWN)# Option B: Write the converted subtitles to a local pathconverter.write("/path/to/file.vtt",LANGUAGE_CODE_UNKNOWN)

常量是内部表示。 用于表示未知语言代码中的字幕。这将是默认值 只有用于SCCSRTVTT字幕转换器的语言代码。

如果你不确定格式,但你知道文件的语言, 用这种语言有条件地替换LANGUAGE_CODE_UNKNOWN比较安全:

frompressurecooker.subtitlesimportbuild_subtitle_converter_from_filefrompressurecooker.subtitlesimportLANGUAGE_CODE_UNKNOWNconverter=build_subtitle_converter_from_file('/path/to/file')# Replace unknown language code if presentifconverter.has_language(LANGUAGE_CODE_UNKNOWN):converter.replace_unknown_language('en')assertconverter.has_language('en'),'Must have English after replace'output_str=converter.convert('en')

一个演示如何处理诸如DFXPSAMITTML等字幕格式的示例, 有多种语言,如下所示:

frompressurecooker.subtitlesimportbuild_subtitle_converter_from_filefrompressurecooker.subtitlesimportLANGUAGE_CODE_UNKNOWN,InvalidSubtitleLanguageErrorconverter=build_subtitle_converter_from_file('/path/to/file')forlang_codeinconverter.get_language_codes():# `some_logic` would be your decisions on whether to use this languageifsome_logic(lang_code):converter.write("/path/to/file-{}.vtt".format(lang_code),lang_code)eliflang_code==LANGUAGE_CODE_UNKNOWN:raiseInvalidSubtitleLanguageError('Unexpected unknown language')

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用JNA创建同一库的多个实例?   java在将Graphql查询作为JSON字符串传递时收到意外的令牌错误   OAuth2 oltu的java问题   java桌面应用程序使用的好的嵌入式数据库是什么?   java Firebase数据库高级查询选项   java正在使磁盘上的EhCache元素过期   java 安卓还原处于backstack中的片段的实例状态   XMemcached中的java异步集   java TimescaleDB是否使用与Postgresql完全相同的JDBC驱动程序?   java从网站c读取信息#   检查java Android中的字符串是否只包含数字和空格   c#如何向web服务发送特殊字符?   grails无法调用需要java的方法。lang.类参数?   java我在组合框中调用的方法不会运行所有代码,它只运行部分代码   java发送带有标头的HTTP GET请求