这个问题与另一个问题@ SuperUser有关。
我想下载特德会谈和相应的字幕以便离线查看,例如,让我们以理查德·圣约翰的简短讲话为例,高分辨率视频下载网址如下:
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."从副标题的end:
{
"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是我的首选),我不知道JSON文件中的和键代表E 230。
到目前为止我知道的是:
startTime 从0开始,duration = 3000 = 3000startTime 以184000结尾,duration为2000年= 186000可能还值得注意以下Javascript片段:
introDuration:16500,
adDuration:4000,
postAdDuration:2000,因此,我的问题是,我应该应用什么逻辑将startTime duration 和值转换为.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钉了它,公式如下:
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.发布于 2009-12-23 22:51:05
我的猜测是,json中的时间以毫秒表示,例如1000 =1秒。可能有一个主定时器,其中startTime表示字幕应该出现在时间线上的时间,而持续时间很可能是字幕应该保持在视觉中的时间。186000 / 1000 = 186秒= 186 / 60 = 3.1分钟=3分6秒的除法进一步证实了这一理论。剩下的几秒可能是掌声;-)使用这些信息,您还应该能够计算出从哪个帧到应该将转换应用到哪个帧,也就是说,您已经知道每秒的帧是什么,所以您所需要做的就是将启动时间的秒数与FPS相乘,以获得开始帧。端帧可由:(startTime +持续时间)* fps :-)获得。
发布于 2010-01-05 22:47:15
我制作了一个简单的基于控制台的程序来下载字幕。我在考虑用像油脂猴这样的脚本系统通过网络提供.下面是我的博客链接和代码.:http://estebanordano.com.ar/ted-talks-download-subtitles/
发布于 2012-04-07 23:53:56
我发现了另一个使用这种格式的网站。我很快就黑了一个函数,把它们转换成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')))https://stackoverflow.com/questions/1955618
复制相似问题