Fluent FFMPEG complex filter to split file into multiple outputs

1.9k Views Asked by At

It appears possible to have multiple outputs from a single FFMPEG command: ffmpeg overlay on multiple outputs

I'd like to know how to do this in FFMPEG. I'm specifically using the complexFilter option in an attempt to split the video into 4 different sizes and place an overlay, and then save the 4 resulting files.

The code is my attempt to simply split the video into 4 and save it. I get the Error: ffmpeg exited with code 1: Filter split:output3 has an unconnected output error. I'm unsure how to connect the output to a file in fluent-ffmpeg.

    let ffmpegCommand = ffmpeg() 
        .addInput(path.join(__dirname, PROCESSING_CACHE_DIRECTORY, "tempImage_%d.jpg"))

        .addOutput(outputPathFull)
        .addOutput(outputPathMed)
        .addOutput(outputPathSmall)
        .addOutput(outputPathThumb)


        .toFormat('mp4')
        .videoCodec('libx264')
        .outputOptions('-pix_fmt yuv420p')
        .complexFilter([
        {
                filter: 'split', options: '4',
                inputs: ['0:v'], outputs: [outputPathFull, outputPathMed, outputPathSmall, outputPathThumb]
            },
        ])

When I flip the outputs and put them below the complexFilter, I get 4 files - one with the appropriate quality (and 4x bigger than expected) and the others in very low quality.

1

There are 1 best solutions below

0
On

The correct way to do this in ffmpeg is to define the desired filters for each output using -map, follow the example with fluent-ffmpeg:

let ffmpeg = require('fluent-ffmpeg')
let fileName = 'video.mp4'
let outputID1 = '1'
let outputID2 = '2'
let outputID3 = '3'
let outputID4 = '4'
let outputPathFull = 'out-1.mp4'
let outputPathMed = 'out-2.mp4'
let outputPathSmall = 'out-3.mp4'
let outputPathThumb = 'out-4.mp4'

ffmpeg() 
.addInput(path.join(__dirname, PROCESSING_CACHE_DIRECTORY, fileName))
.complexFilter([
{
        filter: 'split', options: '4',
        inputs: ['0:v'], outputs: [outputID1, outputID2, outputID3, outputID4]
    },
])

.output(outputPathFull)
.map(outputID1)
.toFormat('mp4')
.addOutputOption('-c:v libx264')
.addOutputOption('-pix_fmt yuv420p')

.output(outputPathMed)
.map(outputID2)
.toFormat('mp4')
.addOutputOption('-c:v libx264')
.addOutputOption('-pix_fmt yuv420p')

.output(outputPathSmall)
.map(outputID3)
.toFormat('mp4')
.addOutputOption('-c:v libx264')
.addOutputOption('-pix_fmt yuv420p')

.output(outputPathThumb)
.map(outputID4)
.toFormat('mp4')
.addOutputOption('-c:v libx264')
.addOutputOption('-pix_fmt yuv420p')

.run()