如何从没有格式的FFmpeg获取stdout?

时间:2017-10-04 14:14:07

标签: node.js command-line ffmpeg stream

我需要获取没有格式化的rtsp流的stdout。愿有人知道怎么做吗?

如果尝试从命令行手动ffmpeg,这就是我得到的:

root@cl-som-imx6ul-sid: ffmpeg -rtsp_transport tcp -i rtsp://admin:pass@10.168.9.141/Streaming/channels/1/ -vcodec cpoy -acodec copy -

ffmpeg version 3.2.5-1~bpo8+1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --prefix=/usr --extra-version='1~bpo8+1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --disable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil      55. 34.101 / 55. 34.101
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.101 / 57. 56.101
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libavresample   3.  1.  0 /  3.  1.  0
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100
Input #0, rtsp, from 
'rtsp://admin:pass@10.168.9.141/Streaming/channels/1/':
Metadata:
title           : Media Presentation
Duration: N/A, start: 0.240000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 640x480, 25 fps, 25.08 tbr, 90k tbn, 50 tbc
[NULL @ 0x5683bc30] Unable to find a suitable output format for 'pipe:'
 pipe:: Invalid argument

NodeJS代码示例

this.stream = child_process.spawn("ffmpeg", ["-rtsp_transport", "tcp", "-i", this.url, '-acodec', 'copy', '-vcodec', 'copy', '-'], {
  detached: false
});
this.inputStreamStarted = true;
this.stream.stdout.on('data', function(data) {
  return self.emit('mpeg1data', data);
});
this.stream.stderr.on('data', function(data) {
  return self.emit('ffmpegError', data);
});

1 个答案:

答案 0 :(得分:1)

输出管道时,您需要手动指示ffmpeg您要使用的输出格式。您可以使用-f选项执行此操作。例如:

ffmpeg -rtsp_transport tcp -i rtsp://admin:pass@10.168.9.141/Streaming/channels/1/ -c copy -f mpegts -

由于正在使用-c copy,因此不执行任何重新编码。