Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在node.js中终止ffmpeg进程_Node.js_Video_Ffmpeg - Fatal编程技术网

如何在node.js中终止ffmpeg进程

如何在node.js中终止ffmpeg进程,node.js,video,ffmpeg,Node.js,Video,Ffmpeg,我正在使用node.js代码,使用FFMPEG将Axis Ipcamera实时流转换为mp4 var childProcess=require('child_process'); var childArguments = []; var child=[]; var cmd='ffmpeg -i rtsp://172.24.22.117:554/axis-media/media.amp -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -

我正在使用node.js代码,使用FFMPEG将Axis Ipcamera实时流转换为mp4

 var childProcess=require('child_process');
 var childArguments = [];
var child=[];
var cmd='ffmpeg -i rtsp://172.24.22.117:554/axis-media/media.amp -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slower -crf 18 -vf "scale=trunc(in_w/2)*2:trunc(in_h/2)*2"'+' '+__dirname+'/uploads/ouput.mp4';

  child=childProcess.exec(       
        cmd,
        childArguments,
        {            
            env: process.env,
            silent:true
        },  function (err, stdout, stderr) {
            if (err) {
                throw err;
            }
            console.log(stdout);

        });     

        //    here generate events for listen child process (works properly)
    // Listen for incoming(stdout) data
    child.stdout.on('data', function (data) {
        console.log("Got data from child: " + data);
    });

    // Listen for any errors:
    child.stderr.on('data', function (data) {
        console.log('There was an error: ' + data);
    });

    // Listen for exit event
    child.on('exit', function(code) {
        console.log('Child process exited with exit code ' + code);
        child.stdout.pause();
        child.kill();
    });
我上面的代码工作得很好。它提供我想要的输出,但我无法终止(停止)ffmpeg命令。我正在使用下面的代码来停止进程,但在后台它仍在继续

child.kill("SIGTERM"); 
我还使用了以下命令:child.kill('SIGUSR1');杀死孩子(“叹息”);杀害儿童(“SIGINT”);child.kill('SIGUSR2');用于终止此过程,但它不起作用

目前,我强制关闭节点应用程序以停止ffmpeg命令并生成mp4文件。我不要这个。
但是我需要停止ffmpeg进程并生成mp4文件的命令,而不终止节点应用程序。

您正在从
child.on('exit')
回调调用
child.kill()
child.on('exit')
实际上是在子进程完成时调用的

此外,如果需要终止子进程,则明确表示该命令本身不会退出。如果是这种情况,您可能需要设置一个超时,以便在运行一段时间后调用
child.kill()

var cp = require('child_process');
var cmd = 'ffmpeg...'
var child = cp.exec(cmd, function(err, stdout, stderr) {})
child.stdin.write('q')