Julian Bilcke
commited on
Commit
·
b522c4a
1
Parent(s):
7822bfc
hmm
Browse files
src/bug-in-bun/aitube_ffmpeg/analyze/getMediaInfo.ts
CHANGED
|
@@ -19,16 +19,21 @@ export async function getMediaInfo(input: string): Promise<MediaMetadata> {
|
|
| 19 |
// If the input is a base64 string
|
| 20 |
if (input.startsWith("data:")) {
|
| 21 |
// Extract the base64 content
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
// Decode the base64 content to a buffer
|
| 28 |
-
const buffer = Buffer.from(base64Content, 'base64')
|
| 29 |
|
| 30 |
// Generate a temporary file name
|
| 31 |
-
const tempFileName = join(tmpdir(), `temp-media-${Date.now()}`);
|
|
|
|
| 32 |
|
| 33 |
// Write the buffer to a temporary file
|
| 34 |
await writeFile(tempFileName, buffer);
|
|
|
|
| 19 |
// If the input is a base64 string
|
| 20 |
if (input.startsWith("data:")) {
|
| 21 |
// Extract the base64 content
|
| 22 |
+
// Extract the base64 content
|
| 23 |
+
const [head, tail] = input.split(";base64,")
|
| 24 |
+
if (!tail) {
|
| 25 |
+
throw new Error("Invalid base64 data");
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const extension = head.split("/").pop() || ""
|
| 29 |
+
const base64Content = tail || ""
|
| 30 |
|
| 31 |
// Decode the base64 content to a buffer
|
| 32 |
+
const buffer = Buffer.from(base64Content, 'base64')
|
| 33 |
|
| 34 |
// Generate a temporary file name
|
| 35 |
+
const tempFileName = join(tmpdir(), `temp-media-${Date.now()}.${extension}`);
|
| 36 |
+
|
| 37 |
|
| 38 |
// Write the buffer to a temporary file
|
| 39 |
await writeFile(tempFileName, buffer);
|