以下是版本:
节点v12.9.1,npm 6.10.2,ffmpeg.js@4.2.9003
存储库:https://github.com/Kagami/ffmpeg.js
decode.js代码如下:
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,然后我得到了错误:
[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发布于 2020-07-21 17:28:58
这是因为使用了npm install ffmpeg.js。
它不包含image2复用器和mjpeg编码器。
所以我用docker构建并修改了makefile:
WEBM_MUXERS = webm ogg null image2
WEBM_ENCODERS = libvpx_vp8 libopus png mjpeg然后制作并获取ffmpeg-webm.js
测试代码:
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);并获取:
{
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
]
}它起作用了!
希望对你有帮助~
https://stackoverflow.com/questions/62950128
复制相似问题