使用 JWPlayer 将文件转换为 JSON

Converting file into JSON using JWPlayer

大家好,我在为视频添加字幕时遇到了问题。

我将我的 .vtt 作为一个值放在我的对象中,但浏览器似乎不喜欢它的输出方式。我正在关注本指南 here

这是我的控制台上弹出的错误

    {name: "", message: "Converting circular structure to JSON", error: TypeError: Converting circular structure to JSON at Object.stringify (native) at Object.<ano…}

字幕-en.vtt

00:00:01.000 --> 00:00:15.000
What brings you to the land
of the gatekeepers?

00:00:15.500 --> 00:00:20.500
I'm searching for someone.

00:00:36.500 --> 00:00:39.000
A dangerous quest for a lone hunter.

00:00:41.500 --> 00:00:44.000
I've been alone for as long
as I can remember.

Javascript

jwplayer("my-video").setup({
    file: "<my-video-file>",
    width: "100%",
    aspectratio: "24:10",
    primary: "flash",
    tracks: [{
        file: "/assets/captions/captions-en.vtt",
        label: "English",
        kind: "captions"
    }]
});

我还确保我保存为 "UTF-8" 编码。

我还缺少另一个步骤吗?像一个解析方法?

另请注意,我正在从 AWS S3 Bucket 流式传输视频。这是否是导致我必须将 vtt 文件上传到那里的错误的原因?

这个 post 中的错误是相同的,但他们通过放置在一个字符串中展示了他们是如何做到的。如果它来自 vtt 文件,我将如何处理?

Also note that I'm streaming the video from AWS S3 Bucket. Would that be the reason causing the error that I would have to upload the vtt file on there?

是的,无论您的视频在哪里,都可以上传 VTT 文件。 VTT 存在安全限制,根据我自己的经验,我尚未成功 运行 JWPlayer 使用与视频位于不同存储桶中的 VTT。

通过 运行 在 https://quuz.org/webvtt/

处检查 VTT 文件是否有效

S3 可能会将您的 VTT 默认为 content-type 作为 application/octet-stream。我不确定您是如何使用 S3 的,但是如果您可以在 上传后检查 VTT 的属性,请查找 属性:

Content-Type: binary/octet-stream

如果你看到了,那么你需要把它改成这样:

Content-Type: text/vtt

如果您没有建立过程and/or工具来检查 S3 上的 VTT,请使用 S3 浏览器或 Cloudberry S3 Explorer 的免费软件版本。

关于那个错误:

{name: "", message: "Converting circular structure to JSON", error: TypeError: Converting circular structure to JSON at Object.stringify (native) at Object.<ano…}

我不认为 VTT 文件是错误的原因。如果您查看它的格式,VTT 与 JSON 没有任何相似之处,但 JW 设置语法的结构非常相似。