-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
994 lines (908 loc) · 32.1 KB
/
index.html
File metadata and controls
994 lines (908 loc) · 32.1 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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Discord用 動画カット&圧縮ツール</title>
<meta name="description" content="Discord無料プランの10MB制限に対応。ブラウザ上で動画をカット・圧縮してWebM形式で出力。サーバーアップロード不要、完全ローカル処理。" />
<meta name="author" content="wory-bonbon" />
<!-- OGP -->
<meta property="og:title" content="Discord用 動画カット&圧縮ツール" />
<meta property="og:description" content="10MB制限対応。ブラウザ上で動画をカット・圧縮。完全ローカル処理。" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://wory-bonbon.github.io/discord-video-compressor/" />
<meta name="twitter:card" content="summary" />
<style>
* {
box-sizing: border-box;
}
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
margin: 0;
padding: 24px 32px;
background: #fafafa;
color: #1f2937;
min-height: 100vh;
}
/* ===== 画面全体でドロップ受付 ===== */
body.dragover::after {
content: 'ここにドロップ';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(168, 139, 250, 0.15);
font-size: 24px;
font-weight: 600;
color: #7c3aed;
pointer-events: none;
z-index: 1000;
border: 3px dashed #a78bfa;
}
/* ===== ヘッダー ===== */
header {
margin-bottom: 20px;
}
header h1 {
font-size: 22px;
font-weight: 700;
margin: 0 0 8px 0;
color: #111827;
}
header p {
font-size: 14px;
color: #6b7280;
margin: 0;
}
header .drop-hint {
color: #7c3aed;
font-weight: 500;
}
header a {
color: #7c3aed;
text-decoration: none;
font-weight: 500;
}
header a:hover {
text-decoration: underline;
}
/* ===== 動画セクション(左右レイアウト) ===== */
.video-container {
display: flex;
gap: 20px;
}
@media (max-width: 900px) {
.video-container {
flex-direction: column;
}
}
.video-panel {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.video-panel-label {
font-size: 13px;
font-weight: 600;
margin-bottom: 10px;
padding: 8px 14px;
border-radius: 8px;
display: inline-flex;
align-items: center;
gap: 6px;
}
.video-panel.original .video-panel-label,
.video-panel.preview .video-panel-label {
background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
color: #4338ca;
}
/* ===== チェッカーパターン背景 ===== */
.video-wrapper {
position: relative;
border-radius: 12px;
overflow: hidden;
flex: 1;
display: flex;
flex-direction: column;
/* チェッカーパターン */
background-color: #ffffff;
background-image:
linear-gradient(45deg, rgba(0,0,0,0.04) 25%, transparent 25%, transparent 75%, rgba(0,0,0,0.04) 75%),
linear-gradient(45deg, rgba(0,0,0,0.04) 25%, transparent 25%, transparent 75%, rgba(0,0,0,0.04) 75%);
background-size: 16px 16px;
background-position: 0 0, 8px 8px;
/* 境界線 */
border: 1px solid rgba(0,0,0,0.08);
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.video-wrapper video {
width: 100%;
height: 100%;
min-height: 300px;
max-height: 58vh;
object-fit: contain;
display: block;
}
/* ===== タイムラインマーカー ===== */
.timeline-section {
margin-top: 12px;
}
.timeline-container {
position: relative;
height: 32px;
background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
border-radius: 8px;
cursor: pointer;
border: 1px solid rgba(0,0,0,0.06);
}
.timeline-progress {
height: 100%;
background: linear-gradient(135deg, #c4b5fd 0%, #a78bfa 100%);
border-radius: 8px;
width: 0%;
opacity: 0.5;
}
.timeline-marker {
position: absolute;
top: -2px;
transform: translateX(-50%);
font-size: 18px;
line-height: 1;
cursor: ew-resize;
user-select: none;
filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
}
.timeline-marker.start {
color: #7c3aed;
}
.timeline-marker.end {
color: #ec4899;
}
.timeline-marker-label {
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
font-size: 10px;
font-weight: 600;
white-space: nowrap;
margin-top: 4px;
background: #fff;
padding: 2px 6px;
border-radius: 4px;
color: #6b7280;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.timeline-time {
display: flex;
justify-content: space-between;
font-size: 11px;
color: #9ca3af;
margin-top: 6px;
font-weight: 500;
}
/* ===== コントロール ===== */
.controls {
margin-top: 20px;
display: flex;
flex-wrap: wrap;
gap: 16px;
align-items: flex-start;
padding: 16px 20px;
background: #fff;
border-radius: 12px;
border: 1px solid rgba(0,0,0,0.06);
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.control-item {
display: flex;
flex-direction: column;
}
.control-item label {
font-size: 11px;
font-weight: 600;
color: #6b7280;
margin-bottom: 6px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.control-item input[type="text"],
.control-item select {
padding: 10px 12px;
background: #f9fafb;
color: #1f2937;
border: 1px solid #e5e7eb;
border-radius: 8px;
min-width: 100px;
height: 42px;
font-size: 14px;
font-weight: 500;
transition: border-color 0.15s, box-shadow 0.15s;
}
.control-item input[type="text"]:focus,
.control-item select:focus {
outline: none;
border-color: #a78bfa;
box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.15);
}
.control-hint {
font-size: 10px;
color: #9ca3af;
margin-top: 4px;
min-height: 14px;
}
.control-item button {
height: 42px;
padding: 0 24px;
background: linear-gradient(135deg, #a78bfa 0%, #7c3aed 100%);
border: none;
border-radius: 8px;
color: #fff;
cursor: pointer;
font-size: 14px;
font-weight: 600;
transition: transform 0.1s, box-shadow 0.15s;
box-shadow: 0 2px 8px rgba(124, 58, 237, 0.25);
}
.control-item button:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}
.control-item button:active {
transform: translateY(0);
}
.control-item button:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
/* ===== 音声削除トグル ===== */
.toggle-item {
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.toggle-item label {
font-size: 11px;
font-weight: 600;
color: #6b7280;
margin-bottom: 6px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.toggle-switch {
position: relative;
width: 52px;
height: 42px;
display: flex;
align-items: center;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-slider {
position: absolute;
cursor: pointer;
top: 50%;
transform: translateY(-50%);
left: 0;
width: 48px;
height: 26px;
background-color: #e5e7eb;
border-radius: 26px;
transition: 0.2s;
}
.toggle-slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 3px;
top: 3px;
background-color: white;
border-radius: 50%;
transition: 0.2s;
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider {
background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
}
.toggle-switch input:checked + .toggle-slider:before {
transform: translateX(22px);
}
.toggle-label-text {
font-size: 10px;
color: #9ca3af;
margin-top: 4px;
min-height: 14px;
white-space: nowrap;
}
.toggle-switch input:checked ~ .toggle-label-text {
color: #ef4444;
}
/* ===== ステータス/情報 ===== */
.status-bar {
margin-top: 16px;
padding: 14px 18px;
background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
border-radius: 10px;
font-size: 13px;
color: #4b5563;
text-align: center;
border: 1px solid rgba(0,0,0,0.04);
}
.status-bar.error {
background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
color: #b91c1c;
border-color: rgba(185, 28, 28, 0.1);
}
.size-info {
margin-top: 10px;
font-size: 13px;
color: #6b7280;
text-align: center;
font-weight: 500;
}
.re-preview-hint {
margin-top: 8px;
font-size: 12px;
color: #f59e0b;
text-align: center;
font-weight: 500;
}
.download-link {
display: none;
margin: 16px auto 0;
padding: 14px 32px;
background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
color: #fff;
text-decoration: none;
border-radius: 10px;
font-weight: 600;
font-size: 15px;
text-align: center;
box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
transition: transform 0.1s, box-shadow 0.15s;
}
.download-link:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}
/* ===== 情報カード ===== */
.info-cards {
margin-top: 24px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 16px;
}
.info-card {
background: #fff;
border-radius: 12px;
padding: 18px 20px;
border: 1px solid rgba(0,0,0,0.06);
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.info-card h3 {
font-size: 13px;
font-weight: 700;
color: #374151;
margin: 0 0 12px 0;
display: flex;
align-items: center;
gap: 6px;
}
.info-card table {
width: 100%;
font-size: 12px;
border-collapse: collapse;
}
.info-card th,
.info-card td {
padding: 6px 8px;
text-align: left;
border-bottom: 1px solid #f3f4f6;
}
.info-card th {
color: #6b7280;
font-weight: 500;
}
.info-card td {
color: #374151;
}
.info-card ul {
margin: 0;
padding-left: 18px;
font-size: 12px;
color: #4b5563;
line-height: 1.7;
}
/* ===== フッター ===== */
footer {
margin-top: 32px;
padding-top: 16px;
border-top: 1px solid #e5e7eb;
font-size: 12px;
color: #9ca3af;
text-align: center;
}
footer a {
color: #7c3aed;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<!-- ヘッダー -->
<header>
<h1>Discord用 動画カット&圧縮ツール</h1>
<p>
<span class="drop-hint">画面全体にドラッグ&ドロップ</span>、
または <a href="#" id="fileSelectLink">ファイルを選択</a>
<input type="file" id="fileInput" accept="video/*" hidden />
</p>
</header>
<!-- 動画セクション -->
<div class="video-container" id="videoContainer" hidden>
<!-- 元動画パネル -->
<div class="video-panel original">
<div class="video-panel-label">📹 元動画</div>
<div class="video-wrapper">
<video id="video" controls></video>
</div>
<!-- タイムラインマーカー -->
<div class="timeline-section">
<div class="timeline-container" id="timeline">
<div class="timeline-progress" id="timelineProgress"></div>
<div class="timeline-marker start" id="startMarker">▼
<span class="timeline-marker-label" id="startMarkerLabel">0:00</span>
</div>
<div class="timeline-marker end" id="endMarker">▼
<span class="timeline-marker-label" id="endMarkerLabel">0:00</span>
</div>
</div>
<div class="timeline-time">
<span>0:00</span>
<span id="durationDisplay">0:00</span>
</div>
</div>
</div>
<!-- プレビューパネル -->
<div class="video-panel preview">
<div class="video-panel-label">✨ プレビュー</div>
<div class="video-wrapper">
<video id="previewVideo" controls></video>
</div>
</div>
</div>
<!-- コントロール -->
<div class="controls" id="controls" hidden>
<div class="control-item">
<label>スタート (秒)</label>
<input type="text" id="startTime" value="0" />
<span class="control-hint">ホイールで±1秒</span>
</div>
<div class="control-item">
<label>エンド (秒)</label>
<input type="text" id="endTime" value="0" />
<span class="control-hint">ホイールで±1秒</span>
</div>
<div class="control-item">
<label>解像度</label>
<select id="resolution">
<option value="original">オリジナル</option>
<option value="1920">1920px</option>
<option value="1280" selected>1280px</option>
<option value="960">960px</option>
<option value="640">640px</option>
<option value="480">480px</option>
</select>
<span class="control-hint">スクロールで変更</span>
</div>
<div class="control-item">
<label>ビットレート</label>
<select id="bitrate">
<option value="8000">8,000 kbps</option>
<option value="6000">6,000 kbps</option>
<option value="4000" selected>4,000 kbps</option>
<option value="2500">2,500 kbps</option>
<option value="1500">1,500 kbps</option>
<option value="1000">1,000 kbps</option>
</select>
<span class="control-hint">スクロールで変更</span>
</div>
<div class="control-item">
<label>再生速度</label>
<select id="playbackSpeed">
<option value="0.5">0.5x</option>
<option value="0.75">0.75x</option>
<option value="1" selected>1x</option>
<option value="1.25">1.25x</option>
<option value="1.5">1.5x</option>
<option value="2">2x</option>
</select>
<span class="control-hint">タイムラプス風</span>
</div>
<div class="control-item toggle-item">
<label>音声</label>
<label class="toggle-switch">
<input type="checkbox" id="muteAudio" />
<span class="toggle-slider"></span>
</label>
<span class="toggle-label-text" id="muteLabel">🔊 音声あり</span>
</div>
<div class="control-item" style="margin-left: auto;">
<label> </label>
<button id="previewBtn" disabled>▶ プレビュー</button>
<span class="control-hint"></span>
</div>
</div>
<!-- ステータス -->
<div class="status-bar" id="statusBar">動画ファイルをドロップしてください。</div>
<div class="size-info" id="sizeInfo"></div>
<div class="re-preview-hint" id="rePreviewHint" hidden>💡 音声削除を反映するには再度プレビューしてください</div>
<a class="download-link" id="downloadLink" download="discord_clip.webm">⬇ ダウンロード</a>
<!-- 情報カード -->
<div class="info-cards" id="infoCards" hidden>
<div class="info-card">
<h3>📊 10MB制限の目安</h3>
<table>
<tr><th>長さ</th><th>解像度</th><th>ビットレート</th></tr>
<tr><td>8秒</td><td>1920px</td><td>6,000〜8,000 kbps</td></tr>
<tr><td>15秒</td><td>1280px</td><td>4,000〜5,000 kbps</td></tr>
<tr><td>30秒</td><td>960px</td><td>2,000〜2,500 kbps</td></tr>
<tr><td>45秒</td><td>640px</td><td>1,200〜1,600 kbps</td></tr>
</table>
</div>
<div class="info-card">
<h3>💡 使い方のヒント</h3>
<ul>
<li>タイムラインの🔽マーカーをドラッグして範囲指定</li>
<li>各入力欄でマウスホイールを回すと値を調整可能</li>
<li>プレビューで確認後、ダウンロードボタンで保存</li>
<li>音声削除でファイルサイズを更に削減可能</li>
</ul>
</div>
</div>
<!-- フッター -->
<footer>
出力形式: WebM (VP9/VP8 + Opus) | 完全ローカル処理 |
<a href="https://github.com/wory-bonbon/discord-video-compressor" target="_blank">GitHub</a>
</footer>
<script>
const video = document.getElementById('video');
const previewVideo = document.getElementById('previewVideo');
const startTimeInput = document.getElementById('startTime');
const endTimeInput = document.getElementById('endTime');
const resolutionSelect = document.getElementById('resolution');
const bitrateSelect = document.getElementById('bitrate');
const playbackSpeedSelect = document.getElementById('playbackSpeed');
const muteAudioCheckbox = document.getElementById('muteAudio');
const muteLabel = document.getElementById('muteLabel');
const previewBtn = document.getElementById('previewBtn');
const statusBar = document.getElementById('statusBar');
const sizeInfoEl = document.getElementById('sizeInfo');
const downloadLink = document.getElementById('downloadLink');
const videoContainer = document.getElementById('videoContainer');
const controls = document.getElementById('controls');
const infoCardsEl = document.getElementById('infoCards');
const durationDisplay = document.getElementById('durationDisplay');
const fileInput = document.getElementById('fileInput');
const fileSelectLink = document.getElementById('fileSelectLink');
const timeline = document.getElementById('timeline');
const timelineProgress = document.getElementById('timelineProgress');
const startMarker = document.getElementById('startMarker');
const endMarker = document.getElementById('endMarker');
const startMarkerLabel = document.getElementById('startMarkerLabel');
const endMarkerLabel = document.getElementById('endMarkerLabel');
const rePreviewHint = document.getElementById('rePreviewHint');
let videoDuration = 0;
let recording = false;
let lastPreviewHadAudio = false;
// ========== 音声トグル ==========
muteAudioCheckbox.addEventListener('change', () => {
if (muteAudioCheckbox.checked) {
muteLabel.textContent = '🔇 音声削除';
muteLabel.style.color = '#ef4444';
// 音声ありでプレビュー済みなら再プレビューを促す
if (lastPreviewHadAudio) {
rePreviewHint.hidden = false;
}
} else {
muteLabel.textContent = '🔊 音声あり';
muteLabel.style.color = '#9ca3af';
rePreviewHint.hidden = true;
}
});
// ========== ユーティリティ ==========
function formatTime(sec) {
const m = Math.floor(sec / 60);
const s = Math.floor(sec % 60);
return `${m}:${s.toString().padStart(2, '0')}`;
}
function humanSize(bytes) {
if (bytes < 1024) return bytes + ' B';
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
}
function setStatus(msg, isError = false) {
statusBar.textContent = msg;
statusBar.classList.toggle('error', isError);
}
function updateMarkers() {
const start = parseFloat(startTimeInput.value) || 0;
const end = parseFloat(endTimeInput.value) || videoDuration;
if (videoDuration <= 0) return;
const startPercent = (start / videoDuration) * 100;
const endPercent = (end / videoDuration) * 100;
startMarker.style.left = startPercent + '%';
endMarker.style.left = endPercent + '%';
startMarkerLabel.textContent = formatTime(start);
endMarkerLabel.textContent = formatTime(end);
}
function updateTimelineProgress() {
if (videoDuration <= 0) return;
const percent = (video.currentTime / videoDuration) * 100;
timelineProgress.style.width = percent + '%';
}
// ========== ホイール操作 ==========
function attachWheelToInput(el, min, maxFn, step) {
el.addEventListener('wheel', (e) => {
e.preventDefault();
let val = parseFloat(el.value) || 0;
const max = typeof maxFn === 'function' ? maxFn() : maxFn;
if (e.deltaY < 0) {
val = Math.min(max, val + step);
} else {
val = Math.max(min, val - step);
}
el.value = val.toFixed(1);
el.dispatchEvent(new Event('change'));
});
}
function attachScrollSelect(select) {
select.addEventListener('wheel', (e) => {
e.preventDefault();
let idx = select.selectedIndex;
if (e.deltaY < 0) {
if (idx > 0) idx--;
} else {
if (idx < select.options.length - 1) idx++;
}
select.selectedIndex = idx;
});
}
attachWheelToInput(startTimeInput, 0, () => videoDuration, 1);
attachWheelToInput(endTimeInput, 0, () => videoDuration, 1);
attachScrollSelect(resolutionSelect);
attachScrollSelect(bitrateSelect);
attachScrollSelect(playbackSpeedSelect);
startTimeInput.addEventListener('focus', () => startTimeInput.select());
endTimeInput.addEventListener('focus', () => endTimeInput.select());
// ========== ファイル読み込み ==========
async function handleFile(file) {
if (!file || !file.type.startsWith('video/')) {
setStatus('動画ファイルを選択してください。', true);
return;
}
const url = URL.createObjectURL(file);
video.src = url;
await video.play().catch(() => {});
video.pause();
video.currentTime = 0;
videoDuration = video.duration;
startTimeInput.value = '0';
endTimeInput.value = Math.floor(videoDuration).toString();
durationDisplay.textContent = formatTime(videoDuration);
videoContainer.hidden = false;
controls.hidden = false;
infoCardsEl.hidden = false;
previewBtn.disabled = false;
previewVideo.src = '';
updateMarkers();
setStatus('動画を読み込みました。範囲とパラメータを設定してください。');
sizeInfoEl.textContent = '';
downloadLink.style.display = 'none';
lastPreviewHadAudio = false;
rePreviewHint.hidden = true;
}
// ========== バリデーション ==========
function validateTimes() {
const startVal = parseFloat(startTimeInput.value);
const endValRaw = parseFloat(endTimeInput.value);
if (isNaN(startVal) || isNaN(endValRaw)) return;
if (endValRaw > videoDuration) {
endTimeInput.value = Math.floor(videoDuration).toString();
}
if (startVal >= endValRaw) {
setStatus('エンド時間はスタートより大きい値にしてください。', true);
} else {
setStatus('');
}
updateMarkers();
}
startTimeInput.addEventListener('change', validateTimes);
endTimeInput.addEventListener('change', validateTimes);
startTimeInput.addEventListener('input', updateMarkers);
endTimeInput.addEventListener('input', updateMarkers);
video.addEventListener('timeupdate', updateTimelineProgress);
// タイムラインクリックでシーク
timeline.addEventListener('click', (e) => {
const rect = timeline.getBoundingClientRect();
const percent = (e.clientX - rect.left) / rect.width;
video.currentTime = percent * videoDuration;
});
// マーカードラッグ
let draggingMarker = null;
function startDrag(marker, inputEl) {
return (e) => {
e.stopPropagation();
draggingMarker = { marker, inputEl };
document.addEventListener('mousemove', onDrag);
document.addEventListener('mouseup', stopDrag);
};
}
function onDrag(e) {
if (!draggingMarker) return;
const rect = timeline.getBoundingClientRect();
let percent = (e.clientX - rect.left) / rect.width;
percent = Math.max(0, Math.min(1, percent));
const time = percent * videoDuration;
draggingMarker.inputEl.value = time.toFixed(1);
validateTimes();
updateMarkers();
}
function stopDrag() {
draggingMarker = null;
document.removeEventListener('mousemove', onDrag);
document.removeEventListener('mouseup', stopDrag);
}
startMarker.addEventListener('mousedown', startDrag(startMarker, startTimeInput));
endMarker.addEventListener('mousedown', startDrag(endMarker, endTimeInput));
// ========== 録画処理 ==========
async function recordClip() {
if (recording) return;
const start = parseFloat(startTimeInput.value) || 0;
const end = parseFloat(endTimeInput.value) || videoDuration;
const playbackSpeed = parseFloat(playbackSpeedSelect.value) || 1;
const muteAudio = muteAudioCheckbox.checked;
let width;
if (resolutionSelect.value === 'original') {
width = video.videoWidth;
} else {
width = parseInt(resolutionSelect.value);
}
const bitrate = parseInt(bitrateSelect.value) * 1000;
const height = Math.round(video.videoHeight * width / video.videoWidth);
recording = true;
previewBtn.disabled = true;
rePreviewHint.hidden = true;
setStatus('録画を開始します…');
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
const canvasStream = canvas.captureStream();
// 音声トラック追加(muteがOFFの場合のみ)
if (!muteAudio) {
const audioTracks = video.captureStream().getAudioTracks();
if (audioTracks.length > 0) {
canvasStream.addTrack(audioTracks[0]);
}
}
let mimeType = 'video/webm';
if (MediaRecorder.isTypeSupported('video/webm;codecs=vp9,opus')) {
mimeType = 'video/webm;codecs=vp9,opus';
} else if (MediaRecorder.isTypeSupported('video/webm;codecs=vp8,opus')) {
mimeType = 'video/webm;codecs=vp8,opus';
}
const recorder = new MediaRecorder(canvasStream, {
mimeType: mimeType,
videoBitsPerSecond: bitrate,
});
const chunks = [];
recorder.ondataavailable = (e) => {
if (e.data && e.data.size > 0) chunks.push(e.data);
};
recorder.onstop = () => {
const blob = new Blob(chunks, { type: recorder.mimeType });
const sizeMB = blob.size / (1024 * 1024);
if (blob.size === 0) {
setStatus('録画に失敗しました。設定を調整してください。', true);
sizeInfoEl.textContent = '出力サイズ: 0.00 MB';
downloadLink.style.display = 'none';
recording = false;
previewBtn.disabled = false;
return;
}
const url = URL.createObjectURL(blob);
previewVideo.src = url;
previewVideo.currentTime = 0;
previewVideo.play().catch(() => {});
downloadLink.href = url;
downloadLink.style.display = 'inline-block';
const audioStatus = muteAudio ? ' (音声なし)' : '';
sizeInfoEl.textContent = '出力サイズ: ' + humanSize(blob.size) + audioStatus;
if (sizeMB <= 10) {
setStatus('プレビュー完了。Discord にアップできます。');
} else {
setStatus('プレビュー完了しましたが 10MB を超えています。パラメータを調整してください。', true);
}
// 音声ありで録画したかを記録
lastPreviewHadAudio = !muteAudio;
recording = false;
previewBtn.disabled = false;
};
// ===== シーク完了を待ってから録画開始 =====
const duration = end - start;
const expectedTime = duration / playbackSpeed;
video.playbackRate = playbackSpeed;
video.currentTime = start;
// 音声ミュート設定(録画中は元動画の音を消す)
video.muted = muteAudio;
setStatus(`シーク中…`);
video.onseeked = () => {
video.onseeked = null;
recorder.start();
video.play();
const audioInfo = muteAudio ? '音声なし' : '音声あり';
setStatus(`録画中… (約${expectedTime.toFixed(1)}秒かかります / ${audioInfo})`);
function draw() {
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
if (video.currentTime >= end || video.currentTime >= video.duration || video.ended) {
recorder.stop();
video.pause();
video.playbackRate = 1;
video.muted = false;
return;
}
requestAnimationFrame(draw);
}
draw();
};
}
previewBtn.addEventListener('click', recordClip);
// ========== 画面全体でドロップ ==========
document.body.addEventListener('dragenter', (e) => {
e.preventDefault();
document.body.classList.add('dragover');
});
document.body.addEventListener('dragover', (e) => {
e.preventDefault();
});
document.body.addEventListener('dragleave', (e) => {
if (e.target === document.body || !document.body.contains(e.relatedTarget)) {
document.body.classList.remove('dragover');
}
});
document.body.addEventListener('drop', (e) => {
e.preventDefault();
document.body.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files && files[0]) {
handleFile(files[0]);
}
});
// クリックで選択
fileSelectLink.addEventListener('click', (e) => {
e.preventDefault();
fileInput.click();
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file) {
handleFile(file);
}
});
</script>
</body>
</html>