json - 解析和转换 TED 演讲 JSON 字幕

标签 json parsing string video subtitle

这个问题与this other question @ SuperUser有关.

我要下载 TED Talks以及离线观看的相应字幕,例如让我们看this short talk by 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 是我的首选)我不知道什么是startTime 和JSON文件的duration键代表

目前我所知道的是:

  • 下载的视频时长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.

最佳答案

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

关于json - 解析和转换 TED 演讲 JSON 字幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1955618/

相关文章:

java - 当传递基类类型的引用时,JSON 仅序列化基类字段

json - Loopback 也创建了一个构建 json 模型的数据库结构

javascript - 不和谐 : Using a command to get Data from Array

c++ - 如何更改 C++ 中字符串的大小写?

java - 如何使用 Ruby 生成 Java 的 String hashCode

javascript - 计算后将JSON对象值转为十进制数

parsing - 如何解析文本并提取整数

parsing - Scrapy:将列表项解析到单独的行上

php - 如何从 php 执行 casperjs?

javascript - 从字符串模板获取通配符名称