NodeJS生成FFMPEG进程无法正确理解参数

时间:2018-08-07 16:34:28

标签: node.js ffmpeg

我正在编写代码,以使用带乘法器的FFMPEG加速视频。 5倍的视频快5倍,0.5倍的视频慢2倍,等等。

此代码以前在其他用例中也可以使用,但是args数组似乎有问题。

var spawn = require('child_process').spawn;
var cmd = 'node_modules\\ffmpeg-binaries\\bin\\ffmpeg.exe';

speedupFilename = tmpdir + vts + 'speedup.mp4';

var args = ['-i', filename, '-filter:v ', '"setpts=PTS/' + multiplier + '"', speedupFilename];
console.log(cmd + ' ' + args.join(' '));

var proc = spawn(cmd, args);

/* code that reads stdout and print it out to console */

这将在控制台中打印出来:

node_modules\ffmpeg-binaries\bin\ffmpeg.exe -i C:\Users\User\AppData\Local\Temp\1533658543video.mp4 -filter:v  "setpts=PTS/0.10" C:\Users\User\AppData\Local\Temp\1533658543speedup.mp4
ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.0 (GCC)

   configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil      55. 34.100 / 55. 34.100
libavcodec     57. 64.100 / 57. 64.100
libavformat    57. 56.100 / 57. 56.100
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\User\AppData\Local\Temp\1533658543video.mp4':
Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: 
script.js:337 isomiso2avc1mp41
    encoder         : Lavf57.56.100
Duration: 00:00:00.12, start: 0.000000, bitrate: 9398 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 9340 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
    handler_name    : VideoHandler

[AVFilterGraph @ 05c67dc0] No such filter: '"setpts'
Error opening filters!

我的FFMPEG中有setpts过滤器,我调查了ffmpeg -filters

如果我在控制台中运行命令(输出的第一行),则可以正常运行。

如果我将-filter:v ', '"setpts=PTS/' + multiplier + '"'数组中的-filter:v "setpts=PTS/' + multiplier + '"'更改为args(删除', '以连接这两个数组项),那么它只会说At least one output file must be specified:< / p>

ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib

libavutil      55. 34.100 / 55. 34.100
libavcodec     57. 64.100 / 57. 64.100
libavformat    57. 56.100 / 57. 56.100
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100
Trailing options were found on the commandline.

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\User\AppData\Local\Temp\1533659280video.mp4':
Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands:
isomiso2avc1mp41
    encoder         : Lavf57.56.100
Duration: 00:00:00.12, start: 0.000000, bitrate: 9398 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 9340 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
    handler_name    : VideoHandler
At least one output file must be specified

1 个答案:

答案 0 :(得分:0)

我终于找到了解决方案。

在数组项'"pts=PTS/' + multiplier + '"'中,我必须删除引号。它们是无用的,因为无论如何参数都是孤立的,与命令行空间不同,这是不够的。