Sterling Butters
Sterling Butters

Reputation: 1175

FFMPEG & Node.js Spawn outputs nothing

I have the following Node.js code:

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);
});

Which outputs nothing on execution nor is any FFMPEG process generated as far as I can tell.

Is there anything obvious that I am missing?

Thanks in advance

Upvotes: 1

Views: 1737

Answers (2)

Aamer Alturi
Aamer Alturi

Reputation: 11

what is the event right when camera disconnected, I try this :

this.stream.on("close",code => {
            console.log(chalk.blue(`child process closed with code ${code}`));
        });

not work , and this :

this.stream.on("error", error => {
   console.log(chalk.red(`error: ${error}`));
});

and this :

this.stream.on("disconnect", code => {
        console.log(chalk.blue(`child process disconnect with code ${code}`));
});

Upvotes: 0

Doug W
Doug W

Reputation: 105

Your program is printing nothing because ffmpeg is not sending anything to stdout. If you listen to stderr as well, you'll see why.

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);
});

For me this outputs

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'

Adding the -hide_banner flag to the ffmpeg argument list will get rid of everything except for the actual error message.

Upvotes: 1

Related Questions