0
當我在命令行中輸入以下命令時,FFMPEG完全正確並按預期靜音視頻的各個部分。nodejs 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' }
最好的我能想到的是它與'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 += ",";
}
}
每個分組之間擺脫空間的,它精美的工作。
'沒有這樣的過濾器:「‘volume'' - 它認爲篩選器名稱是「’volume',可能是因爲沒有被添加收盤報價。如果你可以避免任何空格,你可以在開始和結束時刪除雙引號。 – Mulvya
@Mulvya你關於取出空格的建議非常好用!如果你想把它作爲答案,我會很樂意將它標記爲正確的! – shaun