-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
vexport.js
185 lines (113 loc) · 3.79 KB
/
vexport.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function exportdata(){
var buttons = document.getElementsByClassName("button")
buttons[0].disabled = true;
buttons[1].disabled = true;
buttons[2].disabled = true;
buttons[3].disabled = true;
buttons[4].disabled = true;
if(source){source.stop()}
clearInterval(intervalid);
clearInterval(videointerval);
if (check!=null && array !== null){
exportflag = 1;
document.getElementById("status").innerHTML = "Exporting in Progress it may take some time";
var canvas = document.getElementById("canvas1")
canvas.width = videoinfo.width;
canvas.height = videoinfo.height
document.getElementById("timer").innerHTML = time;
source = audiocontext.createBufferSource();
var array1 = new Float32Array(array);
var audiobuffer = audiocontext.createBuffer(1, array.length, audiocontext.sampleRate);
var ab1= audiobuffer.getChannelData(0);
ab1.set(array);
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);
var intervalcounter = 1;
setTimeout(()=>{
var init = {
type: 'key',
data: videodata[0],
timestamp: 33+intervalcounter,
duration: 40,
};
var chunk = new EncodedVideoChunk(init);
videoDecoder.decode(chunk);
},0)
intervalcounter = 1;
clearInterval(videointerval);
videointerval = setInterval(()=>{
var init = {
type: 'key',
data: videodata[intervalcounter],
timestamp: 33+intervalcounter,
duration: 40,
};
var chunk = new EncodedVideoChunk(init);
videoDecoder.decode(chunk);
intervalcounter++;
if (intervalcounter>=videodata.length){
clearInterval(videointerval);
}
},1000/videoinfo.samplerate)
source.buffer=audiobuffer;
source.connect(audiocontext.destination);
source.start(0);
const dest = audiocontext.createMediaStreamDestination();
source.connect(dest);
var audiotracks = dest.stream.getAudioTracks();
var canvasstream = canvas.captureStream();
var outputstream = new MediaStream();
var canvastracks = canvasstream.getTracks();
var audiotracks = dest.stream.getAudioTracks()
outputstream.addTrack(canvastracks[0])
outputstream.addTrack(audiotracks[0])
var mediarecorder = new MediaRecorder(outputstream, {mimeType:'video/webm; codecs="vp9, opus"'});
mediarecorder.start();
mediarecorder.ondataavailable=((e)=>{
videochunk.push(e.data)
}
)
mediarecorder.onstop=(()=>{
var blob = new Blob(videochunk, {type:'video/webm'})
const url = URL.createObjectURL(blob);
var anchor = document.createElement('a');
anchor.href = url;
anchor.download = "amooiz.webm"
document.body.appendChild(anchor);
anchor.click();
})
source.onended = function(){
mediarecorder.stop();
exportflag = 0;
canvas.width = videoinfo.width/2;
canvas.height = videoinfo.height/2
var buttons = document.getElementsByClassName("button")
buttons[0].disabled = false;
buttons[1].disabled = false;
buttons[2].disabled = false;
buttons[3].disabled = false;
buttons[4].disabled = false;
}
}
else {
document.getElementById("error").innerHTML = "Please select a file";
}
}