-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.js
89 lines (76 loc) · 3.02 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var moment = require('moment');
exports = module.exports = {
getXmlFileNameFromClip: function(clip) {
return clip.playlist_id + "$" + clip.id + ".xml";
},
getPlaylistIdFromXmlFileName: function(filename) {
var aux = filename.split("$");
if ( aux.length > 0 ) {
filename = aux[0];
}
return filename;
},
getClipIdFromXmlFileName: function(filename) {
// return everything between the first - and .xml
var match = filename.match(/^[^\$]+\$(.*)\.xml$/);
if( match ) {
return match[1];
}
return filename;
},
getTimeLengthFromFrames: function(frames, fps) {
var seconds = parseFloat(frames) / parseFloat(fps);
var minutes = 0;
if (seconds > 60) {
minutes = parseInt(seconds / 60);
seconds = parseInt (seconds - (minutes * 60));
}
var hours = 0;
if (minutes > 60) {
hours = parseInt(hours / 60);
minutes = parseInt(minutes - (hours * 60));
}
return "." + hours + ":" + minutes + ":" + seconds;
},
getCurrentPosFromClip: function(actualFrame, totalFrames) {
return parseFloat(actualFrame / totalFrames);
},
getFramePositionFromClock: function( clock_position, clip_start, frames_length, fps ) {
var millis = moment.duration( clock_position - clip_start ).asMilliseconds();
var frame_position = Math.max( (millis / 1000.0 ) * fps, frames_length - 1);
return frame_position;
},
convertFramesToSeconds: function ( frames, fps ) {
return frames/fps;
},
convertLengthToMilliseconds: function ( frames ) {
var m = moment( frames, "HH:mm:ss.SS");
return m.hours()*60*60*1000 + m.minutes()*60*1000 + m.seconds()*1000 + m.milliseconds();
},
convertFramesToMilliseconds: function ( frames, fps ) {
if ( isNaN(frames) || fps+""=="NaN" || fps==undefined || fps===false || fps==0) {
var m = moment( frames, "HH:mm:ss.SS");
if (m) return m.hours()*60*60*1000 + m.minutes()*60*1000 + m.seconds()*1000 + m.milliseconds();
}
fps = parseFloat(fps);
var millis = frames * 1000.0 / (1.0 * fps);
if (millis!==undefined) return millis;
},
convertDurationToString: function( moment_duration ) {
return moment_duration.hours()+":"+moment_duration.minutes()+":"+moment_duration.seconds()+"."+moment_duration.milliseconds();
},
convertUnixToDate: function ( unix_timestamp ) {
//var date = new Date(unix_timestamp*1000);
var date = new moment(unix_timestamp);
return date.format("hh:mm:ss");
},
convertDateToUnix: function ( date_timestamp ) {
var date = new moment(date_timestamp);
return date.unix();
},
convertTimeToFrames: function(time, fps) {
var mTime = moment(time, "HH:mm:ss");
var seconds = mTime.seconds() + (mTime.minutes() * 60) + (mTime.hours() * 60 * 60);
return seconds * fps;
}
};