-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.js
More file actions
533 lines (506 loc) · 15.9 KB
/
Copy pathMainPage.js
File metadata and controls
533 lines (506 loc) · 15.9 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
function generatecommand()
{
// 输出命令的textarea
var outputplace = document.getElementById("outputcommand");
// 输入文件的地址
var inputfile = document.getElementById("filesrc").value;
if (inputfile[0] != "\"")
{
inputfile = "\"" + inputfile;
}
if (inputfile[inputfile.length - 1] != "\"")
{
inputfile += "\"";
}
// 输出文件的名字,可以留空
var outputfile = document.getElementById("outputfilename").value;
// 输出文件的地址,可以留空
var outputdir = document.getElementById("outputdir").value;
// 视频选项
// 输出视频的分辨率,可以留空
var videowidth = document.getElementById("videowidth").value;
var videoheight = document.getElementById("videoheight").value;
// 输出视频的比特率,可以留空
var videobyterate = document.getElementById("videobyte").value;
// 输出视频的帧数,可以留空
var videofps = document.getElementById("videofps").value;
// 输出视频的速度,可以留空,注意检查状态
var videopresent = document.getElementById("videoPresent").value;
// 输入视频的解码器
var videodecoder = document.getElementById('videoDecoder').value;
// 输出视频的编码器
var videoencoder = document.getElementById("videoEncoder").value;
// 音频选项
// 输出音频的编码器
var audioencoder = document.getElementById("audioEncoder").value;
// 特殊选项
// 简略信息
var shortinfo = document.getElementById("hideMessage").checked;
// 询问是否覆盖输出目录下的同名文件,选中则不询问
var overwrite = document.getElementById("overwrite").checked;
// 选择编码过程中是否显示编码进度
var showEncodingStatus = document.getElementById("showEncodingStatus").checked;
// 不输出视频
var noVideo = document.getElementById("noVideoOut").checked;
// 不输出音频
var noAudio = document.getElementById("noAudioOut").checked;
// 命令的初始部分,后续添加参数
var command = "ffmpeg ";
// 这里添加参数
if (videodecoder)
{
// 输入视频解码器
command += "-hwaccel " + videodecoder + " ";
}
if (inputfile)
{
// 输入文件
command += "-i " + inputfile + " ";
// 必须先写设定参数
// 输出视频编码器,可以留空
if (videoencoder)
{
command += "-c:v " + videoencoder + " ";
}
// 输出音频编码器,可以留空
if (audioencoder)
{
command += "-c:a " + audioencoder + " ";
}
// 输出视频分辨率,可以留空
if (videowidth && videoheight)
{
command += "-s " + videowidth + "x" + videoheight + " ";
}
// 输出视频比特率,单位kbps,可以留空
if (videobyterate)
{
command += "-b:v " + videobyterate + "k ";
}
// 设置输出视频帧数,单位fps,可以留空,默认和原视频一样
if (videofps)
{
command += "-r " + videofps + " ";
}
// 设置输出视频速度,可以留空,默认为medium
if (videopresent)
{
command += "-preset " + videopresent + " ";
}
// 输出目录存在与输出文件同名的文件时是否覆盖,默认为否,勾选则添加参数
if (overwrite)
{
command += "-y ";
}
// 选择编码过程中是否显示编码进度
if (showEncodingStatus)
{
command += "-stats ";
}
// 特殊选项
// 简略信息
if (shortinfo)
{
command += "-hide_banner ";
}
// 不输出视频和音频
if (noVideo && noAudio)
{
alert("不输出视频和音频的情况下没有意义,不能执行");
}
else
{
// 不输出视频
if (noVideo)
{
command += "-vn ";
}
// 不输出音频
if (noAudio)
{
command += "-an ";
}
}
// 最后填写输出文件名
// 如果有填写输出文件名
if (outputfile)
{
// 如果有填写输出文件夹就拼接地址
if (outputdir)
{
if (outputdir[0] != "\"")
{
command += "\"";
}
if (outputdir[outputdir.length - 1] == "\"")
{
outputdir = outputdir.substring(0, outputdir.length - 1);
}
command += outputdir;
if (outputdir[outputdir.length - 1] != "\\")
{
command += "\\";
}
command += outputfile.split("\\")[outputfile.split("\\").length - 1];
if (outputfile[outputfile.length - 1] != "\"")
{
command += "\"";
}
}
// 没有就不管
else
{
if (inputfile[0] != "\"")
{
command += "\"";
}
var temp = inputfile.split("\\");
// 分割文件夹,拼接输出地址
for (var i = 0; i < temp.length; i++)
{
if (i != temp.length - 1)
{
command += temp[i] + "\\";
}
}
command += outputfile;
if (command[command.length - 1] != "\"")
{
command += "\"";
}
}
}
// 如果没有填写输出文件名
else
{
// 如果有填写输出文件夹就拼接地址
if (outputdir)
{
if (outputdir[0] != "\"")
{
command += "\"";
}
if (outputdir[outputdir.length - 1] == "\"")
{
outputdir = outputdir.substring(0, outputdir.length - 1);
}
command += outputdir;
if (outputdir[outputdir.length - 1] != "\\")
{
command += "\\";
}
var filename = inputfile.split("\\")[inputfile.split("\\").length - 1];
var temp = filename.split(".");
// 防止文件名中有.的情况
for (var i = 0; i < temp.length; i++)
{
command += temp[i];
// console.log(temp[i]);
if (i == temp.length - 2)
{
command += "_ffmpeg.";
}
else if (i == temp.length - 1)
{
command += " ";
}
else
{
command += ".";
}
}
}
// 没有就不管
else
{
var temp = inputfile.split(".");
// 防止文件名中有.的情况
for (var i = 0; i < temp.length; i++)
{
command += temp[i];
// console.log(temp[i]);
if (i == temp.length - 2)
{
command += "_ffmpeg.";
}
else if (i == temp.length - 1)
{
command += " ";
}
else
{
command += ".";
}
}
}
}
}
// 报错,没有输入文件地址
else
{
alert("请输入文件地址,必须是绝对地址");
}
// 输出命令
outputplace.innerHTML = command;
}
// 复制命令
function clicktocopy()
{
console.log("clicktocopy");
var text = document.getElementById("outputcommand").value;
navigator.clipboard.writeText(text).then(function () { alert("复制成功"); }, function () { alert("复制失败"); });
}
// 一键导出
function clicktoexport(width, height, fps, byte)
{
// 输出命令的textarea
var outputplace = document.getElementById("outputcommand");
// 输入文件的地址
var inputfile = document.getElementById("filesrc").value;
// 输出文件的名字,可以留空
var outputfile = document.getElementById("outputfilename").value;
// 输出文件的地址,可以留空
var outputdir = document.getElementById("outputdir").value;
// 输出视频的分辨率
var videowidth = width;
var videoheight = height;
// 输出视频的比特率
var videobyterate = byte;
// 输出视频的帧数
var videofps = fps;
// 命令的初始部分,后续添加参数
var command = "ffmpeg ";
// 这里添加参数
if (inputfile)
{
// 输入文件
command += "-i " + inputfile + " ";
// 必须先写设定参数
// 输出视频分辨率
command += "-s " + videowidth + "x" + videoheight + " ";
// 输出视频比特率,单位kbps
command += "-b:v " + videobyterate + "k ";
// 设置输出视频帧数,单位fps
command += "-r " + videofps + " ";
// 最后填写输出文件名
// 如果有填写输出文件名
if (outputfile)
{
// 如果有填写输出文件夹就拼接地址
if (outputdir)
{
if (outputdir[0] != "\"")
{
command += "\"";
}
if (outputdir[outputdir.length - 1] == "\"")
{
outputdir = outputdir.substring(0, outputdir.length - 1);
}
command += outputdir;
if (outputdir[outputdir.length - 1] != "\\")
{
command += "\\";
}
command += outputfile.split("\\")[outputfile.split("\\").length - 1];
if (outputfile[outputfile.length - 1] != "\"")
{
command += "\"";
}
}
// 没有就不管
else
{
if (inputfile[0] != "\"")
{
command += "\"";
}
var temp = inputfile.split("\\");
// 分割文件夹,拼接输出地址
for (var i = 0; i < temp.length; i++)
{
if (i != temp.length - 1)
{
command += temp[i] + "\\";
}
}
command += outputfile;
if (command[command.length - 1] != "\"")
{
command += "\"";
}
}
}
// 如果没有填写输出文件名
else
{
// 如果有填写输出文件夹就拼接地址
if (outputdir)
{
if (outputdir[0] != "\"")
{
command += "\"";
}
if (outputdir[outputdir.length - 1] == "\"")
{
outputdir = outputdir.substring(0, outputdir.length - 1);
}
command += outputdir;
if (outputdir[outputdir.length - 1] != "\\")
{
command += "\\";
}
var filename = inputfile.split("\\")[inputfile.split("\\").length - 1];
var temp = filename.split(".");
// 防止文件名中有.的情况
for (var i = 0; i < temp.length; i++)
{
command += temp[i];
// console.log(temp[i]);
if (i == temp.length - 2)
{
command += "_ffmpeg.";
}
else if (i == temp.length - 1)
{
command += " ";
}
else
{
command += ".";
}
}
}
// 没有就不管
else
{
var temp = inputfile.split(".");
// command += temp[0] + "_ffmpeg." + temp[1];
// 防止文件名中有.的情况
for (var i = 0; i < temp.length; i++)
{
command += temp[i];
// console.log(temp[i]);
if (i == temp.length - 2)
{
command += "_ffmpeg.";
}
else if (i == temp.length - 1)
{
command += " ";
}
else
{
command += ".";
}
}
}
}
}
// 报错,没有输入文件地址
else
{
alert("请输入文件地址,必须是绝对地址");
}
// 输出命令
outputplace.innerHTML = command;
}
// 预设选项卡展开和收起
function dis()
{
var dis01 = document.getElementById("dis01");
var dis02 = document.getElementById("dis02");
var dis03 = document.getElementById("dis03");
dis01.hidden = !dis01.hidden;
dis02.hidden = !dis02.hidden;
dis03.hidden = !dis03.hidden;
}
// websocket
let ws;
function startwebsocket(e)
{
try
{
if (!ws)
{
ws = new WebSocket("ws://localhost:1652");
}
}
catch
{
alert("浏览器不支持websocket");
}
// start websocket
if (e == 0)
{
ws.onopen = function (event)
{
console.log("ws启动");
var time = new Date();
ws.send("start " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());
}
ws.onmessage = function (event)
{
console.log("ws收到消息" + event.data);
if (event.data == "run command")
{
var output = document.getElementById("wsState");
output.innerHTML = "运行命令完成";
}
}
ws.onerror = function (event)
{
console.log("ws报错" + event.data);
}
ws.onclose = function (event)
{
console.log("ws关闭");
}
ckws();
}
// send message to websocket
else if (e == 1)
{
senttowebsocket();
}
// check websocket readyState
function ckws()
{
var state = ws.readyState;
var output = document.getElementById("wsState");
if (state == 0)
{
output.innerHTML = "正在连接:Connecting";
}
else if (state == 1)
{
output.innerHTML = "已连接:Connected";
}
else if (state == 2)
{
output.innerHTML = "正在关闭:Closing";
}
else if (state == 3)
{
output.innerHTML = "已关闭:Closed";
}
if (timeout)
{
clearTimeout(timeout);
}
var timeout = setTimeout(ckws, 1000);
}
// 发送命令到后台webserver服务器
function senttowebsocket()
{
var command = document.getElementById("outputcommand").value;
console.log(command);
ws.send(command);
}
}
// 查看支持的编码器
function _encoders()
{
var output = document.getElementById("outputcommand");
output.innerHTML = "ffmpeg -encoders";
}