-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvwucut.js
163 lines (95 loc) · 3.94 KB
/
vwucut.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function cut(){
if (videoDecoder.state==="configured"){
videoDecoder.reset();
}
if (videoDecoder.state==="unconfigured"){
var config = {
codec:codecinfo,
codedWidth:videoinfo.width/2,
codedHeight: videoinfo.height/2,
description:avcC,
}
videoDecoder.configure(config);
}
var init = {
type: 'key',
data: keyframe,
timestamp: 2000,
duration: 37,
};
var chunk = new EncodedVideoChunk(init);
videoDecoder.decode(chunk);
clearInterval(intervalid);
clearInterval(videointerval)
var start = parseFloat(document.getElementById("start").value);
var end = parseFloat(document.getElementById("end").value);
time=0;
if(source){
source.stop();
}
if (waveformsource){
waveformsource.stop();
}
document.getElementById("timer").innerHTML = time;
if (check === null ){
document.getElementById("error").innerHTML = "Please select a file"
}
else if (array===null){
document.getElementById("error").innerHTML = "No data available"
}
else if (isNaN(start)){
document.getElementById("error").innerHTML = "Starting point is not a number"
}
else if (start >= source.buffer.duration){
document.getElementById("error").innerHTML = "starting point is greater than or equal to source buffer duration"
}
else if (start < 0 )
{
document.getElementById("error").innerHTML = "Starting Point must be greater than 0"
}
else if (start >= end) {
document.getElementById("error").innerHTML = "Starting Point must be less than Ending Point"
}
else if (isNaN(end)){
document.getElementById("error").innerHTML = "Ending Point is not a number"
}
else if ( end > source.buffer.duration ){
document.getElementById("error").innerHTML = "Ending point is greater than duration"
end < 0 }
else if ( end <= start){
document.getElementById("error").innerHTML = "Ending Point is greater than equal to Starting Point"
}
else{
document.getElementById("timer").innerHTML = time;
var array1;
if (end*source.buffer.sampleRate >= 1){
array1 = array.slice(parseInt(start*audiocontext.sampleRate), parseInt(end*audiocontext.sampleRate));
array = array1;
var array2;
array2 = videodata.slice(parseInt(start*videoinfo.samplerate), parseInt(end*videoinfo.samplerate))
videodata = array2;
document.getElementById("start").value="";
document.getElementById("end").value="";
document.getElementById("totallength").innerHTML=array.length;
}
source = audiocontext.createBufferSource();
array1 = new Float32Array(array);
var audiobuffer = audiocontext.createBuffer(1, array.length, audiocontext.sampleRate);
var ab1= audiobuffer.getChannelData(0);
ab1.set(array);
source.buffer=audiobuffer;
source.connect(audiocontext.destination);
source.start(0,0,0)
sourceduration = source.buffer.duration;
document.getElementById("duration").innerHTML = source.buffer.duration.toFixed(3);
if (source.buffer.duration>=1){
intervalid = setInterval(()=>{
time++;
document.getElementById("timer").innerHTML = time;
if (time === parseInt(source.buffer.duration)){
clearInterval(intervalid);
}
}, 1000);
}
}
}