Skip to content

Commit

Permalink
Temp remove MP4Box
Browse files Browse the repository at this point in the history
  • Loading branch information
vassbo authored Oct 17, 2024
1 parent 351f278 commit afd026b
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/electron/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { app, dialog, shell } from "electron"
import { ExifImage } from "exif"
import fs, { type Stats } from "fs"
import MP4Box from "MP4Box"
// import MP4Box from "MP4Box"
import path, { join, parse } from "path"
import { uid } from "uid"
import { FILE_INFO, MAIN, OPEN_FOLDER, OUTPUT, READ_FOLDER, SHOW, STORE } from "../../types/Channels"
Expand Down Expand Up @@ -406,39 +406,40 @@ export function readExifData({ id }: any, e: any) {

// GET MEDIA CODEC
export function getMediaCodec(data: any) {
extractCodecInfo(data)
toApp(MAIN, { channel: "MEDIA_CODEC", data: { ...data, codecs: [], mimeType: getMimeType(data.path), mimeCodec: "" } })
// extractCodecInfo(data)
}

async function extractCodecInfo(data: any) {
const arrayBuffer: any = toArrayBuffer(await readFileBufferAsync(data.path))
// async function extractCodecInfo(data: any) {
// const arrayBuffer: any = toArrayBuffer(await readFileBufferAsync(data.path))

const mp4boxfile = MP4Box.createFile()
mp4boxfile.onError = (e: Error) => console.error("MP4Box error:", e)
mp4boxfile.onReady = (info: any) => {
const codecs = info.tracks.map((track: any) => track.codec)
const mimeType = getMimeType(data.path)
const mimeCodec = `${mimeType}; codecs="${codecs.join(", ")}"`
toApp(MAIN, { channel: "MEDIA_CODEC", data: { ...data, codecs, mimeType, mimeCodec } })
}
// const mp4boxfile = MP4Box.createFile()
// mp4boxfile.onError = (e: Error) => console.error("MP4Box error:", e)
// mp4boxfile.onReady = (info: any) => {
// const codecs = info.tracks.map((track: any) => track.codec)
// const mimeType = getMimeType(data.path)
// const mimeCodec = `${mimeType}; codecs="${codecs.join(", ")}"`
// toApp(MAIN, { channel: "MEDIA_CODEC", data: { ...data, codecs, mimeType, mimeCodec } })
// }

arrayBuffer.fileStart = 0
mp4boxfile.appendBuffer(arrayBuffer)
mp4boxfile.flush()
}
// arrayBuffer.fileStart = 0
// mp4boxfile.appendBuffer(arrayBuffer)
// mp4boxfile.flush()
// }

function getMimeType(path: string) {
const ext = path.split(".").pop()?.toLowerCase() || ""
return mimeTypes[ext] || ""
}

function toArrayBuffer(buffer: Buffer) {
const arrayBuffer = new ArrayBuffer(buffer.length)
const view = new Uint8Array(arrayBuffer)
for (let i = 0; i < buffer.length; ++i) {
view[i] = buffer[i]
}
return arrayBuffer
}
// function toArrayBuffer(buffer: Buffer) {
// const arrayBuffer = new ArrayBuffer(buffer.length)
// const view = new Uint8Array(arrayBuffer)
// for (let i = 0; i < buffer.length; ++i) {
// view[i] = buffer[i]
// }
// return arrayBuffer
// }

//////

Expand Down

0 comments on commit afd026b

Please sign in to comment.