这个问题与SuperUser上的另一个问题有关。
我想要下载TED演讲和相应的字幕以供离线观看,例如,就拿Richard St. John的这篇短演讲来说,其高清视频下载URL如下:
相应的JSON编码英文字幕可以在以下位置下载:
这是实际字幕开头的一部分:
{
"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是我的首选),而且我不知道JSON文件中的startTime
和duration
键表示什么。
目前我所知道的是:
- 下载的视频持续时间为3分钟30秒,有29帧每秒=6090帧。
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 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.