@remotion/media 4.0.387 → 4.0.390

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.
Files changed (62) hide show
  1. package/dist/esm/index.mjs +16 -14
  2. package/dist/media-player.js +15 -13
  3. package/dist/video-iterator-manager.js +1 -4
  4. package/package.json +3 -3
  5. package/dist/audio-for-rendering.d.ts +0 -3
  6. package/dist/audio-for-rendering.js +0 -94
  7. package/dist/audio.d.ts +0 -3
  8. package/dist/audio.js +0 -60
  9. package/dist/audiodata-to-array.d.ts +0 -0
  10. package/dist/audiodata-to-array.js +0 -1
  11. package/dist/convert-audiodata/data-types.d.ts +0 -1
  12. package/dist/convert-audiodata/data-types.js +0 -22
  13. package/dist/convert-audiodata/is-planar-format.d.ts +0 -1
  14. package/dist/convert-audiodata/is-planar-format.js +0 -3
  15. package/dist/convert-audiodata/log-audiodata.d.ts +0 -1
  16. package/dist/convert-audiodata/log-audiodata.js +0 -8
  17. package/dist/convert-audiodata/trim-audiodata.d.ts +0 -0
  18. package/dist/convert-audiodata/trim-audiodata.js +0 -1
  19. package/dist/deserialized-audiodata.d.ts +0 -15
  20. package/dist/deserialized-audiodata.js +0 -26
  21. package/dist/extract-audio.d.ts +0 -7
  22. package/dist/extract-audio.js +0 -98
  23. package/dist/extract-frame-via-broadcast-channel.d.ts +0 -15
  24. package/dist/extract-frame-via-broadcast-channel.js +0 -104
  25. package/dist/extract-frame.d.ts +0 -27
  26. package/dist/extract-frame.js +0 -21
  27. package/dist/extrct-audio.d.ts +0 -7
  28. package/dist/extrct-audio.js +0 -94
  29. package/dist/get-frames-since-keyframe.d.ts +0 -22
  30. package/dist/get-frames-since-keyframe.js +0 -41
  31. package/dist/is-network-error.d.ts +0 -6
  32. package/dist/is-network-error.js +0 -17
  33. package/dist/keyframe-bank.d.ts +0 -25
  34. package/dist/keyframe-bank.js +0 -120
  35. package/dist/keyframe-manager.d.ts +0 -23
  36. package/dist/keyframe-manager.js +0 -170
  37. package/dist/log.d.ts +0 -10
  38. package/dist/log.js +0 -33
  39. package/dist/new-video-for-rendering.d.ts +0 -3
  40. package/dist/new-video-for-rendering.js +0 -108
  41. package/dist/new-video.d.ts +0 -3
  42. package/dist/new-video.js +0 -37
  43. package/dist/props.d.ts +0 -29
  44. package/dist/props.js +0 -1
  45. package/dist/remember-actual-matroska-timestamps.d.ts +0 -4
  46. package/dist/remember-actual-matroska-timestamps.js +0 -19
  47. package/dist/serialize-videoframe.d.ts +0 -0
  48. package/dist/serialize-videoframe.js +0 -1
  49. package/dist/video/media-player.d.ts +0 -62
  50. package/dist/video/media-player.js +0 -361
  51. package/dist/video/new-video-for-preview.d.ts +0 -10
  52. package/dist/video/new-video-for-preview.js +0 -108
  53. package/dist/video/timeout-utils.d.ts +0 -2
  54. package/dist/video/timeout-utils.js +0 -18
  55. package/dist/video-extraction/media-player.d.ts +0 -64
  56. package/dist/video-extraction/media-player.js +0 -501
  57. package/dist/video-extraction/new-video-for-preview.d.ts +0 -10
  58. package/dist/video-extraction/new-video-for-preview.js +0 -114
  59. package/dist/video-for-rendering.d.ts +0 -3
  60. package/dist/video-for-rendering.js +0 -108
  61. package/dist/video.d.ts +0 -3
  62. package/dist/video.js +0 -37
@@ -1,7 +0,0 @@
1
- import type { PcmS16AudioData } from './convert-audiodata/convert-audiodata';
2
- export declare const extractAudio: ({ src, timeInSeconds, durationInSeconds, volume, }: {
3
- src: string;
4
- timeInSeconds: number;
5
- durationInSeconds: number;
6
- volume: number;
7
- }) => Promise<PcmS16AudioData | null>;
@@ -1,94 +0,0 @@
1
- import { combineAudioDataAndClosePrevious } from './convert-audiodata/combine-audiodata';
2
- import { convertAudioData } from './convert-audiodata/convert-audiodata';
3
- import { TARGET_NUMBER_OF_CHANNELS, TARGET_SAMPLE_RATE, } from './convert-audiodata/resample-audiodata';
4
- import { sinkPromises } from './extract-frame';
5
- import { getSinks } from './get-frames-since-keyframe';
6
- export const extractAudio = async ({ src, timeInSeconds, durationInSeconds, volume, }) => {
7
- if (!sinkPromises[src]) {
8
- sinkPromises[src] = getSinks(src);
9
- }
10
- const { audio, actualMatroskaTimestamps, isMatroska } = await sinkPromises[src];
11
- if (audio === null) {
12
- return null;
13
- }
14
- // https://discord.com/channels/@me/1409810025844838481/1415028953093111870
15
- // Audio frames might have dependencies on previous and next frames so we need to decode a bit more
16
- // and then discard it.
17
- // The worst case seems to be FLAC files with a 65'535 sample window, which would be 1486.0ms at 44.1Khz.
18
- // So let's set a threshold of 1.5 seconds.
19
- const extraThreshold = 1.5;
20
- // Matroska timestamps are not accurate unless we start from the beginning
21
- // So for matroska, we need to decode all samples :(
22
- // https://github.com/Vanilagy/mediabunny/issues/105
23
- const sampleIterator = audio.sampleSink.samples(isMatroska ? 0 : Math.max(0, timeInSeconds - extraThreshold), timeInSeconds + durationInSeconds);
24
- const samples = [];
25
- for await (const sample of sampleIterator) {
26
- const realTimestamp = actualMatroskaTimestamps.getRealTimestamp(sample.timestamp);
27
- if (realTimestamp !== null && realTimestamp !== sample.timestamp) {
28
- sample.setTimestamp(realTimestamp);
29
- }
30
- actualMatroskaTimestamps.observeTimestamp(sample.timestamp);
31
- actualMatroskaTimestamps.observeTimestamp(sample.timestamp + sample.duration);
32
- if (sample.timestamp + sample.duration - 0.0000000001 <= timeInSeconds) {
33
- continue;
34
- }
35
- if (sample.timestamp >= timeInSeconds + durationInSeconds - 0.0000000001) {
36
- continue;
37
- }
38
- samples.push(sample);
39
- }
40
- const audioDataArray = [];
41
- for (let i = 0; i < samples.length; i++) {
42
- const sample = samples[i];
43
- // Less than 1 sample would be included - we did not need it after all!
44
- if (Math.abs(sample.timestamp - (timeInSeconds + durationInSeconds)) *
45
- sample.sampleRate <
46
- 1) {
47
- sample.close();
48
- continue;
49
- }
50
- // Less than 1 sample would be included - we did not need it after all!
51
- if (sample.timestamp + sample.duration <= timeInSeconds) {
52
- sample.close();
53
- continue;
54
- }
55
- const isFirstSample = i === 0;
56
- const isLastSample = i === samples.length - 1;
57
- const audioDataRaw = sample.toAudioData();
58
- // amount of samples to shave from start and end
59
- let trimStartInSeconds = 0;
60
- let trimEndInSeconds = 0;
61
- // TODO: Apply playback rate
62
- // TODO: Apply tone frequency
63
- if (isFirstSample) {
64
- trimStartInSeconds = timeInSeconds - sample.timestamp;
65
- }
66
- if (isLastSample) {
67
- trimEndInSeconds =
68
- // clamp to 0 in case the audio ends early
69
- Math.max(0, sample.timestamp +
70
- sample.duration -
71
- (timeInSeconds + durationInSeconds));
72
- }
73
- const audioData = convertAudioData({
74
- audioData: audioDataRaw,
75
- newSampleRate: TARGET_SAMPLE_RATE,
76
- trimStartInSeconds,
77
- trimEndInSeconds,
78
- targetNumberOfChannels: TARGET_NUMBER_OF_CHANNELS,
79
- volume,
80
- });
81
- audioDataRaw.close();
82
- if (audioData.numberOfFrames === 0) {
83
- sample.close();
84
- continue;
85
- }
86
- audioDataArray.push(audioData);
87
- sample.close();
88
- }
89
- if (audioDataArray.length === 0) {
90
- return null;
91
- }
92
- const combined = combineAudioDataAndClosePrevious(audioDataArray);
93
- return combined;
94
- };
@@ -1,22 +0,0 @@
1
- import type { EncodedPacket } from 'mediabunny';
2
- import { AudioSampleSink, EncodedPacketSink, VideoSampleSink } from 'mediabunny';
3
- export declare const getSinks: (src: string) => Promise<{
4
- video: {
5
- sampleSink: VideoSampleSink;
6
- packetSink: EncodedPacketSink;
7
- };
8
- audio: {
9
- sampleSink: AudioSampleSink;
10
- } | null;
11
- actualMatroskaTimestamps: {
12
- observeTimestamp: (startTime: number) => void;
13
- getRealTimestamp: (observedTimestamp: number) => number | null;
14
- };
15
- isMatroska: boolean;
16
- }>;
17
- export type GetSink = Awaited<ReturnType<typeof getSinks>>;
18
- export declare const getFramesSinceKeyframe: ({ packetSink, videoSampleSink, startPacket, }: {
19
- packetSink: EncodedPacketSink;
20
- videoSampleSink: VideoSampleSink;
21
- startPacket: EncodedPacket;
22
- }) => Promise<any>;
@@ -1,41 +0,0 @@
1
- import { ALL_FORMATS, AudioSampleSink, EncodedPacketSink, Input, MATROSKA, UrlSource, VideoSampleSink, } from 'mediabunny';
2
- import { makeKeyframeBank } from './keyframe-bank';
3
- import { rememberActualMatroskaTimestamps } from './remember-actual-matroska-timestamps';
4
- export const getSinks = async (src) => {
5
- const input = new Input({
6
- formats: ALL_FORMATS,
7
- source: new UrlSource(src),
8
- });
9
- const format = await input.getFormat();
10
- const videoTrack = await input.getPrimaryVideoTrack();
11
- if (!videoTrack) {
12
- throw new Error(`No video track found for ${src}`);
13
- }
14
- const audioTrack = await input.getPrimaryAudioTrack();
15
- const isMatroska = format === MATROSKA;
16
- return {
17
- video: {
18
- sampleSink: new VideoSampleSink(videoTrack),
19
- packetSink: new EncodedPacketSink(videoTrack),
20
- },
21
- audio: audioTrack
22
- ? {
23
- sampleSink: new AudioSampleSink(audioTrack),
24
- }
25
- : null,
26
- actualMatroskaTimestamps: rememberActualMatroskaTimestamps(isMatroska),
27
- isMatroska,
28
- };
29
- };
30
- export const getFramesSinceKeyframe = async ({ packetSink, videoSampleSink, startPacket, }) => {
31
- const nextKeyPacket = await packetSink.getNextKeyPacket(startPacket, {
32
- verifyKeyPackets: false,
33
- });
34
- const sampleIterator = videoSampleSink.samples(startPacket.timestamp, nextKeyPacket ? nextKeyPacket.timestamp : Infinity);
35
- const keyframeBank = makeKeyframeBank({
36
- startTimestampInSeconds: startPacket.timestamp,
37
- endTimestampInSeconds: nextKeyPacket ? nextKeyPacket.timestamp : Infinity,
38
- sampleIterator,
39
- });
40
- return keyframeBank;
41
- };
@@ -1,6 +0,0 @@
1
- /**
2
- * Utility to check if error is network error
3
- * @param error
4
- * @returns
5
- */
6
- export declare function isNetworkError(error: Error): boolean;
@@ -1,17 +0,0 @@
1
- /**
2
- * Utility to check if error is network error
3
- * @param error
4
- * @returns
5
- */
6
- export function isNetworkError(error) {
7
- if (
8
- // Chrome
9
- error.message.includes('Failed to fetch') ||
10
- // Safari
11
- error.message.includes('Load failed') ||
12
- // Firefox
13
- error.message.includes('NetworkError when attempting to fetch resource')) {
14
- return true;
15
- }
16
- return false;
17
- }
@@ -1,25 +0,0 @@
1
- import type { VideoSample } from 'mediabunny';
2
- import type { LogLevel } from './log';
3
- export type KeyframeBank = {
4
- startTimestampInSeconds: number;
5
- endTimestampInSeconds: number;
6
- getFrameFromTimestamp: (timestamp: number) => Promise<VideoSample | null>;
7
- prepareForDeletion: () => Promise<void>;
8
- deleteFramesBeforeTimestamp: ({ logLevel, src, timestampInSeconds, }: {
9
- timestampInSeconds: number;
10
- logLevel: LogLevel;
11
- src: string;
12
- }) => void;
13
- hasTimestampInSecond: (timestamp: number) => Promise<boolean>;
14
- addFrame: (frame: VideoSample) => void;
15
- getOpenFrameCount: () => {
16
- size: number;
17
- timestamps: number[];
18
- };
19
- getLastUsed: () => number;
20
- };
21
- export declare const makeKeyframeBank: ({ startTimestampInSeconds, endTimestampInSeconds, sampleIterator, }: {
22
- startTimestampInSeconds: number;
23
- endTimestampInSeconds: number;
24
- sampleIterator: AsyncGenerator<VideoSample, void, unknown>;
25
- }) => KeyframeBank;
@@ -1,120 +0,0 @@
1
- import { Log } from './log';
2
- // Round to only 4 digits, because WebM has a timescale of 1_000, e.g. framer.webm
3
- const roundTo4Digits = (timestamp) => {
4
- return Math.round(timestamp * 1000) / 1000;
5
- };
6
- export const makeKeyframeBank = ({ startTimestampInSeconds, endTimestampInSeconds, sampleIterator, }) => {
7
- const frames = {};
8
- const frameTimestamps = [];
9
- let lastUsed = Date.now();
10
- let alloctionSize = 0;
11
- const hasDecodedEnoughForTimestamp = (timestamp) => {
12
- const lastFrameTimestamp = frameTimestamps[frameTimestamps.length - 1];
13
- if (!lastFrameTimestamp) {
14
- return false;
15
- }
16
- const lastFrame = frames[lastFrameTimestamp];
17
- // Don't decode more, will probably have to re-decode everything
18
- if (!lastFrame) {
19
- return true;
20
- }
21
- return (roundTo4Digits(lastFrame.timestamp + lastFrame.duration) >
22
- roundTo4Digits(timestamp));
23
- };
24
- const addFrame = (frame) => {
25
- frames[frame.timestamp] = frame;
26
- frameTimestamps.push(frame.timestamp);
27
- alloctionSize += frame.allocationSize();
28
- lastUsed = Date.now();
29
- };
30
- const ensureEnoughFramesForTimestamp = async (timestamp) => {
31
- while (!hasDecodedEnoughForTimestamp(timestamp)) {
32
- const sample = await sampleIterator.next();
33
- if (sample.value) {
34
- addFrame(sample.value);
35
- }
36
- if (sample.done) {
37
- break;
38
- }
39
- }
40
- lastUsed = Date.now();
41
- };
42
- const getFrameFromTimestamp = async (timestampInSeconds) => {
43
- lastUsed = Date.now();
44
- if (timestampInSeconds < startTimestampInSeconds) {
45
- return Promise.reject(new Error(`Timestamp is before start timestamp (requested: ${timestampInSeconds}sec, start: ${startTimestampInSeconds})`));
46
- }
47
- if (timestampInSeconds > endTimestampInSeconds) {
48
- return Promise.reject(new Error(`Timestamp is after end timestamp (requested: ${timestampInSeconds}sec, end: ${endTimestampInSeconds})`));
49
- }
50
- await ensureEnoughFramesForTimestamp(timestampInSeconds);
51
- for (let i = frameTimestamps.length - 1; i >= 0; i--) {
52
- const sample = frames[frameTimestamps[i]];
53
- if (!sample) {
54
- return null;
55
- }
56
- if (roundTo4Digits(sample.timestamp) <= roundTo4Digits(timestampInSeconds)) {
57
- return sample;
58
- }
59
- }
60
- throw new Error('No frame found for timestamp ' + timestampInSeconds);
61
- };
62
- const hasTimestampInSecond = async (timestamp) => {
63
- return (await getFrameFromTimestamp(timestamp)) !== null;
64
- };
65
- const prepareForDeletion = async () => {
66
- // Cleanup frames that have been extracted that might not have been retrieved yet
67
- const { value } = await sampleIterator.return();
68
- if (value) {
69
- value.close();
70
- }
71
- for (const frameTimestamp of frameTimestamps) {
72
- if (!frames[frameTimestamp]) {
73
- continue;
74
- }
75
- alloctionSize -= frames[frameTimestamp].allocationSize();
76
- frames[frameTimestamp].close();
77
- delete frames[frameTimestamp];
78
- }
79
- frameTimestamps.length = 0;
80
- };
81
- const deleteFramesBeforeTimestamp = ({ logLevel, src, timestampInSeconds, }) => {
82
- for (const frameTimestamp of frameTimestamps) {
83
- const isLast = frameTimestamp === frameTimestamps[frameTimestamps.length - 1];
84
- // Don't delete the last frame, since it may be the last one in the video!
85
- if (isLast) {
86
- continue;
87
- }
88
- if (frameTimestamp < timestampInSeconds) {
89
- if (!frames[frameTimestamp]) {
90
- continue;
91
- }
92
- alloctionSize -= frames[frameTimestamp].allocationSize();
93
- frames[frameTimestamp].close();
94
- delete frames[frameTimestamp];
95
- Log.verbose(logLevel, `[Video] Deleted frame ${frameTimestamp} for src ${src}`);
96
- }
97
- }
98
- };
99
- const getOpenFrameCount = () => {
100
- return {
101
- size: alloctionSize,
102
- timestamps: frameTimestamps,
103
- };
104
- };
105
- const getLastUsed = () => {
106
- return lastUsed;
107
- };
108
- const keyframeBank = {
109
- startTimestampInSeconds,
110
- endTimestampInSeconds,
111
- getFrameFromTimestamp,
112
- prepareForDeletion,
113
- hasTimestampInSecond,
114
- addFrame,
115
- deleteFramesBeforeTimestamp,
116
- getOpenFrameCount,
117
- getLastUsed,
118
- };
119
- return keyframeBank;
120
- };
@@ -1,23 +0,0 @@
1
- import type { EncodedPacketSink, VideoSampleSink } from 'mediabunny';
2
- import { type KeyframeBank } from './keyframe-bank';
3
- import type { LogLevel } from './log';
4
- export declare const makeKeyframeManager: () => {
5
- requestKeyframeBank: ({ packetSink, timestamp, videoSampleSink, src, logLevel, }: {
6
- timestamp: number;
7
- packetSink: EncodedPacketSink;
8
- videoSampleSink: VideoSampleSink;
9
- src: string;
10
- logLevel: LogLevel;
11
- }) => Promise<KeyframeBank>;
12
- addKeyframeBank: ({ src, bank, startTimestampInSeconds, }: {
13
- src: string;
14
- bank: Promise<KeyframeBank>;
15
- startTimestampInSeconds: number;
16
- }) => void;
17
- getCacheStats: () => Promise<{
18
- count: number;
19
- totalSize: number;
20
- }>;
21
- clearAll: () => Promise<void>;
22
- };
23
- export type KeyframeManager = Awaited<ReturnType<typeof makeKeyframeManager>>;
@@ -1,170 +0,0 @@
1
- import { getFramesSinceKeyframe } from './get-frames-since-keyframe';
2
- import { Log } from './log';
3
- const MAX_CACHE_SIZE = 1000 * 1000 * 1000; // 1GB
4
- export const makeKeyframeManager = () => {
5
- // src => {[startTimestampInSeconds]: KeyframeBank
6
- const sources = {};
7
- const addKeyframeBank = ({ src, bank, startTimestampInSeconds, }) => {
8
- sources[src] = sources[src] ?? {};
9
- sources[src][startTimestampInSeconds] = bank;
10
- };
11
- const logCacheStats = async (logLevel) => {
12
- let count = 0;
13
- let totalSize = 0;
14
- for (const src in sources) {
15
- for (const bank in sources[src]) {
16
- const v = await sources[src][bank];
17
- const { size, timestamps } = v.getOpenFrameCount();
18
- count += timestamps.length;
19
- totalSize += size;
20
- if (size === 0) {
21
- continue;
22
- }
23
- Log.verbose(logLevel, `[Video] Open frames for src ${src}: ${timestamps.join(', ')}}`);
24
- }
25
- }
26
- Log.verbose(logLevel, `[Video] Cache stats: ${count} open frames, ${totalSize} bytes`);
27
- };
28
- const getCacheStats = async () => {
29
- let count = 0;
30
- let totalSize = 0;
31
- for (const src in sources) {
32
- for (const bank in sources[src]) {
33
- const v = await sources[src][bank];
34
- const { timestamps, size } = v.getOpenFrameCount();
35
- count += timestamps.length;
36
- totalSize += size;
37
- if (size === 0) {
38
- continue;
39
- }
40
- }
41
- }
42
- return { count, totalSize };
43
- };
44
- const getTheKeyframeBankMostInThePast = async () => {
45
- let mostInThePast = null;
46
- let mostInThePastBank = null;
47
- for (const src in sources) {
48
- for (const b in sources[src]) {
49
- const bank = await sources[src][b];
50
- const lastUsed = bank.getLastUsed();
51
- if (mostInThePast === null || lastUsed < mostInThePast) {
52
- mostInThePast = lastUsed;
53
- mostInThePastBank = { src, bank };
54
- }
55
- }
56
- }
57
- if (!mostInThePastBank) {
58
- throw new Error('No keyframe bank found');
59
- }
60
- return mostInThePastBank;
61
- };
62
- const ensureToStayUnderMaxCacheSize = async (logLevel) => {
63
- let cacheStats = await getCacheStats();
64
- while (cacheStats.totalSize > MAX_CACHE_SIZE) {
65
- const { bank: mostInThePastBank, src: mostInThePastSrc } = await getTheKeyframeBankMostInThePast();
66
- if (mostInThePastBank) {
67
- await mostInThePastBank.prepareForDeletion();
68
- delete sources[mostInThePastSrc][mostInThePastBank.startTimestampInSeconds];
69
- Log.verbose(logLevel, `[Video] Deleted frames for src ${mostInThePastSrc} from ${mostInThePastBank.startTimestampInSeconds}sec to ${mostInThePastBank.endTimestampInSeconds}sec to free up memory.`);
70
- }
71
- cacheStats = await getCacheStats();
72
- }
73
- };
74
- const clearKeyframeBanksBeforeTime = async ({ timestampInSeconds, src, logLevel, }) => {
75
- // TODO: make it dependent on the fps and concurrency
76
- const SAFE_BACK_WINDOW_IN_SECONDS = 1;
77
- const threshold = timestampInSeconds - SAFE_BACK_WINDOW_IN_SECONDS;
78
- if (!sources[src]) {
79
- return;
80
- }
81
- const banks = Object.keys(sources[src]);
82
- for (const startTimeInSeconds of banks) {
83
- const bank = await sources[src][startTimeInSeconds];
84
- const { endTimestampInSeconds, startTimestampInSeconds } = bank;
85
- if (endTimestampInSeconds < threshold) {
86
- await bank.prepareForDeletion();
87
- Log.verbose(logLevel, `[Video] Cleared frames for src ${src} from ${startTimestampInSeconds}sec to ${endTimestampInSeconds}sec`);
88
- delete sources[src][startTimeInSeconds];
89
- }
90
- else {
91
- bank.deleteFramesBeforeTimestamp({
92
- timestampInSeconds: threshold,
93
- logLevel,
94
- src,
95
- });
96
- }
97
- }
98
- await logCacheStats(logLevel);
99
- };
100
- const getKeyframeBankOrRefetch = async ({ packetSink, timestamp, videoSampleSink, src, logLevel, }) => {
101
- const startPacket = await packetSink.getKeyPacket(timestamp, {
102
- verifyKeyPackets: true,
103
- });
104
- if (!startPacket) {
105
- throw new Error(`No key packet found for timestamp ${timestamp}`);
106
- }
107
- const startTimestampInSeconds = startPacket.timestamp;
108
- const existingBank = sources[src]?.[startTimestampInSeconds];
109
- // Bank does not yet exist, we need to fetch
110
- if (!existingBank) {
111
- const newKeyframeBank = getFramesSinceKeyframe({
112
- packetSink,
113
- videoSampleSink,
114
- startPacket,
115
- });
116
- addKeyframeBank({ src, bank: newKeyframeBank, startTimestampInSeconds });
117
- return newKeyframeBank;
118
- }
119
- // Bank exists and still has the frame we want
120
- if (await (await existingBank).hasTimestampInSecond(timestamp)) {
121
- return existingBank;
122
- }
123
- Log.verbose(logLevel, `[Video] Bank exists but frames have already been evicted!`);
124
- // Bank exists but frames have already been evicted!
125
- // First delete it entirely
126
- await (await existingBank).prepareForDeletion();
127
- delete sources[src][startTimestampInSeconds];
128
- // Then refetch
129
- const replacementKeybank = getFramesSinceKeyframe({
130
- packetSink,
131
- videoSampleSink,
132
- startPacket,
133
- });
134
- addKeyframeBank({ src, bank: replacementKeybank, startTimestampInSeconds });
135
- return replacementKeybank;
136
- };
137
- const requestKeyframeBank = async ({ packetSink, timestamp, videoSampleSink, src, logLevel, }) => {
138
- await ensureToStayUnderMaxCacheSize(logLevel);
139
- await clearKeyframeBanksBeforeTime({
140
- timestampInSeconds: timestamp,
141
- src,
142
- logLevel,
143
- });
144
- const keyframeBank = await getKeyframeBankOrRefetch({
145
- packetSink,
146
- timestamp,
147
- videoSampleSink,
148
- src,
149
- logLevel,
150
- });
151
- return keyframeBank;
152
- };
153
- const clearAll = async () => {
154
- const srcs = Object.keys(sources);
155
- for (const src of srcs) {
156
- const banks = Object.keys(sources[src]);
157
- for (const startTimeInSeconds of banks) {
158
- const bank = await sources[src][startTimeInSeconds];
159
- await bank.prepareForDeletion();
160
- delete sources[src][startTimeInSeconds];
161
- }
162
- }
163
- };
164
- return {
165
- requestKeyframeBank,
166
- addKeyframeBank,
167
- getCacheStats,
168
- clearAll,
169
- };
170
- };
package/dist/log.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export declare const logLevels: readonly ["trace", "verbose", "info", "warn", "error"];
2
- export type LogLevel = (typeof logLevels)[number];
3
- export declare const isEqualOrBelowLogLevel: (currentLevel: LogLevel, level: LogLevel) => boolean;
4
- export declare const Log: {
5
- trace: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
6
- verbose: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
7
- info: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
8
- warn: (logLevel: LogLevel, message?: any, ...optionalParams: any[]) => void;
9
- error: (message?: any, ...optionalParams: any[]) => void;
10
- };
package/dist/log.js DELETED
@@ -1,33 +0,0 @@
1
- /* eslint-disable no-console */
2
- export const logLevels = ['trace', 'verbose', 'info', 'warn', 'error'];
3
- const getNumberForLogLevel = (level) => {
4
- return logLevels.indexOf(level);
5
- };
6
- export const isEqualOrBelowLogLevel = (currentLevel, level) => {
7
- return getNumberForLogLevel(currentLevel) <= getNumberForLogLevel(level);
8
- };
9
- export const Log = {
10
- trace: (logLevel, ...args) => {
11
- if (isEqualOrBelowLogLevel(logLevel, 'trace')) {
12
- return console.log(...args);
13
- }
14
- },
15
- verbose: (logLevel, ...args) => {
16
- if (isEqualOrBelowLogLevel(logLevel, 'verbose')) {
17
- return console.log(...args);
18
- }
19
- },
20
- info: (logLevel, ...args) => {
21
- if (isEqualOrBelowLogLevel(logLevel, 'info')) {
22
- return console.log(...args);
23
- }
24
- },
25
- warn: (logLevel, ...args) => {
26
- if (isEqualOrBelowLogLevel(logLevel, 'warn')) {
27
- return console.warn(...args);
28
- }
29
- },
30
- error: (...args) => {
31
- return console.error(...args);
32
- },
33
- };
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import type { VideoProps } from './props';
3
- export declare const VideoForRendering: React.FC<VideoProps>;