Skip to content

Commit ea84455

Browse files
committed
Added the shader-toy.recordMaxDuration setting.
1 parent 66e1029 commit ea84455

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ The following settings allow to configure recording quality
161161
* `shader-toy.recordVideoCodec`: Set video codec. `vp8`, `vp9`, `h264` and `avc1` are all supported. Default it `vp8`.
162162
* `shader-toy.recordVideoBitRate`: Set recording bit rate in bits/second. Default is 2500000.
163163
* `shader-toy.recordTargetFramerate`: Set recording target frame-rate. Default is 30fps.
164+
* `shader-toy.recordMaxDuration`: Maximum recording duration in seconds. 0 (the default) will keep recording until the record button is pressed again.
164165

165166
## Requirements
166167

@@ -189,6 +190,7 @@ Contributions of any kind are welcome and encouraged.
189190
* Added `shader-toy.recordVideoContainer` (set video file container),
190191
* Added `shader-toy.recordVideoCodec` (set video codec),
191192
* Added `shader-toy.recordVideoBitRate` (set recording bit rate),
193+
* Added `shader-toy.recordMaxDuration` (set maximum recording duration),
192194
* Fixed the `shader-toy.recordTargetFramerate` setting,
193195
* Moved the Stats widget to the bottom left, so it doesn't overlap with the GUI.
194196

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@
144144
"default": 2500000,
145145
"description": "Video encoding bit rate in bits/seconds."
146146
},
147+
"shader-toy.recordMaxDuration": {
148+
"type": "number",
149+
"default": 0,
150+
"description": "Maximum recording duration in seconds. 0 (the default) will keep recording until the record button is pressed again."
151+
},
147152
"shader-toy.showPauseButton": {
148153
"type": "boolean",
149154
"default": true,

resources/webview_base.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
let normalizedMouse = new THREE.Vector2(<!-- Start Normalized Mouse -->);
236236
let frameCounter = 0;
237237
let recorder = null;
238+
let recordingTimeout = null;
238239

239240
// Audio Init
240241
// Audio Resume
@@ -484,11 +485,16 @@
484485
}
485486
function recordAction() {
486487
let recordButton = document.getElementById("record");
488+
if (recordingTimeout != null) {
489+
clearTimeout(recordingTimeout);
490+
recordingTimeout = null;
491+
}
487492
if (recorder == null) {
488493
recordButton.classList.add('recording');
489494

490495
let videoContainer = <!-- Record Video Container -->;
491496
let videoCodec = <!-- Record Video Codec -->;
497+
let maxDuration = <!-- Record Max Duration -->;
492498

493499
let stream = canvas.captureStream(<!-- Record Target Framerate -->);
494500
let recorderOptions = {
@@ -504,6 +510,15 @@
504510
a.download = `shadertoy.${videoContainer}`;
505511
a.click();
506512
};
513+
514+
if (maxDuration > 0) {
515+
recordingTimeout = setTimeout(() => {
516+
recordButton.classList.remove('recording');
517+
recorder.stop();
518+
recorder = null;
519+
recordingTimeout = null;
520+
}, maxDuration*1000);
521+
}
507522
}
508523
else {
509524
recordButton.classList.remove('recording');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
import { WebviewExtension } from '../webview_extension';
4+
5+
export class RecordMaxDurationExtension implements WebviewExtension {
6+
private recordMaxDuration: number;
7+
8+
public constructor(recordMaxDuration: number) {
9+
this.recordMaxDuration = recordMaxDuration;
10+
}
11+
12+
public generateContent(): string {
13+
return `${this.recordMaxDuration}`;
14+
}
15+
}

src/webviewcontentprovider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { RecordTargetFramerateExtension } from './extensions/user_interface/reco
7171
import { RecordVideoContainerExtension } from './extensions/user_interface/record_video_container_extension';
7272
import { RecordVideoCodecExtension } from './extensions/user_interface/record_video_codec_extension';
7373
import { RecordVideoBitRateExtension } from './extensions/user_interface/record_video_bit_rate_extension';
74+
import { RecordMaxDurationExtension } from './extensions/user_interface/record_max_duration_extension';
7475

7576
export class WebviewContentProvider {
7677
private context: Context;
@@ -411,6 +412,10 @@ export class WebviewContentProvider {
411412
const recordVideoBitRateExtension = new RecordVideoBitRateExtension(recordVideoBitRate);
412413
this.webviewAssembler.addReplaceModule(recordVideoBitRateExtension, 'videoBitsPerSecond: <!-- Record Video Bit Rate -->,', '<!-- Record Video Bit Rate -->');
413414

415+
const recordMaxDuration = this.context.getConfig<number>('recordMaxDuration') || 0;
416+
const recordMaxDurationExtension = new RecordMaxDurationExtension(recordMaxDuration);
417+
this.webviewAssembler.addReplaceModule(recordMaxDurationExtension, 'let maxDuration = <!-- Record Max Duration -->;', '<!-- Record Max Duration -->');
418+
414419
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
415420
// Reload Logic
416421
if (!generateStandalone) {

0 commit comments

Comments
 (0)