-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4189 from remotion-dev/test-more-codecs
- Loading branch information
Showing
87 changed files
with
1,354 additions
and
19,297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
image: /generated/articles-docs-media-parser-support.png | ||
id: support | ||
title: Runtime support | ||
slug: /media-parser/support | ||
crumb: "@remotion/media-parser" | ||
--- | ||
|
||
`@remotion/media-parser` works in the Browser, Node.js and Bun. | ||
|
||
However, all of these require some quite modern versions (considered modern as of August 2024). | ||
|
||
## For parsing | ||
|
||
For parsing a video, the following minimum versions are required: | ||
|
||
- Node.js: 20.0.0 | ||
- Bun 1.0.0 | ||
- Chrome 111 | ||
- Edge 111 | ||
- Safari 16.4 | ||
- Firefox 128 | ||
|
||
## For using WebCodecs | ||
|
||
WebCodecs support is not tied to `@remotion/media-parser` itself, but if you use it to extract samples, you need to use the following minimum versions: | ||
|
||
- Chrome 94 | ||
- Edge 94 | ||
- Safari 16.4 - No support for `AudioDecoder` | ||
- Firefox - No support, but in development | ||
|
||
To check for `AudioDecoder` support, use | ||
|
||
```ts | ||
const audioDecoderSupported = typeof AudioDecoder !== 'undefined'; | ||
``` | ||
|
||
To check if a video track can be decoded with WebCodecs, use | ||
|
||
```ts twoslash title="Checking if a video track can be decoded" | ||
import {OnVideoTrack} from '@remotion/media-parser'; | ||
|
||
const onVideoTrack: OnVideoTrack = async (track) => { | ||
const {supported} = await VideoDecoder.isConfigSupported(track); | ||
|
||
if (!supported) { | ||
// Don't receive unsupported video samples | ||
return null; | ||
} | ||
|
||
return (videoSample) => { | ||
console.log('New video sample !', videoSample); | ||
// Accept video sample | ||
} | ||
} | ||
``` | ||
|
||
|
||
```ts twoslash title="Checking if a audio track can be decoded" | ||
// @noErrors | ||
import {OnAudioTrack} from '@remotion/media-parser'; | ||
|
||
const onAudioTrack: OnAudioTrack = async (track) => { | ||
const {supported} = await AudioDecoder.isConfigSupported(track); | ||
|
||
if (!supported) { | ||
// Don't receive unsupported audio samples | ||
return null; | ||
} | ||
|
||
return (audioSample) => { | ||
console.log('New audio sample!', audioSample); | ||
// Accept audio sample | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+37.9 KB
packages/docs/static/generated/articles-docs-media-parser-fetch-reader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38 KB
packages/docs/static/generated/articles-docs-media-parser-node-reader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.3 KB
packages/docs/static/generated/articles-docs-media-parser-support.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.2 KB
packages/docs/static/generated/articles-docs-media-parser-web-file-reader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.2 KB
packages/docs/static/generated/articles-docs-media-parser-webcodecs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import {OnAudioTrack, OnVideoTrack, parseMedia} from '@remotion/media-parser'; | ||
import React, {useCallback, useRef} from 'react'; | ||
import {flushSync} from 'react-dom'; | ||
|
||
export const SrcEncoder: React.FC<{ | ||
src: string; | ||
}> = ({src}) => { | ||
const [samples, setSamples] = React.useState<number>(0); | ||
const [videoFrames, setVideoFrames] = React.useState<number>(0); | ||
const [audioFrames, setAudioFrames] = React.useState<number>(0); | ||
|
||
const ref = useRef<HTMLCanvasElement>(null); | ||
|
||
const onVideoTrack: OnVideoTrack = useCallback(async (track) => { | ||
const decoder = await VideoDecoder.isConfigSupported(track); | ||
|
||
if (!decoder.supported) { | ||
return null; | ||
} | ||
|
||
const videoDecoder = new VideoDecoder({ | ||
async output(inputFrame) { | ||
const image = await createImageBitmap(inputFrame, { | ||
resizeHeight: 100, | ||
resizeWidth: 100, | ||
}); | ||
|
||
ref.current?.getContext('2d')?.drawImage(image, 0, 0); | ||
flushSync(() => { | ||
setVideoFrames((prev) => prev + 1); | ||
}); | ||
inputFrame.close(); | ||
}, | ||
error(error) { | ||
console.error(error); | ||
}, | ||
}); | ||
videoDecoder.configure(track); | ||
|
||
return async (chunk) => { | ||
flushSync(() => { | ||
setSamples((s) => s + 1); | ||
}); | ||
if (videoDecoder.decodeQueueSize > 10) { | ||
let resolve = () => {}; | ||
|
||
const cb = () => { | ||
resolve(); | ||
}; | ||
|
||
await new Promise<void>((r) => { | ||
resolve = r; | ||
videoDecoder.addEventListener('dequeue', cb); | ||
}); | ||
videoDecoder.removeEventListener('dequeue', cb); | ||
} | ||
videoDecoder.decode(new EncodedVideoChunk(chunk)); | ||
}; | ||
}, []); | ||
|
||
const onAudioTrack: OnAudioTrack = useCallback(async (track) => { | ||
console.log(track); | ||
|
||
const {supported} = await AudioDecoder.isConfigSupported(track); | ||
|
||
if (!supported) { | ||
return null; | ||
} | ||
|
||
if (typeof AudioDecoder === 'undefined') { | ||
return null; | ||
} | ||
|
||
const audioDecoder = new AudioDecoder({ | ||
output(inputFrame) { | ||
flushSync(() => { | ||
setAudioFrames((prev) => prev + 1); | ||
}); | ||
inputFrame.close(); | ||
}, | ||
error(error) { | ||
console.error(error); | ||
}, | ||
}); | ||
|
||
audioDecoder.configure(track); | ||
|
||
return async (audioSample) => { | ||
flushSync(() => { | ||
setSamples((s) => s + 1); | ||
}); | ||
if (audioDecoder.decodeQueueSize > 10) { | ||
console.log('audio decoder queue size', audioDecoder.decodeQueueSize); | ||
let resolve = () => {}; | ||
|
||
const cb = () => { | ||
resolve(); | ||
}; | ||
|
||
await new Promise<void>((r) => { | ||
resolve = r; | ||
// @ts-expect-error exists | ||
audioDecoder.addEventListener('dequeue', cb); | ||
}); | ||
// @ts-expect-error exists | ||
audioDecoder.removeEventListener('dequeue', cb); | ||
} | ||
audioDecoder.decode(new EncodedAudioChunk(audioSample)); | ||
}; | ||
}, []); | ||
|
||
const onClick = useCallback(() => { | ||
console.time('done'); | ||
parseMedia({ | ||
src, | ||
onVideoTrack, | ||
onAudioTrack, | ||
}).then(() => { | ||
console.timeEnd('done'); | ||
}); | ||
}, [onAudioTrack, onVideoTrack, src]); | ||
|
||
return ( | ||
<div> | ||
{src}{' '} | ||
<button type="button" onClick={onClick}> | ||
Decode | ||
</button> | ||
{samples > 0 && <div>{samples} samples</div>} | ||
{videoFrames > 0 && <div>{videoFrames} video frames</div>} | ||
{audioFrames > 0 && <div>{audioFrames} audio frames</div>} | ||
<canvas ref={ref} width={100} height={50} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
import {parseVideo, reencodeVideo} from '@remotion/browser-renderer'; | ||
import React from 'react'; | ||
import {staticFile} from 'remotion'; | ||
import {SrcEncoder} from './Encoder/SrcEncoder'; | ||
|
||
export const EncoderDemo: React.FC = () => { | ||
return ( | ||
<> | ||
<input | ||
type="file" | ||
onChange={(e) => parseVideo(e.target.files?.[0] as File)} | ||
/> | ||
<input | ||
type="file" | ||
onChange={(e) => reencodeVideo(e.target.files?.[0] as File)} | ||
/> | ||
<div | ||
style={{ | ||
overflowY: 'scroll', | ||
}} | ||
> | ||
<div> | ||
<input | ||
type="file" | ||
onChange={(e) => parseVideo(e.target.files?.[0] as File)} | ||
/> | ||
<input | ||
type="file" | ||
onChange={(e) => reencodeVideo(e.target.files?.[0] as File)} | ||
/> | ||
</div> | ||
<SrcEncoder src={staticFile('av1.webm')} /> | ||
<SrcEncoder src={staticFile('av1.mp4')} /> | ||
<SrcEncoder src={staticFile('mp4-mp3.mp4')} /> | ||
<SrcEncoder src={staticFile('bigbuckbunny.mp4')} /> | ||
<SrcEncoder src={staticFile('corrupted.mp4')} /> | ||
<SrcEncoder src={staticFile('matroska-pcm16.mkv')} /> | ||
<SrcEncoder src={staticFile('matroska-h265-aac.mkv')} /> | ||
<SrcEncoder src={staticFile('matroska-mp3.mkv')} /> | ||
<SrcEncoder src={staticFile('vid1.mp4')} /> | ||
<SrcEncoder src={staticFile('whip.mp3')} /> | ||
<SrcEncoder src={staticFile('iphone-hevc.mov')} /> | ||
<SrcEncoder src={staticFile('sample.aac')} /> | ||
<SrcEncoder src={staticFile('stretched-vp8.webm')} /> | ||
<SrcEncoder src={staticFile('opus.webm')} /> | ||
<SrcEncoder src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" /> | ||
</div> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.