From 120b9665552b61552fdce594aac76bd9d2a3ccce Mon Sep 17 00:00:00 2001 From: tim000x3 Date: Wed, 16 Apr 2025 07:44:08 -0400 Subject: [PATCH] got seek and end time working on non-direct play --- src/ffmpeg.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ffmpeg.js b/src/ffmpeg.js index c503279..a4f4c74 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -126,8 +126,19 @@ class FFMPEG extends events.EventEmitter { } - if (typeof startTime !== 'undefined') - ffmpegArgs.push(`-ss`, startTime) + // Ensure startTime is a number (seconds), convert if needed + if (typeof startTime !== 'undefined') { + let ss = startTime; + if (typeof ss === 'string' && ss.endsWith('ms')) { + ss = parseInt(ss) / 1000; + } + if (typeof ss === 'number' && ss > 10000) { + // probably ms, convert to seconds + ss = ss / 1000; + } + ffmpegArgs.push(`-ss`, `${ss}`); + console.log(`[FFMPEG] Using custom start position: -ss ${ss}`); + } if (isConcatPlaylist == true) ffmpegArgs.push(`-f`, `concat`, @@ -558,9 +569,18 @@ class FFMPEG extends events.EventEmitter { `service_name="${this.channel.name}"`, ); - //t should be before -f + // Ensure duration is a number (seconds), convert if needed if (typeof duration !== 'undefined') { - ffmpegArgs.push(`-t`, `${duration}`); + let t = duration; + if (typeof t === 'string' && t.endsWith('ms')) { + t = parseInt(t) / 1000; + } + if (typeof t === 'number' && t > 10000) { + // probably ms, convert to seconds + t = t / 1000; + } + ffmpegArgs.push(`-t`, `${t}`); + console.log(`[FFMPEG] Using custom duration: -t ${t}`); } ffmpegArgs.push(`-f`, `mpegts`, `pipe:1`)