Skip to content

Commit

Permalink
Fix adding an intro/outro with splitted HLS
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Jan 31, 2025
1 parent 05f105d commit 319932c
Show file tree
Hide file tree
Showing 2 changed files with 229 additions and 214 deletions.
27 changes: 17 additions & 10 deletions packages/ffmpeg/src/ffmpeg-edition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,32 @@ export class FFmpegEdition {
const mainProbe = await ffprobePromise(videoInputPath)
const fps = await getVideoStreamFPS(videoInputPath, mainProbe)
const { resolution } = await getVideoStreamDimensionsInfo(videoInputPath, mainProbe)
const mainHasAudio = await hasAudioStream(separatedAudioInputPath || videoInputPath, mainProbe)

const mainHasAudio = await hasAudioStream(separatedAudioInputPath || videoInputPath)

const introOutroProbe = await ffprobePromise(introOutroPath)
const introOutroHasAudio = await hasAudioStream(introOutroPath, introOutroProbe)

const command = this.commandWrapper.buildCommand([ ...this.buildInputs(options), introOutroPath ], inputFileMutexReleaser)
.output(outputPath)

const videoInput = 0

const audioInput = separatedAudioInputPath
? videoInput + 1
: videoInput

const introInput = audioInput + 1
let introAudio = introInput

if (!introOutroHasAudio && mainHasAudio) {
const duration = await getVideoStreamDuration(introOutroPath, introOutroProbe)

command.input('anullsrc')
command.withInputFormat('lavfi')
command.withInputOption('-t ' + duration)

introAudio++
}

await presetVOD({
Expand All @@ -159,7 +171,7 @@ export class FFmpegEdition {
// Add black background to correctly scale intro/outro with padding
const complexFilter: FilterSpecification[] = [
{
inputs: [ '1', '0' ],
inputs: [ `${introInput}`, `${videoInput}` ],
filter: 'scale2ref',
options: {
w: 'iw',
Expand All @@ -185,7 +197,7 @@ export class FFmpegEdition {
outputs: [ 'to-scale-bg' ]
},
{
inputs: [ '1', 'to-scale-bg' ],
inputs: [ `${introInput}`, 'to-scale-bg' ],
filter: 'scale2ref',
options: {
w: 'iw',
Expand Down Expand Up @@ -221,14 +233,9 @@ export class FFmpegEdition {
const mainFilterInputs = [ 'main' ]

if (mainHasAudio) {
mainFilterInputs.push('0:a')
mainFilterInputs.push(`${audioInput}:a`)

if (introOutroHasAudio) {
introOutroFilterInputs.push('1:a')
} else {
// Silent input
introOutroFilterInputs.push('2:a')
}
introOutroFilterInputs.push(`${introAudio}:a`)
}

if (type === 'intro') {
Expand Down
Loading

0 comments on commit 319932c

Please sign in to comment.