Node.js子进程问题与Args - Quotes问题?,FFMPEG问题? [英] Node.js Child Process Issue with Args - Quotes Issue?, FFMPEG issue?

查看:210
本文介绍了Node.js子进程问题与Args - Quotes问题?,FFMPEG问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够从Node.js应用程序执行FFMPEG。我相信这个问题可能与正确指定命令行参数,而不是特定于FFMPEG,但因为我一直无法缩小问题,我提出我的整个问题。



我可以从命令提示符执行以下命令

  C: \\Brad\ffmpeg.exe -f dshow -i audio =Microphone(SoundMAX Integratedtestaaa.mp3 



<现在,我尝试在Node.js应用程序中执行同样的操作:

  childProcess = child_process.spawn('C:\\Brad\\ffmpeg.exe',['-f','dshow' '-i','audio =Microphone(SoundMAX Integrated','testaaa.mp3']); 
childProcess.stderr.on('data',function(data){
console.log ('StdioSource从STDERR接收数据:'+ data);
});

strong>在Node.js中,FFMPEG失败!错误是:

  [dshow @ 0000000001eded80]找不到音频设备。 
audio =Microphone(SoundMAX Integrated:Input / output error

一些原因这是一个奇怪的权限错误,我决定从我的Node应用程序中运行FFMPEG与 -list_devices true ,并且确定,列出的设备: p>

  [dshow @ 000000000228ecc0] DirectShow视频设备
[dshow @ 000000000228ecc0]无法枚举视频设备
[ dshow @ 000000000228ecc0] DirectShow音频设备
[dshow @ 000000000228ecc0]麦克风(SoundMAX集成)

有关为什么我无法在FFMPEG的参数中正确指定音频输入设备的问题,或者为什么FFMPEG在作为Node.js的子进程运行时无法识别我的音频输入设备?

解决方案

Brandon's在正确的轨道上。当你在Windows命令行上使用双引号括住参数时,shell将它们关闭,程序看到它们不引用。当你使用 child_process.spawn()你绕过shell,因此程序将字面引号看作参数的一部分,并且不准备处理



例如,我创建了一个小节点脚本 pargs.js ,只包含 console.log(process.argv); 使用你给予FFMPEG的相同参数运行它,我得到:

  C:\Documents and Settings\Eric Bohlman> node pargs -f dshow -i audio =Microphone(SoundMAX Integrated)testaaa.mp3 
['node',
'C:\\ Documents and Settings \\Eric Bohlman \\pargs',
'-f',
'dshow',
'-i',
'audio = Microphone(SoundMAX Integrated',
'testaaa.mp3']

C:\Documents and Settings \Eric Bohlman>

正如你所看到的,shell在使用它们之后,剥离了引号,以避免破坏 audio = ...



请注意,Windows shell(至少与XP SP3一样)不剥离单引号或使用它们用于分组,不像,像在Linux系统上常用的bash。因此,如果你正在查看某人的bash命令行示例,并且它使用单引号,则通常必须将它们替换为双引号,才能在Windows下运行。


I need to be able to execute FFMPEG from my Node.js application. I believe this problem likely has to do with properly specifying command line arguments, and not specific to FFMPEG, but as I have been unable to narrow down the issue, I present my entire problem.

I can execute the following command from the command prompt successfully:

C:\Brad\ffmpeg.exe -f dshow -i audio="Microphone (SoundMAX Integrated" testaaa.mp3

FFMPEG starts as expected, records audio from my audio device, and writes an MP3 file. Now, I try to do the same thing within my Node.js application:

childProcess = child_process.spawn('C:\\Brad\\ffmpeg.exe', ['-f', 'dshow', '-i', 'audio="Microphone (SoundMAX Integrated"', 'testaaa.mp3']);
childProcess.stderr.on('data', function (data) {
    console.log('StdioSource received data from STDERR: ' + data);
});

From within Node.js, FFMPEG fails! The error is simply:

[dshow @ 0000000001eded80] Could not find audio device.
audio="Microphone (SoundMAX Integrated": Input/output error

Thinking that maybe for some reason this was a weird permissions error, I decided to run FFMPEG with -list_devices true from within my Node application, and sure enough, the device in question is listed:

[dshow @ 000000000228ecc0] DirectShow video devices
[dshow @ 000000000228ecc0] Could not enumerate video devices.
[dshow @ 000000000228ecc0] DirectShow audio devices
[dshow @ 000000000228ecc0]  "Microphone (SoundMAX Integrated"

Any thoughts as to why I cannot properly specify the audio input device in the arguments for FFMPEG, or why FFMPEG does not recognize my audio input device when running as a child process to Node.js?

Any hints would be most appreciated.

解决方案

Brandon's on the right track. When you use double quotes around arguments on the Windows command line, the shell strips them off and the program sees them unquoted. When you use child_process.spawn() you're bypassing the shell, and as a result the program sees literal quotes as part of the argument and isn't prepared to deal with them.

For example, I created a tiny node script, pargs.js, consisting only of console.log(process.argv); Running it with the same arguments you gave to FFMPEG, I get:

C:\Documents and Settings\Eric Bohlman>node pargs -f dshow -i audio="Microphone(SoundMAX Integrated" testaaa.mp3
[ 'node',
  'C:\\Documents and Settings\\Eric Bohlman\\pargs',
  '-f',
  'dshow',
  '-i',
  'audio=Microphone (SoundMAX Integrated',
  'testaaa.mp3' ]

C:\Documents and Settings\Eric Bohlman>

As you can see, the shell stripped off the quotes after using them to avoid breaking the audio=... argument at the spaces.

Note that the Windows shell (at least as of XP SP3) doesn't strip off single quotes or use them for grouping, unlike, say, bash as commonly used on Linux systems. Thus if you're looking at someone's example bash command line and it uses single quotes, you'll generally have to replace them with double quotes for it to work under Windows.

这篇关于Node.js子进程问题与Args - Quotes问题?,FFMPEG问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆