解析和转换 TED 演讲 JSON 字幕

发布于 2024-08-16 10:34:29 字数 3768 浏览 5 评论 0原文

此问题与另一个问题@ SuperUser相关。

我想下载 TED 演讲 以及相应的字幕以供离线观看,例如,让我们来看看 Richard St. John 的简短演讲,高分辨率视频下载网址为下列的:

http://www.ted.com/talks/download /video/5118/talk/70

相应的 JSON 编码英文字幕可以在以下位置下载:

http://www.ted.com/talks/subtitles /id/70/lang/eng

这是实际字幕的开头的例外:

{
  "captions": [{
        "content": "This is really a two hour presentation I give to high school students,",
        "startTime": 0,
        "duration": 3000,
        "startOfParagraph": false
      }, {
        "content": "cut down to three minutes.",
        "startTime": 3000,
        "duration": 1000,
        "startOfParagraph": false
      }, {
        "content": "And it all started one day on a plane, on my way to TED,",
        "startTime": 4000,
        "duration": 3000,
        "startOfParagraph": false
      }, {
        "content": "seven years ago."

从字幕的结尾

{
  "content": "Or failing that, do the eight things -- and trust me,",
  "startTime": 177000,
  "duration": 3000,
  "startOfParagraph": false
}, {
  "content": "these are the big eight things that lead to success.",
  "startTime": 180000,
  "duration": 4000,
  "startOfParagraph": false
}, {
  "content": "Thank you TED-sters for all your interviews!",
  "startTime": 184000,
  "duration": 2000,
  "startOfParagraph": false
}]
}

我想编写一个自动运行的应用程序下载视频的高分辨率版本和所有可用的字幕,但我真的很难,因为我必须将字幕转换为(VLC或任何其他像样的视频播放器)<兼容格式(.srt 或 .sub 是我的首选)并且我不知道 startTimeduration 键是什么JSON 文件表示

到目前为止我所知道的是:

  • 下载的视频持续3分30秒,并且具有29 FPS = 6090帧
  • startTime 从 0 开始,duration 为 3000 = 3000
  • startTime结束于 184000duration 为 2000 = 186000

还可能值得注意的是以下 Javascript 片段:

introDuration:16500,
adDuration:4000,
postAdDuration:2000,

所以我的问题是,我应该应用什么逻辑startTimeduration 值转换为 .srt 兼容格式

1
00:01:30,200 --> 00:01:32,201
MEGA DENG COOPER MINE, INDIA

2
00:01:37,764 --> 00:01:39,039
Watch out, watch out!

或转换为 .sub 兼容格式

{FRAME_FROM}{FRAME_TO}This is really a two hour presentation I give to high school students,
{FRAME_FROM}{FRAME_TO}cut down to three minutes.

任何人都可以帮我解决这个问题吗?


Ninh Bui 成功了,公式如下:

introDuration - adDuration + startTime ... introDuration - adDuration + startTime + duration

这种方法允许我通过两种方式直接转换为 .srt 格式(无需知道长度和 FPS):

00:00:12,500 --> 00:00:15,500
This is really a two hour presentation I give to high school students,

00:00:15,500 --> 00:00:16,500
cut down to three minutes.

以及:

00:00:00,16500 --> 00:00:00,19500
And it all started one day on a plane, on my way to TED,

00:00:00,19500 --> 00:00:00,20500
seven years ago.

This question is related to this other question @ SuperUser.

I want to download the TED Talks and the respective subtitles for offline viewing, for instance lets take this short talk by Richard St. John, the high-resolution video download URL is the following:

http://www.ted.com/talks/download/video/5118/talk/70

And the respective JSON encoded english subtitles can be downloaded at:

http://www.ted.com/talks/subtitles/id/70/lang/eng

Here is an except from the beginning of actual subtitle:

{
  "captions": [{
        "content": "This is really a two hour presentation I give to high school students,",
        "startTime": 0,
        "duration": 3000,
        "startOfParagraph": false
      }, {
        "content": "cut down to three minutes.",
        "startTime": 3000,
        "duration": 1000,
        "startOfParagraph": false
      }, {
        "content": "And it all started one day on a plane, on my way to TED,",
        "startTime": 4000,
        "duration": 3000,
        "startOfParagraph": false
      }, {
        "content": "seven years ago."

And from the end of the subtitle:

{
  "content": "Or failing that, do the eight things -- and trust me,",
  "startTime": 177000,
  "duration": 3000,
  "startOfParagraph": false
}, {
  "content": "these are the big eight things that lead to success.",
  "startTime": 180000,
  "duration": 4000,
  "startOfParagraph": false
}, {
  "content": "Thank you TED-sters for all your interviews!",
  "startTime": 184000,
  "duration": 2000,
  "startOfParagraph": false
}]
}

I want to write an app that automatically downloads the high-resolution version of the video and all the available subtitles, but I'm having a really hard time since I have to convert the subtitle to a (VLC or any other decent video player) compatible format (.srt or .sub are my first choices) and I've no idea what the startTime and duration keys of the JSON file represent.

What I know so far is this:

  • The downloaded video lasts for 3 minutes and 30 seconds, and has 29 FPS = 6090 frames.
  • startTime starts at 0 with a duration of 3000 = 3000
  • startTime ends at 184000 with a duration of 2000 = 186000

It may also be worthwhile noticing the following Javascript snippet:

introDuration:16500,
adDuration:4000,
postAdDuration:2000,

So my question is, what logic should I apply to convert startTime and duration values to a .srt compatible format:

1
00:01:30,200 --> 00:01:32,201
MEGA DENG COOPER MINE, INDIA

2
00:01:37,764 --> 00:01:39,039
Watch out, watch out!

Or to a .sub compatible format:

{FRAME_FROM}{FRAME_TO}This is really a two hour presentation I give to high school students,
{FRAME_FROM}{FRAME_TO}cut down to three minutes.

Can anyone help me out with this?


Ninh Bui nailed it, the formula is the following:

introDuration - adDuration + startTime ... introDuration - adDuration + startTime + duration

This approach allows to me convert directly to .srt format (no need to know length and FPS) in two ways:

00:00:12,500 --> 00:00:15,500
This is really a two hour presentation I give to high school students,

00:00:15,500 --> 00:00:16,500
cut down to three minutes.

And:

00:00:00,16500 --> 00:00:00,19500
And it all started one day on a plane, on my way to TED,

00:00:00,19500 --> 00:00:00,20500
seven years ago.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

节枝 2024-08-23 10:34:29

我的猜测是,json 中的时间以毫秒表示,例如 1000 = 1 秒。可能有一个主计时器,其中 startTime 指示时间线上字幕应出现的时间,而持续时间可能是字幕应在视觉中保留的时间量。通过除以186000 / 1000 = 186秒= 186 / 60 = 3.1分钟= 3分6秒进一步证实了这一理论。剩下的几秒可能是掌声;-) 有了这些信息,您还应该能够计算出您应该将转换应用到哪个帧到哪个帧,即您已经知道每秒的帧数是多少,所以您需要做的就是相乘获取开始帧的 FPS 开始时间的秒数。结束帧可以通过以下方式获得:(startTime + 持续时间) * fps :-)

My guess would be that the times in the json are expressed in milliseconds, e.g. 1000 = 1 second. There is probably a maintimer, where startTime indicates the time on the timeline at which the subtitle should appear and the duration is probably the amount of time the subtitle should remain in vision. This theory is further affirmed by dividing 186000 / 1000 = 186 seconds = 186 / 60 = 3.1 minutes = 3 minutes and 6 seconds. The remaining seconds are probably applause ;-) With this information you should also be able to calculate from what frame to what frame you should apply your conversion to, i.e. you already know what the frames per second is so all you need to do is multiply the number of seconds of starttime with the FPS to get the begin frame. The end frame can be obtained by: (startTime + duration) * fps :-)

同尘 2024-08-23 10:34:29

我制作了一个简单的基于控制台的程序来下载字幕。我正在考虑使用一些脚本系统(例如油脂猴子)通过网络使其可用...这是我的博客文章与代码的链接。: http://estebanordano.com.ar/ted-talks-download-subtitles/

I made a simple console-based program to download the subtitles. I was thinking of making it available via web using some script system like grease monkey... Here is the link to my blogpost with the code.: http://estebanordano.com.ar/ted-talks-download-subtitles/

深海夜未眠 2024-08-23 10:34:29

我发现另一个使用这种格式的网站。我很快就破解了一个函数将它们转换为 srt,应该是不言自明的:

import urllib2
import json

def json2srt(url, fname):
    data = json.load(urllib2.urlopen(url))['captions']

    def conv(t):
        return '%02d:%02d:%02d,%03d' % (
            t / 1000 / 60 / 60,
            t / 1000 / 60 % 60,
            t / 1000 % 60,
            t % 1000)

    with open(fname, 'wb') as fhandle:
        for i, item in enumerate(data):
            fhandle.write('%d\n%s --> %s\n%s\n\n' %
                (i,
                 conv(item['startTime']),
                 conv(item['startTime'] + item['duration'] - 1),
                 item['content'].encode('utf8')))

I found another site which used this format. I quickly hacked a function to convert them into srt, should be self-explanatory:

import urllib2
import json

def json2srt(url, fname):
    data = json.load(urllib2.urlopen(url))['captions']

    def conv(t):
        return '%02d:%02d:%02d,%03d' % (
            t / 1000 / 60 / 60,
            t / 1000 / 60 % 60,
            t / 1000 % 60,
            t % 1000)

    with open(fname, 'wb') as fhandle:
        for i, item in enumerate(data):
            fhandle.write('%d\n%s --> %s\n%s\n\n' %
                (i,
                 conv(item['startTime']),
                 conv(item['startTime'] + item['duration'] - 1),
                 item['content'].encode('utf8')))
蓝天白云 2024-08-23 10:34:29

TEDGrabber beta2:我的程序:
http://sourceforge.net/projects/tedgrabber/

TEDGrabber beta2 : my program :
http://sourceforge.net/projects/tedgrabber/

朕就是辣么酷 2024-08-23 10:34:29

我编写了一个 python 脚本,用于下载任何 TED 视频并创建一个 mkv 文件,其中嵌入了所有字幕/元数据( https://github.com/oxplot/ted2mkv)。

我在 TED 演讲页面的 javascript 代码中使用了变量 pad_seconds 作为要添加到 JSON 字幕文件中所有时间戳的偏移量。我想这就是 Flash 播放器所使用的。

I've written a python script that downloads any TED video and creates an mkv file with all the subtitles/metadata embedded in it ( https://github.com/oxplot/ted2mkv ).

I used the variable pad_seconds in the javascript code of the TED talk page as an offset to be added to all the timestamps in JSON subtitle files. It is what the flash player uses, I assume.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文