Kagami/ffmpeg.js webm to images got Unable to find a suitable output format for '%04d.jpg' error

530 Views Asked by At

Here is versions:

node v12.9.1, npm 6.10.2, [email protected]

repo: https://github.com/Kagami/ffmpeg.js

decode.js code like this:

const fs = require('fs');
const ffmpeg = require('ffmpeg.js');

const testData = new Uint8Array(fs.readFileSync("test/test.webm"));
const result = ffmpeg({
    MEMFS: [{ name: "test.webm", data: testData }],
    arguments: ["-i", "test.webm",  "-hide_banner", "%04d.jpg" ],
});

node decode.js then I got errors:

[vp8 @ 0x6a9850] Warning: not compiled with thread support, using thread emulation
[vorbis @ 0x6ac650] Warning: not compiled with thread support, using thread emulation
Input #0, matroska,webm, from 'test.webm':
  Metadata:
    encoder         : Lavf56.40.100
  Duration: 00:00:03.95, start: 0.000000, bitrate: 798 kb/s
    Stream #0:0: Video: vp8, yuv420p, 854x480, SAR 1:1 DAR 427:240, 24 fps, 24 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1: Audio: vorbis, 48000 Hz, stereo, fltp (default)
    Stream #0:2(eng): Subtitle: webvtt
[NULL @ 0x6ae530] Unable to find a suitable output format for '%04d.jpg'
%04d.jpg: Invalid argument
1

There are 1 best solutions below

0
On

This is because of the use npm install ffmpeg.js .

It does not contain image2muxer and mjpeg encoder .

So I build with docker and modify makefile:

WEBM_MUXERS = webm ogg null image2
WEBM_ENCODERS = libvpx_vp8 libopus png mjpeg

then make and get the ffmpeg-webm.js

Test code:

const fs = require('fs');
const ffmpeg = require('./ffmpeg-webm.js');

const testData = new Uint8Array(fs.readFileSync("test/test.webm"));
const result = ffmpeg({
    MEMFS: [{ name: "test.webm", data: testData }],
    arguments: ["-i", "test.webm",  "-hide_banner", "%04d.jpg" ],
});
const out = result.MEMFS[0];
console.log(out);

and get:

{
  name: '0001.jpg',
  data: Uint8Array [
    137,  80,  78,  71,  13,  10,  26,  10,   0,   0,   0,  13,
     73,  72,  68,  82,   0,   0,   3,  86,   0,   0,   1, 224,
      8,   2,   0,   0,   0,  41,  50, 107, 125,   0,   0,   0,
      9, 112,  72,  89, 115,   0,   0,   0,   1,   0,   0,   0,
      1,   0,  79,  37, 196, 214,   0,   0,  16,   0,  73,  68,
     65,  84, 120, 156, 220, 221, 247, 111,  91, 249, 153,  47,
    254, 221, 205, 100,  48,  30, 219,  80, 133,  58,  84, 161,
     10, 177, 129,  21, 172,  96,   5,  69,  73,  80, 133, 228,
      2,  87, 184,  72,
    ... 524188 more items
  ]
}

It works!

Hope it helps you ~