我有以下 Node.js 代码:
var ffmpeg = spawn('ffmpeg', ["-f","v4l2",
"-framerate","30",
"-video_size","1920x1080",
"-i","/dev/video0",
"-f","mpegts",
"-codec:v","mpeg1video",
"-s","1920x1080",
"-b:v","3000k",
"qscale:v","20",
"-bf","0",
"http://localhost:8081/DEFAULT",
"pipe:1"]);
ffmpeg.stdout.on('data', function(chunk){
var textChunk = chunk.toString('utf8');
console.log(textChunk);
});
据我所知,它在执行时不输出任何内容,也没有生成任何 FFMPEG 过程。
我有什么明显的缺失吗?
提前致谢
您的程序没有打印任何内容,因为 ffmpeg 没有向标准输出发送任何内容。如果你也听stdrr,你就会明白为什么。
var ffmpeg = spawn('ffmpeg', ["-f","v4l2",
"-framerate","30",
"-video_size","1920x1080",
"-i","/dev/video0",
"-f","mpegts",
"-codec:v","mpeg1video",
"-s","1920x1080",
"-b:v","3000k",
"qscale:v","20",
"-bf","0",
"http://localhost:8081/DEFAULT",
"pipe:1"]);
ffmpeg.stdout.on('data', function(chunk){
var textChunk = chunk.toString('utf8');
console.log(textChunk);
});
ffmpeg.stderr.on('data', function(chunk){
var textChunk = chunk.toString('utf8');
console.error(textChunk);
});
对我来说,这输出
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Unknown input format: 'v4l2'
将-hide_banner
标志添加到 ffmpeg 参数列表将删除除实际错误消息之外的所有内容。
相机断开连接时会发生什么事件,我试试这个:
this.stream.on("close",code => {
console.log(chalk.blue(`child process closed with code ${code}`));
});
不工作,这个:
this.stream.on("error", error => {
console.log(chalk.red(`error: ${error}`));
});
而这个:
this.stream.on("disconnect", code => {
console.log(chalk.blue(`child process disconnect with code ${code}`));
});