-
-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c02059d
commit 0d12126
Showing
10 changed files
with
79 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { RouterOutlet } from '@angular/router'; | |
import { FFmpeg } from '@ffmpeg/ffmpeg'; | ||
import { fetchFile, toBlobURL } from '@ffmpeg/util'; | ||
|
||
const baseURL = "https://unpkg.com/@ffmpeg/[email protected].6/dist/esm"; | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/esm'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
|
@@ -16,33 +16,34 @@ const baseURL = "https://unpkg.com/@ffmpeg/[email protected]/dist/esm"; | |
export class AppComponent { | ||
loaded = false; | ||
ffmpeg = new FFmpeg(); | ||
videoURL = ""; | ||
message = ""; | ||
videoURL = ''; | ||
message = ''; | ||
async load() { | ||
this.ffmpeg.on("log", ({ message }) => { | ||
this.ffmpeg.on('log', ({ message }) => { | ||
this.message = message; | ||
}); | ||
await this.ffmpeg.load({ | ||
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"), | ||
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'), | ||
wasmURL: await toBlobURL( | ||
`${baseURL}/ffmpeg-core.wasm`, | ||
"application/wasm" | ||
'application/wasm' | ||
), | ||
workerURL: await toBlobURL( | ||
`${baseURL}/ffmpeg-core.worker.js`, | ||
"text/javascript" | ||
'text/javascript' | ||
), | ||
}); | ||
this.loaded = true; | ||
}; | ||
} | ||
async transcode() { | ||
const videoURL = "https://raw.githubusercontent.com/ffmpegwasm/testdata/master/video-15s.avi"; | ||
await this.ffmpeg.writeFile("input.avi", await fetchFile(videoURL)); | ||
await this.ffmpeg.exec(["-i", "input.avi", "output.mp4"]); | ||
const videoURL = | ||
'https://raw.githubusercontent.com/ffmpegwasm/testdata/master/video-15s.avi'; | ||
await this.ffmpeg.writeFile('input.avi', await fetchFile(videoURL)); | ||
await this.ffmpeg.exec(['-i', 'input.avi', 'output.mp4']); | ||
const fileData = await this.ffmpeg.readFile('output.mp4'); | ||
const data = new Uint8Array(fileData as ArrayBuffer); | ||
this.videoURL = URL.createObjectURL( | ||
new Blob([data.buffer], { type: 'video/mp4' }) | ||
); | ||
}; | ||
} | ||
} |
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,42 +1,52 @@ | ||
'use client' | ||
"use client"; | ||
|
||
import { FFmpeg } from '@ffmpeg/ffmpeg' | ||
import { fetchFile, toBlobURL } from '@ffmpeg/util' | ||
import { useRef, useState } from 'react' | ||
import { FFmpeg } from "@ffmpeg/ffmpeg"; | ||
import { fetchFile, toBlobURL } from "@ffmpeg/util"; | ||
import { useRef, useState } from "react"; | ||
|
||
export default function Home() { | ||
const [loaded, setLoaded] = useState(false) | ||
const [isLoading, setIsLoading] = useState(false) | ||
const ffmpegRef = useRef(new FFmpeg()) | ||
const videoRef = useRef<HTMLVideoElement | null>(null) | ||
const messageRef = useRef<HTMLParagraphElement | null>(null) | ||
const [loaded, setLoaded] = useState(false); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const ffmpegRef = useRef(new FFmpeg()); | ||
const videoRef = useRef<HTMLVideoElement | null>(null); | ||
const messageRef = useRef<HTMLParagraphElement | null>(null); | ||
|
||
const load = async () => { | ||
setIsLoading(true) | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const ffmpeg = ffmpegRef.current | ||
ffmpeg.on('log', ({ message }) => { | ||
if (messageRef.current) messageRef.current.innerHTML = message | ||
}) | ||
setIsLoading(true); | ||
const baseURL = "https://unpkg.com/@ffmpeg/[email protected].7/dist/umd"; | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on("log", ({ message }) => { | ||
if (messageRef.current) messageRef.current.innerHTML = message; | ||
}); | ||
// toBlobURL is used to bypass CORS issue, urls with the same | ||
// domain can be used directly. | ||
await ffmpeg.load({ | ||
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'), | ||
wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm') | ||
}) | ||
setLoaded(true) | ||
setIsLoading(false) | ||
} | ||
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"), | ||
wasmURL: await toBlobURL( | ||
`${baseURL}/ffmpeg-core.wasm`, | ||
"application/wasm" | ||
), | ||
}); | ||
setLoaded(true); | ||
setIsLoading(false); | ||
}; | ||
|
||
const transcode = async () => { | ||
const ffmpeg = ffmpegRef.current | ||
const ffmpeg = ffmpegRef.current; | ||
// u can use 'https://ffmpegwasm.netlify.app/video/video-15s.avi' to download the video to public folder for testing | ||
await ffmpeg.writeFile('input.avi', await fetchFile('https://raw.githubusercontent.com/ffmpegwasm/testdata/master/video-15s.avi')) | ||
await ffmpeg.exec(['-i', 'input.avi', 'output.mp4']) | ||
const data = (await ffmpeg.readFile('output.mp4')) as any | ||
await ffmpeg.writeFile( | ||
"input.avi", | ||
await fetchFile( | ||
"https://raw.githubusercontent.com/ffmpegwasm/testdata/master/video-15s.avi" | ||
) | ||
); | ||
await ffmpeg.exec(["-i", "input.avi", "output.mp4"]); | ||
const data = (await ffmpeg.readFile("output.mp4")) as any; | ||
if (videoRef.current) | ||
videoRef.current.src = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4' })) | ||
} | ||
videoRef.current.src = URL.createObjectURL( | ||
new Blob([data.buffer], { type: "video/mp4" }) | ||
); | ||
}; | ||
|
||
return loaded ? ( | ||
<div className="fixed top-[50%] left-[50%] translate-x-[-50%] translate-y-[-50%]"> | ||
|
@@ -72,5 +82,5 @@ export default function Home() { | |
</span> | ||
)} | ||
</button> | ||
) | ||
); | ||
} |
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 |
---|---|---|
|
@@ -5,11 +5,11 @@ import { toBlobURL, fetchFile } from "@ffmpeg/util"; | |
function App() { | ||
const [loaded, setLoaded] = useState(false); | ||
const ffmpegRef = useRef(new FFmpeg()); | ||
const videoRef = useRef<HTMLVideoElement | null>(null) | ||
const messageRef = useRef<HTMLParagraphElement | null>(null) | ||
const videoRef = useRef<HTMLVideoElement | null>(null); | ||
const messageRef = useRef<HTMLParagraphElement | null>(null); | ||
|
||
const load = async () => { | ||
const baseURL = "https://unpkg.com/@ffmpeg/[email protected].6/dist/esm"; | ||
const baseURL = "https://unpkg.com/@ffmpeg/[email protected].7/dist/esm"; | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on("log", ({ message }) => { | ||
if (messageRef.current) messageRef.current.innerHTML = message; | ||
|
@@ -31,16 +31,17 @@ function App() { | |
}; | ||
|
||
const transcode = async () => { | ||
const videoURL = "https://raw.githubusercontent.com/ffmpegwasm/testdata/master/video-15s.avi"; | ||
const videoURL = | ||
"https://raw.githubusercontent.com/ffmpegwasm/testdata/master/video-15s.avi"; | ||
const ffmpeg = ffmpegRef.current; | ||
await ffmpeg.writeFile("input.avi", await fetchFile(videoURL)); | ||
await ffmpeg.exec(["-i", "input.avi", "output.mp4"]); | ||
const fileData = await ffmpeg.readFile('output.mp4'); | ||
const fileData = await ffmpeg.readFile("output.mp4"); | ||
const data = new Uint8Array(fileData as ArrayBuffer); | ||
if (videoRef.current) { | ||
videoRef.current.src = URL.createObjectURL( | ||
new Blob([data.buffer], { type: 'video/mp4' }) | ||
) | ||
new Blob([data.buffer], { type: "video/mp4" }) | ||
); | ||
} | ||
}; | ||
|
||
|
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ import type { LogEvent } from '@ffmpeg/ffmpeg/dist/esm/types' | |
import { fetchFile, toBlobURL } from '@ffmpeg/util' | ||
import { defineComponent, ref } from 'vue' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/esm' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/esm' | ||
const videoURL = 'https://raw.githubusercontent.com/ffmpegwasm/testdata/master/video-15s.avi' | ||
export default defineComponent({ | ||
|
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ It is recommended to read [Overview](/docs/overview) first. | |
:::caution | ||
If you are a [vite](https://vitejs.dev/) user, use `esm` in **baseURL** instead of `umd`: | ||
|
||
~~https://unpkg.com/@ffmpeg/[email protected].6/dist/umd~~ => https://unpkg.com/@ffmpeg/[email protected].6/dist/esm | ||
~~https://unpkg.com/@ffmpeg/[email protected].7/dist/umd~~ => https://unpkg.com/@ffmpeg/[email protected].7/dist/esm | ||
::: | ||
|
||
```jsx live | ||
|
@@ -24,7 +24,7 @@ function() { | |
const messageRef = useRef(null); | ||
|
||
const load = async () => { | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/umd' | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on('log', ({ message }) => { | ||
messageRef.current.innerHTML = message; | ||
|
@@ -81,7 +81,7 @@ function() { | |
const messageRef = useRef(null); | ||
|
||
const load = async () => { | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/umd' | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on('log', ({ message }) => { | ||
messageRef.current.innerHTML = message; | ||
|
@@ -134,7 +134,7 @@ function() { | |
const messageRef = useRef(null); | ||
|
||
const load = async () => { | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/umd' | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on('log', ({ message }) => { | ||
messageRef.current.innerHTML = message; | ||
|
@@ -192,7 +192,7 @@ function() { | |
const messageRef = useRef(null); | ||
|
||
const load = async () => { | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/umd' | ||
const ffmpeg = ffmpegRef.current; | ||
// Listen to progress event instead of log. | ||
ffmpeg.on('progress', ({ progress, time }) => { | ||
|
@@ -243,7 +243,7 @@ function() { | |
const messageRef = useRef(null); | ||
|
||
const load = async () => { | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/umd' | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on('log', ({ message }) => { | ||
messageRef.current.innerHTML = message; | ||
|
@@ -313,7 +313,7 @@ function() { | |
const messageRef = useRef(null); | ||
|
||
const load = async () => { | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/umd' | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on('log', ({ message }) => { | ||
messageRef.current.innerHTML = message; | ||
|
@@ -372,7 +372,7 @@ function() { | |
const messageRef = useRef(null); | ||
|
||
const load = async () => { | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].6/dist/umd' | ||
const baseURL = 'https://unpkg.com/@ffmpeg/[email protected].7/dist/umd' | ||
const ffmpeg = ffmpegRef.current; | ||
ffmpeg.on('log', ({ message }) => { | ||
messageRef.current.innerHTML = message; | ||
|
@@ -425,18 +425,20 @@ function() { | |
|
||
:::note | ||
Required: | ||
|
||
- @ffmpeg/ffmpeg@0.12.7+ | ||
- @ffmpeg/core@0.12.4+ | ||
::: | ||
::: | ||
|
||
Please Check this PR: [Add WORKERFS support](https://github.com/ffmpegwasm/ffmpeg.wasm/pull/581) | ||
|
||
## Abort exec() with signal | ||
|
||
:::note | ||
Required: | ||
|
||
- @ffmpeg/ffmpeg@0.12.7+ | ||
- @ffmpeg/core@0.12.4+ | ||
::: | ||
::: | ||
|
||
Please check this PR: [abort signal](https://github.com/ffmpegwasm/ffmpeg.wasm/pull/573) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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