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(
|
export async function transcodeVideoStream(input: ReadableStream<Uint8Array>): Promise<ReadableStream<Uint8Array>> {
|
||||||
inputStream: ReadableStream<Uint8Array>,
|
const opts = {
|
||||||
): Promise<ReadableStream<Uint8Array>> {
|
'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', {
|
const command = new Deno.Command('ffmpeg', {
|
||||||
args: [
|
args: [
|
||||||
'-i',
|
...Object.entries(opts).flatMap(([k, v]) => [`-${k}`, v]),
|
||||||
'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
|
|
||||||
'pipe:1', // Output to stdout
|
'pipe:1', // Output to stdout
|
||||||
],
|
],
|
||||||
stdin: 'piped',
|
stdin: 'piped',
|
||||||
|
|
@ -38,7 +31,7 @@ export async function transcodeVideoStream(
|
||||||
|
|
||||||
// Pipe the input stream into FFmpeg stdin and ensure completion
|
// Pipe the input stream into FFmpeg stdin and ensure completion
|
||||||
const writer = process.stdin.getWriter();
|
const writer = process.stdin.getWriter();
|
||||||
const reader = inputStream.getReader();
|
const reader = input.getReader();
|
||||||
|
|
||||||
async function pumpInput() {
|
async function pumpInput() {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue