Search code examples
node.jsffmpeggoogle-cloud-functionsfluent-ffmpeg

Intermittent pixel format error when using fluent-ffmpeg


I'm using the (excellent!) node-fluent-ffmpeg library as the first step in a video processing pipeline. Depending on the source video I provide to node-fluent-ffmpeg (videos are coming from same provider which makes this behavior surprising, but I digress), I sometimes see the following error when piping the output to the next ffmpeg processor in my pipeline:

Unable to parse option value "-1" as pixel format

Per this issue I have tried setting inputFormat('mp4'), videoCodec('libx264') and .inputOption('-pix_fmt yuv420p'). The first two don't seem to have any effect and the third causes the following error: "Error: ffmpeg exited with code 1: Option pixel_format not found." (To complicate things, I'm running this process inside a Google Cloud Function, so I'm unclear how to query for which pix_fmts are available.)

Does anyone know how I can work around this issue?

Here's my latest attempt in full:

  const process = ffmpeg({source: stream})
    .inputFormat('mp4')
    .inputOption('-pix_fmt yuv420p')
    .setFfmpegPath(ffmpeg_static.path)
    .videoBitrate(1024)
    .videoCodec('libx264')
    .aspect('1:1')
    .format('mp4')
    .noAudio()
    .seekInput(start)
    .duration(duration)
    .save(destination);

I was able to query ffmpeg for the available pixel formats and, while yuv420p isn't available, a number of others are. The closest (textual) match is yuv4mpegpipe, but that results in the same error.


Solution

  • yuv4mpegpipe is not a pixel format, Its an input/output format. The reason your code is not working is -pix_fmt yuv420p is an outputOption not an inputOption. It's probably best to not set inputFormat either, and let ffmpeg decide automatically.