@remotion/webcodecs 4.0.227 → 4.0.229
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audio-decoder-config.js +3 -0
- package/dist/audio-decoder.d.ts +3 -3
- package/dist/audio-decoder.js +23 -29
- package/dist/audio-encoder.d.ts +3 -2
- package/dist/audio-encoder.js +17 -29
- package/dist/auto-select-writer.d.ts +3 -0
- package/dist/auto-select-writer.js +20 -0
- package/dist/calculate-progress.d.ts +4 -0
- package/dist/calculate-progress.js +10 -0
- package/dist/can-copy-audio-track.d.ts +8 -0
- package/dist/can-copy-audio-track.js +10 -0
- package/dist/can-copy-video-track.d.ts +8 -0
- package/dist/can-copy-video-track.js +13 -0
- package/dist/can-reencode-audio-track.d.ts +7 -0
- package/dist/can-reencode-audio-track.js +21 -0
- package/dist/can-reencode-audio.d.ts +7 -0
- package/dist/can-reencode-audio.js +21 -0
- package/dist/can-reencode-video-track.d.ts +6 -0
- package/dist/can-reencode-video-track.js +15 -0
- package/dist/can-reencode-video.d.ts +6 -0
- package/dist/can-reencode-video.js +15 -0
- package/dist/codec-id.d.ts +7 -2
- package/dist/codec-id.js +7 -0
- package/dist/convert-encoded-chunk.d.ts +2 -0
- package/dist/convert-encoded-chunk.js +15 -0
- package/dist/convert-media.d.ts +25 -9
- package/dist/convert-media.js +69 -15
- package/dist/esm/index.mjs +602 -297
- package/dist/event-emitter.d.ts +25 -0
- package/dist/event-emitter.js +23 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +12 -1
- package/dist/io-manager/event-emitter.d.ts +27 -0
- package/dist/io-manager/event-emitter.js +24 -0
- package/dist/io-manager/io-synchronizer.d.ts +12 -0
- package/dist/io-manager/io-synchronizer.js +95 -0
- package/dist/log.d.ts +10 -0
- package/dist/log.js +6 -0
- package/dist/on-audio-track.d.ts +6 -5
- package/dist/on-audio-track.js +23 -21
- package/dist/on-frame.d.ts +11 -0
- package/dist/on-frame.js +32 -0
- package/dist/on-video-track.d.ts +8 -6
- package/dist/on-video-track.js +30 -21
- package/dist/polyfill-encoded-audio-chunk.d.ts +3 -0
- package/dist/polyfill-encoded-audio-chunk.js +5 -0
- package/dist/resolve-audio-action.d.ts +15 -11
- package/dist/resolve-audio-action.js +23 -21
- package/dist/resolve-video-action.d.ts +14 -11
- package/dist/resolve-video-action.js +17 -24
- package/dist/video-decoder.d.ts +3 -3
- package/dist/video-decoder.js +23 -28
- package/dist/video-encoder-config.d.ts +6 -1
- package/dist/video-encoder-config.js +6 -1
- package/dist/video-encoder.d.ts +4 -3
- package/dist/video-encoder.js +26 -29
- package/dist/wait-until-return.d.ts +4 -0
- package/dist/wait-until-return.js +14 -0
- package/dist/with-resolvers.d.ts +5 -0
- package/dist/with-resolvers.js +16 -1
- package/package.json +4 -4
package/dist/convert-media.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2024 Remotion AG
|
|
4
|
+
* For licensing, see: https://remotion.dev/docs/webcodecs#license
|
|
5
|
+
*/
|
|
2
6
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
8
|
};
|
|
5
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
10
|
exports.convertMedia = void 0;
|
|
7
11
|
const media_parser_1 = require("@remotion/media-parser");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
12
|
+
const auto_select_writer_1 = require("./auto-select-writer");
|
|
13
|
+
const calculate_progress_1 = require("./calculate-progress");
|
|
10
14
|
const error_cause_1 = __importDefault(require("./error-cause"));
|
|
11
15
|
const on_audio_track_1 = require("./on-audio-track");
|
|
12
16
|
const on_video_track_1 = require("./on-video-track");
|
|
13
|
-
const resolve_audio_action_1 = require("./resolve-audio-action");
|
|
14
|
-
const resolve_video_action_1 = require("./resolve-video-action");
|
|
15
17
|
const with_resolvers_1 = require("./with-resolvers");
|
|
16
|
-
const convertMedia = async ({ src, onVideoFrame, onMediaStateUpdate, audioCodec,
|
|
17
|
-
if (
|
|
18
|
+
const convertMedia = async function ({ src, onVideoFrame, onMediaStateUpdate: onMediaStateDoNoCallDirectly, audioCodec, container, videoCodec, signal: userPassedAbortSignal, onAudioTrack: userAudioResolver, onVideoTrack: userVideoResolver, reader, fields, logLevel = 'info', writer, ...more }) {
|
|
19
|
+
if (userPassedAbortSignal === null || userPassedAbortSignal === void 0 ? void 0 : userPassedAbortSignal.aborted) {
|
|
20
|
+
return Promise.reject(new error_cause_1.default('Aborted'));
|
|
21
|
+
}
|
|
22
|
+
if (container !== 'webm') {
|
|
18
23
|
return Promise.reject(new TypeError('Only `to: "webm"` is supported currently'));
|
|
19
24
|
}
|
|
20
25
|
if (audioCodec !== 'opus') {
|
|
@@ -23,7 +28,7 @@ const convertMedia = async ({ src, onVideoFrame, onMediaStateUpdate, audioCodec,
|
|
|
23
28
|
if (videoCodec !== 'vp8' && videoCodec !== 'vp9') {
|
|
24
29
|
return Promise.reject(new TypeError('Only `videoCodec: "vp8"` and `videoCodec: "vp9"` are supported currently'));
|
|
25
30
|
}
|
|
26
|
-
const {
|
|
31
|
+
const { resolve, reject, getPromiseToImmediatelyReturn } = (0, with_resolvers_1.withResolversAndWaitForReturn)();
|
|
27
32
|
const controller = new AbortController();
|
|
28
33
|
const abortConversion = (errCause) => {
|
|
29
34
|
reject(errCause);
|
|
@@ -40,9 +45,34 @@ const convertMedia = async ({ src, onVideoFrame, onMediaStateUpdate, audioCodec,
|
|
|
40
45
|
decodedVideoFrames: 0,
|
|
41
46
|
encodedVideoFrames: 0,
|
|
42
47
|
encodedAudioFrames: 0,
|
|
48
|
+
bytesWritten: 0,
|
|
49
|
+
millisecondsWritten: 0,
|
|
50
|
+
expectedOutputDurationInMs: null,
|
|
51
|
+
overallProgress: 0,
|
|
52
|
+
};
|
|
53
|
+
const onMediaStateUpdate = (newState) => {
|
|
54
|
+
if (controller.signal.aborted) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
onMediaStateDoNoCallDirectly === null || onMediaStateDoNoCallDirectly === void 0 ? void 0 : onMediaStateDoNoCallDirectly(newState);
|
|
43
58
|
};
|
|
44
|
-
const
|
|
45
|
-
|
|
59
|
+
const state = await media_parser_1.MediaParserInternals.createMedia({
|
|
60
|
+
writer: await (0, auto_select_writer_1.autoSelectWriter)(writer, logLevel),
|
|
61
|
+
onBytesProgress: (bytesWritten) => {
|
|
62
|
+
convertMediaState.bytesWritten = bytesWritten;
|
|
63
|
+
onMediaStateUpdate === null || onMediaStateUpdate === void 0 ? void 0 : onMediaStateUpdate(convertMediaState);
|
|
64
|
+
},
|
|
65
|
+
onMillisecondsProgress: (millisecondsWritten) => {
|
|
66
|
+
if (millisecondsWritten > convertMediaState.millisecondsWritten) {
|
|
67
|
+
convertMediaState.millisecondsWritten = millisecondsWritten;
|
|
68
|
+
convertMediaState.overallProgress = (0, calculate_progress_1.calculateProgress)({
|
|
69
|
+
millisecondsWritten: convertMediaState.millisecondsWritten,
|
|
70
|
+
expectedOutputDurationInMs: convertMediaState.expectedOutputDurationInMs,
|
|
71
|
+
});
|
|
72
|
+
onMediaStateUpdate === null || onMediaStateUpdate === void 0 ? void 0 : onMediaStateUpdate(convertMediaState);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
});
|
|
46
76
|
const onVideoTrack = (0, on_video_track_1.makeVideoTrackHandler)({
|
|
47
77
|
state,
|
|
48
78
|
onVideoFrame: onVideoFrame !== null && onVideoFrame !== void 0 ? onVideoFrame : null,
|
|
@@ -51,7 +81,9 @@ const convertMedia = async ({ src, onVideoFrame, onMediaStateUpdate, audioCodec,
|
|
|
51
81
|
convertMediaState,
|
|
52
82
|
controller,
|
|
53
83
|
videoCodec,
|
|
54
|
-
onVideoTrack: userVideoResolver !== null && userVideoResolver !== void 0 ? userVideoResolver :
|
|
84
|
+
onVideoTrack: userVideoResolver !== null && userVideoResolver !== void 0 ? userVideoResolver : null,
|
|
85
|
+
logLevel,
|
|
86
|
+
container,
|
|
55
87
|
});
|
|
56
88
|
const onAudioTrack = (0, on_audio_track_1.makeAudioTrackHandler)({
|
|
57
89
|
abortConversion,
|
|
@@ -60,14 +92,37 @@ const convertMedia = async ({ src, onVideoFrame, onMediaStateUpdate, audioCodec,
|
|
|
60
92
|
convertMediaState,
|
|
61
93
|
onMediaStateUpdate: onMediaStateUpdate !== null && onMediaStateUpdate !== void 0 ? onMediaStateUpdate : null,
|
|
62
94
|
state,
|
|
63
|
-
onAudioTrack: userAudioResolver !== null && userAudioResolver !== void 0 ? userAudioResolver :
|
|
64
|
-
|
|
95
|
+
onAudioTrack: userAudioResolver !== null && userAudioResolver !== void 0 ? userAudioResolver : null,
|
|
96
|
+
logLevel,
|
|
97
|
+
container,
|
|
65
98
|
});
|
|
66
99
|
(0, media_parser_1.parseMedia)({
|
|
67
100
|
src,
|
|
68
101
|
onVideoTrack,
|
|
69
102
|
onAudioTrack,
|
|
70
103
|
signal: controller.signal,
|
|
104
|
+
fields: {
|
|
105
|
+
...fields,
|
|
106
|
+
durationInSeconds: true,
|
|
107
|
+
},
|
|
108
|
+
reader,
|
|
109
|
+
...more,
|
|
110
|
+
onDurationInSeconds: (durationInSeconds) => {
|
|
111
|
+
if (durationInSeconds === null) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const casted = more;
|
|
115
|
+
if (casted.onDurationInSeconds) {
|
|
116
|
+
casted.onDurationInSeconds(durationInSeconds);
|
|
117
|
+
}
|
|
118
|
+
const expectedOutputDurationInMs = durationInSeconds * 1000;
|
|
119
|
+
convertMediaState.expectedOutputDurationInMs = expectedOutputDurationInMs;
|
|
120
|
+
convertMediaState.overallProgress = (0, calculate_progress_1.calculateProgress)({
|
|
121
|
+
millisecondsWritten: convertMediaState.millisecondsWritten,
|
|
122
|
+
expectedOutputDurationInMs,
|
|
123
|
+
});
|
|
124
|
+
onMediaStateUpdate(convertMediaState);
|
|
125
|
+
},
|
|
71
126
|
})
|
|
72
127
|
.then(() => {
|
|
73
128
|
return state.waitForFinish();
|
|
@@ -77,10 +132,9 @@ const convertMedia = async ({ src, onVideoFrame, onMediaStateUpdate, audioCodec,
|
|
|
77
132
|
})
|
|
78
133
|
.catch((err) => {
|
|
79
134
|
reject(err);
|
|
80
|
-
})
|
|
81
|
-
|
|
135
|
+
});
|
|
136
|
+
return getPromiseToImmediatelyReturn().finally(() => {
|
|
82
137
|
userPassedAbortSignal === null || userPassedAbortSignal === void 0 ? void 0 : userPassedAbortSignal.removeEventListener('abort', onUserAbort);
|
|
83
138
|
});
|
|
84
|
-
return promise;
|
|
85
139
|
};
|
|
86
140
|
exports.convertMedia = convertMedia;
|