-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move download buttons inside of list items
- Loading branch information
Showing
6 changed files
with
168 additions
and
24 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
69 changes: 69 additions & 0 deletions
69
examples/sound-effects/video-to-sfx/lib/mergeAndDownload.ts
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,69 @@ | ||
export async function mergeAndDownload( | ||
videoFile: File | null, | ||
audioData: string | ||
) { | ||
const { FFmpeg } = await import("@ffmpeg/ffmpeg"); | ||
const { fetchFile, toBlobURL } = await import("@ffmpeg/util"); | ||
const ffmpeg = new FFmpeg(); | ||
|
||
const load = async () => { | ||
const baseURL = "https://unpkg.com/@ffmpeg/[email protected]/dist/umd"; | ||
ffmpeg.on("log", ({ message }) => { | ||
console.log(message); | ||
}); | ||
await ffmpeg.load({ | ||
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"), | ||
wasmURL: await toBlobURL( | ||
`${baseURL}/ffmpeg-core.wasm`, | ||
"application/wasm" | ||
), | ||
}); | ||
}; | ||
const process = async () => { | ||
console.log("transcoding"); | ||
if (!videoFile) { | ||
throw new Error("No video file"); | ||
} | ||
|
||
if (videoFile) { | ||
await ffmpeg.writeFile( | ||
"input.mp4", | ||
await fetchFile(URL.createObjectURL(videoFile)) | ||
); | ||
} | ||
|
||
await ffmpeg.writeFile("audio.mpeg", await fetchFile(audioData)); | ||
|
||
await ffmpeg.exec(["-v", "error", "-i", "input.mp4", "-f", "null", "-"]); | ||
|
||
await ffmpeg.exec(["-v", "error", "-i", "audio.mpeg", "-f", "null", "-"]); | ||
|
||
await ffmpeg.exec([ | ||
"-v", | ||
"verbose", | ||
"-i", | ||
"input.mp4", | ||
"-i", | ||
"audio.mpeg", | ||
"-c:v", | ||
"copy", // Copy the video codec | ||
"-c:a", | ||
"aac", // Transcode audio to AAC | ||
"-strict", | ||
"experimental", | ||
"output.mp4", | ||
]); | ||
console.log("transcoding completed"); | ||
const data = await ffmpeg.readFile("output.mp4"); | ||
const final_url = URL.createObjectURL( | ||
new Blob([data.buffer], { type: "video/mp4" }) | ||
); | ||
const downloadLinkFinalVideo = document.createElement("a"); | ||
downloadLinkFinalVideo.href = final_url; | ||
downloadLinkFinalVideo.download = "final_output.mp4"; | ||
downloadLinkFinalVideo.click(); | ||
}; | ||
|
||
await load(); | ||
await process(); | ||
} |
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