我正试图在ffmpeg.js的帮助下从客户端的mp4中提取图像/帧。
等效Ffmpeg命令:
ffmpeg -i Sample.mp4 -r 1输出%d.png
但是我可以尝试从jpeg文件创建webm文件,但我不能反过来并最终出现以下错误消息
无法为'output%d.png'
找到合适的输出格式
这是我正在尝试使用的代码。
var ffmpeg = require("ffmpeg.js/ffmpeg-mp4");
var fs = require("fs");
var stdout = "";
var stderr = "";
var testData = new Uint8Array(fs.readFileSync("Sample.mp4"));
var result = ffmpeg({
MEMFS: [{name: "Sample.mp4", data: testData}],
stdin: function() {},
arguments: ["-i", "Sample.mp4","-r","1", "output%d.png"],
});
console.log(result.MEMFS.length)
if(result.MEMFS.length>0){
var out = result.MEMFS[0].data;
fs.writeFileSync("test.jpg", Buffer(out.data));
}
控制台输出
ffmpeg version n3.1.2 Copyright (c) 2000-2016 the FFmpeg developers
built with emcc (Emscripten gcc/clang-like replacement) 1.36.7 ()
configuration: --cc=emcc --enable-cross-compile --target-os=none --arch=x86 --disable-runtime-cpudetect --disable-asm --disable-fast-unaligned --disable-pthreads --disable-w32threads --di
sable-os2threads --disable-debug --disable-stripping --disable-all --enable-ffmpeg --enable-avcodec --enable-avformat --enable-avutil --enable-swresample --enable-swscale --enable-avfilter
--disable-network --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder=vp8 --enable-decoder=vp9 --enable-decoder=theora --enable-decoder=mpeg2vid
eo --enable-decoder=mpeg4 --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=png --enable-decoder=mjpeg --enable-decoder=vorbis --enable-decoder=opus --enable-decoder=mp3 --enable
-decoder=ac3 --enable-decoder=aac --enable-decoder=ass --enable-decoder=ssa --enable-decoder=srt --enable-decoder=webvtt --enable-demuxer=matroska --enable-demuxer=ogg --enable-demuxer=avi
--enable-demuxer=mov --enable-demuxer=flv --enable-demuxer=mpegps --enable-demuxer=image2 --enable-demuxer=mp3 --enable-demuxer=concat --enable-protocol=file --enable-filter=aresample --ena
ble-filter=scale --enable-filter=crop --enable-filter=overlay --disable-bzlib --disable-iconv --disable-libxcb --disable-lzma --disable-sdl --disable-securetransport --disable-xlib --disabl
e-zlib --enable-encoder=libx264 --enable-encoder=libmp3lame --enable-encoder=aac --enable-muxer=mp4 --enable-muxer=mp3 --enable-muxer=null --enable-gpl --enable-libmp3lame --enable-libx264
--extra-cflags=-I../lame/dist/include --extra-ldflags=-L../lame/dist/lib
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavfilter 6. 47.100 / 6. 47.100
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
[h264 @ 0x809d50] Warning: not compiled with thread support, using thread emulation
[aac @ 0x80e640] Warning: not compiled with thread support, using thread emulation
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Sample.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.56.100
Duration: 00:01:00.00, start: 0.000000, bitrate: 137 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 360x214, 113 kb/s, 1 fps, 1 tbr, 16384 tbn, 32768 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, mono, fltp, 23 kb/s (default)
Metadata:
handler_name : SoundHandler
[NULL @ 0x810d00] Unable to find a suitable output format for 'output%d.png'
output%d.png: Invalid argument
答案 0 :(得分:1)
您--disable-all
要“禁用构建组件,库和程序”,但您没有包含--enable-muxer=image2
(可能还有其他一些组件)。
我建议不要使用--disable-all
,除非您需要--enable-headaches
,因为需要重新编译以启用被遗忘的组件。
另外,请避免使用--disable-asm
:这会使事情变得不必要地慢。