speedtrans/js/staticfuncs.js

95 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-04-21 14:25:36 +00:00
function npt2ms(npt) {
var ms = 0.0
npt = String(npt);
var p = npt.split(':')
for(i=0;i<p.length;i++)
ms = ms * 60 + parseFloat(p[i])
return ms * 1000;
}
function ms2npt(ms) {
var it, ss, mm, hh, npt;
var it = parseInt(ms / 1000)
ms = ms - it * 1000;
if (ms.toString().length > 3) {
ms = ms.toString().substring(0,3);
}
ss = it % 60;
mm = ((it - ss) / 60) % 60;
hh = ((it - (mm * 60) - ss) / 3600) % 60;
npt = hh+':'+strpad(mm.toString(), '0', 2, 'left')
npt += ':'+strpad(ss.toString(), '0', 2, 'left')
npt += '.'+strpad(ms.toString(), '0', 3, 'left')
return npt;
}
2015-12-20 23:54:18 +00:00
function ms2frames(ms, fmt) {
2015-04-21 14:25:36 +00:00
if (!fmt) var fmt = "PAL";
var npt = ms2npt(ms);
var dotpos = npt.lastIndexOf(".");
var mmStr = npt.substring(dotpos + 1, npt.length);
var mmInt = parseInt(mmStr);
if (fmt == 'PAL') {
var frames = parseInt((mmInt / 1000) * 24);
2015-12-20 23:54:18 +00:00
} else if (fmt == "NTSC") {
2015-04-21 14:25:36 +00:00
var frames = parseInt((mmInt / 1000) * 29.97);
2015-12-20 23:54:18 +00:00
}
2015-04-21 14:25:36 +00:00
var framesTc = '';
var joinToken = ":";
var framesTc = npt.substring(0, dotpos ) + joinToken + frames;
return framesTc;
2015-12-20 23:54:18 +00:00
}
2015-04-21 14:25:36 +00:00
2015-12-20 23:54:18 +00:00
function ms2time(ms) {
var npt = ms2npt(ms)
return npt.substr(npt.length-9, npt.length-6);
}
2015-04-21 14:25:36 +00:00
function framesToNpt(timeCode) {
2015-12-20 23:54:18 +00:00
var frames = timeCode.substring(9, 11);
var ms = parseInt(frames) / 25 * 1000;
var ms = String(ms);
var ms = strpad(ms, '0', 3, 'right');
var timeCodeNpt = timeCode.substring(0,8) + "." + ms;
return timeCodeNpt;
}
2015-04-21 14:25:36 +00:00
function strpad(str, pad, len, dir) {
while (str.length < len) {
if (dir == 'left')
str = pad + str;
else if (dir == 'right')
str = str + pad;
}
return str;
2015-12-20 23:54:18 +00:00
}
2015-04-21 14:25:36 +00:00
function isValidTimecode(tc) {
var tc = $.trim(tc);
var nptRegex = new RegExp("^[0-9][0-9]?\:[0-9][0-9]\:[0-9][0-9][\.|\,|\:][0-9]?[0-9]?[0-9]?$");
return nptRegex.test(tc);to
2015-12-20 23:54:18 +00:00
}
2015-04-21 14:25:36 +00:00
//where filters is a JSON object, for eg. {'Video Files': '*.dv;*.ogg;*.ogv;*.ogx;*.avi;*.mov;*.mp4;*.mpeg;*.mpg;*.vob'}
function selectFile(filters, callback) {
alert('select file');
//fixme. select file
callback && callback(fp);
2015-04-21 14:25:36 +00:00
}
function getFileNameExt(filename) {
var dotPos = filename.lastIndexOf(".");
var ext = filename.substring(dotPos + 1, filename.length);
return ext;
2015-12-20 23:54:18 +00:00
}
2015-04-21 14:25:36 +00:00
function getFileNameSansExt(filename) {
var dotPos = filename.lastIndexOf(".");
if (dotPos != '-1') {
var filenameSansExt = filename.substring(0,dotPos);
} else {
var filenameSansExt = filename;
}
return filenameSansExt;
2015-12-20 23:54:18 +00:00
}