nodejs FFMPEG参数问题

时间:2016-08-16 17:24:47

标签: node.js ffmpeg

当我在命令行中输入以下命令时,FFMPEG完全正确并按预期静音视频部分。

C:\>ffmpeg -y -i C:/Users/ADMINI~1/AppData/Local/Temp/2/0400028520160811144100001i100.mp4 -af "volume=enable='between(t,1,3)':volume=0, volume=enable='between(t,10,12)':volume=0, volume=enable='between(t,4,6)':volume=0, volume=enable='between(t,7,9)':volume=0" -c:v copy -movflags +faststart c:\temp\31e7ac4063d111e6bdc67f1f7f7b55d3.mp4
ffmpeg version N-79651-ge1c2048 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.3 (GCC)
  configuration: --prefix=/usr/local/x86_64-w64-mingw32 --enable-gpl --enable-nonfree --enable-libx264 --enable-libfdk_aac --enable-static --enable-runtime-cpudetect --enable-w32threads --disable-shared --disable-ffplay --disable-ffserver --arch=x86_64 --extra-cflags=-I/local/x86_64-w64-mingw32/include --extra-ldflags='-L/local/x86_64-w64-mingw32/lib -static'
  libavutil      55. 22.101 / 55. 22.101
  libavcodec     57. 38.100 / 57. 38.100
  libavformat    57. 34.103 / 57. 34.103
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 44.100 /  6. 44.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/ADMINI~1/AppData/Local/Temp/2/0400028520160811144100001i100.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.34.103
  Duration: 00:00:12.78, start: 0.000000, bitrate: 4074 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 4006 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[mp4 @ 03a8e5e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, mp4, to 'c:\temp\31e7ac4063d111e6bdc67f1f7f7b55d3-AudRedact.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.34.103
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31, 4006 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc57.38.100 aac
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[mp4 @ 03a8e5e0] Starting second pass: moving the moov atom to the beginning of the file24.3x
frame=  383 fps=0.0 q=-1.0 Lsize=    6325kB time=00:00:12.73 bitrate=4068.3kbits/s speed=24.7x
video:6244kB audio:69kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.191899%
[aac @ 03776160] Qavg: 51080.756

但是,如果我以编程方式在节点中构建相同的内容:

function redactAudio(tempFilePath, arrPairs, cb){
    // ffmpeg -loglevel fatal -y -i video.mp4 -af "volume=enable='between(t,5,10)':volume=0, volume=enable='between(t,15,20)':volume=0" -c:v copy -movflags +faststart output.mp4

    var tempBuff = Buffer.alloc(16);
    jsuuid.v1(null, tempBuff, 0);
    var outFileName = tempBuff.toString('hex') + path2.extname(tempFilePath);

    var volStr = '"';
    for (var i = 0; i < arrPairs.length; i++) {
        volStr += "volume=enable='between(t," + arrPairs[i].start + "," + arrPairs[i].end + ")':volume=0";
        if (i !== arrPairs.length - 1) {
            volStr += ", ";
        } else {
            volStr += '"';
        }
    }

    child_process.execFile(
        'ffmpeg',
        [
            /*'-loglevel', 'fatal',*/
            '-y', '-i', tempFilePath,
            '-af', volStr,
            '-c:v', 'copy',
            '-movflags', '+faststart', outFileName
        ],
        {
            cwd: tempDir,
            maxBuffer: Infinity
        },
        function(err, stdout, stderr) {
            if (err) {
                console.error(clc.magentaBright(clc.whiteBright('FFMPEG - ERROR OCC: ', path2.basename(tempFilePath), ' : ', stderr, '\n')));
                return cb(err, 'FFMpeg Failed: ' +  JSON.stringify({ stdout: stdout, stderr: stderr} ));
            } else {
                console.log(clc.magentaBright(clc.whiteBright('FFMPEG - Finished:  ', path2.basename(tempFilePath), '\n')));
                return cb(null, outFileName);
            }
        }
    );  
}

请帮助我了解发生了什么,因为每次从节点运行时都会出现以下错误。

FFMPEG - ERROR OCC:  0400028520160811144100001i100.mp4  :  ffmpeg version N-79651-ge1c2048 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.3 (GCC)
  configuration: --prefix=/usr/local/x86_64-w64-mingw32 --enable-gpl --enable-nonfree --enable-libx264 --enable-libfdk_aac --enable-static --enable-runtime-cpudetect --enable-w32threads --disable-shared --disable-ffplay --disable-ffserver --arch=x86_64 --extra-cflags=-I/local/x86_64-w64-mingw32/include --extra-ldflags='-L/local/x86_64-w64-mingw32/lib -static'
  libavutil      55. 22.101 / 55. 22.101
  libavcodec     57. 38.100 / 57. 38.100
  libavformat    57. 34.103 / 57. 34.103
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 44.100 /  6. 44.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/ADMINI~1/AppData/Local/Temp/2/0400028520160811144100001i100.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.34.103
  Duration: 00:00:12.78, start: 0.000000, bitrate: 4074 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 4006 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[AVFilterGraph @ 00381600] No such filter: '"volume'
Error opening filters!

0400028520160811144100001i100.mp4 
 { Error: Command failed: ffmpeg -y -i C:/Users/ADMINI~1/AppData/Local/Temp/2/0400028520160811144100001i100.mp4 -af "volume=enable='between(t,1,3)':volume=0, volume=enable='between(t,10,12)':volume=0, volume=enable='between(t,4,6)':volume=0, volume=enable='between(t,7,9)':volume=0" -c:v copy -movflags +faststart ea1eae2063d211e6bbf2af16c2e9be57.mp4
ffmpeg version N-79651-ge1c2048 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.3 (GCC)
  configuration: --prefix=/usr/local/x86_64-w64-mingw32 --enable-gpl --enable-nonfree --enable-libx264 --enable-libfdk_aac --enable-static --enable-runtime-cpudetect --enable-w32threads --disable-shared --disable-ffplay --disable-ffserver --arch=x86_64 --extra-cflags=-I/local/x86_64-w64-mingw32/include --extra-ldflags='-L/local/x86_64-w64-mingw32/lib -static'
  libavutil      55. 22.101 / 55. 22.101
  libavcodec     57. 38.100 / 57. 38.100
  libavformat    57. 34.103 / 57. 34.103
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 44.100 /  6. 44.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/ADMINI~1/AppData/Local/Temp/2/0400028520160811144100001i100.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.34.103
  Duration: 00:00:12.78, start: 0.000000, bitrate: 4074 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 4006 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[AVFilterGraph @ 00381600] No such filter: '"volume'
Error opening filters!

    at ChildProcess.exithandler (child_process.js:202:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
  killed: false,
  code: 1,
  signal: null,
  cmd: 'ffmpeg -y -i C:/Users/ADMINI~1/AppData/Local/Temp/2/0400028520160811144100001i100.mp4 -af "volume=enable=\'between(t,1,3)\':volume=0, volume=enable=\'between(t,10,12)\':volume=0, volume=enable=\'between(t,4,6)\':volume=0, volume=enable=\'between(t,7,9)\':volume=0" -c:v copy -movflags +faststart ea1eae2063d211e6bbf2af16c2e9be57.mp4' }

我最好能想到的是它与\#39;在volStr,但我不知道如何以任何其他方式创建它。

在@Mulvya评论之后我将我的for循环改为

var volStr = '';
for (var i = 0; i < arrPairs.length; i++) {
    volStr += "volume=enable='between(t," + arrPairs[i].start + "," + arrPairs[i].end + ")':volume=0";
    if (i !== arrPairs.length - 1) {
        volStr += ",";
    }
}

摆脱每个分组之间的空间,它工作得很漂亮。

1 个答案:

答案 0 :(得分:1)

无法调试nodeJS字符串形成时发生的事情,但if statement表示不会添加结束语。

您有两种解决方法。摆脱No such filter: '"volume'字符串中的空格。或者您可以使用一个音量过滤器。

-af