mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
transcode: use a structured object for ffmpeg options
This commit is contained in:
parent
82f16e0cfe
commit
25d5db8db6
1 changed files with 15 additions and 22 deletions
|
|
@ -1,26 +1,19 @@
|
|||
export async function transcodeVideoStream(
|
||||
inputStream: ReadableStream<Uint8Array>,
|
||||
): Promise<ReadableStream<Uint8Array>> {
|
||||
export async function transcodeVideoStream(input: ReadableStream<Uint8Array>): Promise<ReadableStream<Uint8Array>> {
|
||||
const opts = {
|
||||
'i': 'pipe:0', // Read input from stdin
|
||||
'c:v': 'libx264', // Convert to H.264
|
||||
'preset': 'veryfast', // Encoding speed
|
||||
'loglevel': 'fatal', // Suppress logs
|
||||
'crf': '23', // Compression level (lower = better quality)
|
||||
'c:a': 'aac', // Convert to AAC audio
|
||||
'b:a': '128k', // Audio bitrate
|
||||
'movflags': 'frag_keyframe+empty_moov', // Ensures MP4 streaming compatibility
|
||||
'f': 'mp4', // Force MP4 format
|
||||
};
|
||||
|
||||
const command = new Deno.Command('ffmpeg', {
|
||||
args: [
|
||||
'-i',
|
||||
'pipe:0', // Read input from stdin
|
||||
'-c:v',
|
||||
'libx264', // Convert to H.264
|
||||
'-preset',
|
||||
'veryfast', // Encoding speed
|
||||
'-loglevel',
|
||||
'fatal', // Suppress logs
|
||||
'-crf',
|
||||
'23', // Compression level (lower = better quality)
|
||||
'-c:a',
|
||||
'aac', // Convert to AAC audio
|
||||
'-b:a',
|
||||
'128k', // Audio bitrate
|
||||
'-movflags',
|
||||
'frag_keyframe+empty_moov', // Ensures MP4 streaming compatibility
|
||||
'-f',
|
||||
'mp4', // Force MP4 format
|
||||
...Object.entries(opts).flatMap(([k, v]) => [`-${k}`, v]),
|
||||
'pipe:1', // Output to stdout
|
||||
],
|
||||
stdin: 'piped',
|
||||
|
|
@ -38,7 +31,7 @@ export async function transcodeVideoStream(
|
|||
|
||||
// Pipe the input stream into FFmpeg stdin and ensure completion
|
||||
const writer = process.stdin.getWriter();
|
||||
const reader = inputStream.getReader();
|
||||
const reader = input.getReader();
|
||||
|
||||
async function pumpInput() {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue