mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-28 02:32:11 +10:00
chore: update public repo
This commit is contained in:
parent
9891d7734d
commit
2423324540
8 changed files with 531 additions and 0 deletions
30
utils/opus.ts
Normal file
30
utils/opus.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { Bytes, write } from '@fuman/io'
|
||||
import { $ } from 'zx'
|
||||
|
||||
export async function generateOpusImageBlob(image: Uint8Array) {
|
||||
// todo we should probably not use ffprobe here but whatever lol
|
||||
const proc = $`ffprobe -of json -v error -show_entries stream=codec_name,width,height pipe:0`
|
||||
proc.stdin.write(image)
|
||||
proc.stdin.end()
|
||||
const json = await proc.json()
|
||||
|
||||
const img = json.streams[0]
|
||||
// https://www.rfc-editor.org/rfc/rfc9639.html#section-8.8
|
||||
const mime = img.codec_name === 'mjpeg' ? 'image/jpeg' : 'image/png'
|
||||
const description = 'Cover Artwork'
|
||||
|
||||
const res = Bytes.alloc(image.length + 128)
|
||||
write.uint32be(res, 3) // picture type = album cover
|
||||
write.uint32be(res, mime.length)
|
||||
write.rawString(res, mime)
|
||||
write.uint32be(res, description.length)
|
||||
write.rawString(res, description)
|
||||
write.uint32be(res, img.width)
|
||||
write.uint32be(res, img.height)
|
||||
write.uint32be(res, 0) // color depth
|
||||
write.uint32be(res, 0) // color index (unused, for gifs)
|
||||
write.uint32be(res, image.length)
|
||||
write.bytes(res, image)
|
||||
|
||||
return res.result()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue