Killing a FFmpeg process triggered by spawn in NodeJs
up vote
1
down vote
favorite
I am facing an issue wanting to kill a FFmpeg
process triggered by spawn
from the child_process
native NodeJs
package.
Here is the script i use to trigger the ffmpeg process.
Assume that the conversion takes a long time, like about 2 hours.
/**
* Execute a command line cmd
* with the arguments in options given as an array of string
* processStore is an array that will store the process during its execution
* and remove it at the end of the command or when error occurs
*/
function execCommandLine({
cmd,
options = ,
processStore = ,
}) {
return new Promise((resolve, reject) => {
const spwaned_process = childProcess.spawn(cmd, options);
// Append the process to a buffer to keep track on it
processStore.push(spwaned_process);
// Do nothing about stdout
spwaned_process.stdout.on('data', () => true);
// Do nothing about stderr
spwaned_process.stderr.on('data', () => true);
spwaned_process.on('close', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
resolve();
});
spwaned_process.on('error', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
reject();
});
});
}
const processStore = ;
await execCommandLine({
cmd: 'ffmpeg',
options: [
'-i',
'/path/to/input',
'-c:v',
'libvpx-vp9',
'-strict',
'-2',
'-crf',
'30',
'-b:v',
'0',
'-vf',
'scale=1920:1080',
'/path/to/output',
],
processStore,
});
During the conversion, the following code is called to kill all process into the processStore
, including the FFmpeg
process that is triggered.
// getProcessStore() returns the const processStore array of the above script
getProcessStore().forEach(x => x.kill());
process.exit();
After the program exit, when i run ps -ef | grep ffmpeg
, there is still some FFmpeg
process running.
root 198 1 0 09:26 ? 00:00:00 ffmpeg -i /path/to/input -ss 00:01:47 -vframes 1 /path/to/output
root 217 1 0 09:26 ? 00:00:00 ps -ef
Do you have an idea about the way to kill a ffmpeg process properly ?
node.js ffmpeg spawn kill-process
add a comment |
up vote
1
down vote
favorite
I am facing an issue wanting to kill a FFmpeg
process triggered by spawn
from the child_process
native NodeJs
package.
Here is the script i use to trigger the ffmpeg process.
Assume that the conversion takes a long time, like about 2 hours.
/**
* Execute a command line cmd
* with the arguments in options given as an array of string
* processStore is an array that will store the process during its execution
* and remove it at the end of the command or when error occurs
*/
function execCommandLine({
cmd,
options = ,
processStore = ,
}) {
return new Promise((resolve, reject) => {
const spwaned_process = childProcess.spawn(cmd, options);
// Append the process to a buffer to keep track on it
processStore.push(spwaned_process);
// Do nothing about stdout
spwaned_process.stdout.on('data', () => true);
// Do nothing about stderr
spwaned_process.stderr.on('data', () => true);
spwaned_process.on('close', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
resolve();
});
spwaned_process.on('error', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
reject();
});
});
}
const processStore = ;
await execCommandLine({
cmd: 'ffmpeg',
options: [
'-i',
'/path/to/input',
'-c:v',
'libvpx-vp9',
'-strict',
'-2',
'-crf',
'30',
'-b:v',
'0',
'-vf',
'scale=1920:1080',
'/path/to/output',
],
processStore,
});
During the conversion, the following code is called to kill all process into the processStore
, including the FFmpeg
process that is triggered.
// getProcessStore() returns the const processStore array of the above script
getProcessStore().forEach(x => x.kill());
process.exit();
After the program exit, when i run ps -ef | grep ffmpeg
, there is still some FFmpeg
process running.
root 198 1 0 09:26 ? 00:00:00 ffmpeg -i /path/to/input -ss 00:01:47 -vframes 1 /path/to/output
root 217 1 0 09:26 ? 00:00:00 ps -ef
Do you have an idea about the way to kill a ffmpeg process properly ?
node.js ffmpeg spawn kill-process
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am facing an issue wanting to kill a FFmpeg
process triggered by spawn
from the child_process
native NodeJs
package.
Here is the script i use to trigger the ffmpeg process.
Assume that the conversion takes a long time, like about 2 hours.
/**
* Execute a command line cmd
* with the arguments in options given as an array of string
* processStore is an array that will store the process during its execution
* and remove it at the end of the command or when error occurs
*/
function execCommandLine({
cmd,
options = ,
processStore = ,
}) {
return new Promise((resolve, reject) => {
const spwaned_process = childProcess.spawn(cmd, options);
// Append the process to a buffer to keep track on it
processStore.push(spwaned_process);
// Do nothing about stdout
spwaned_process.stdout.on('data', () => true);
// Do nothing about stderr
spwaned_process.stderr.on('data', () => true);
spwaned_process.on('close', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
resolve();
});
spwaned_process.on('error', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
reject();
});
});
}
const processStore = ;
await execCommandLine({
cmd: 'ffmpeg',
options: [
'-i',
'/path/to/input',
'-c:v',
'libvpx-vp9',
'-strict',
'-2',
'-crf',
'30',
'-b:v',
'0',
'-vf',
'scale=1920:1080',
'/path/to/output',
],
processStore,
});
During the conversion, the following code is called to kill all process into the processStore
, including the FFmpeg
process that is triggered.
// getProcessStore() returns the const processStore array of the above script
getProcessStore().forEach(x => x.kill());
process.exit();
After the program exit, when i run ps -ef | grep ffmpeg
, there is still some FFmpeg
process running.
root 198 1 0 09:26 ? 00:00:00 ffmpeg -i /path/to/input -ss 00:01:47 -vframes 1 /path/to/output
root 217 1 0 09:26 ? 00:00:00 ps -ef
Do you have an idea about the way to kill a ffmpeg process properly ?
node.js ffmpeg spawn kill-process
I am facing an issue wanting to kill a FFmpeg
process triggered by spawn
from the child_process
native NodeJs
package.
Here is the script i use to trigger the ffmpeg process.
Assume that the conversion takes a long time, like about 2 hours.
/**
* Execute a command line cmd
* with the arguments in options given as an array of string
* processStore is an array that will store the process during its execution
* and remove it at the end of the command or when error occurs
*/
function execCommandLine({
cmd,
options = ,
processStore = ,
}) {
return new Promise((resolve, reject) => {
const spwaned_process = childProcess.spawn(cmd, options);
// Append the process to a buffer to keep track on it
processStore.push(spwaned_process);
// Do nothing about stdout
spwaned_process.stdout.on('data', () => true);
// Do nothing about stderr
spwaned_process.stderr.on('data', () => true);
spwaned_process.on('close', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
resolve();
});
spwaned_process.on('error', () => {
const index = processStore.indexOf(spwaned_process);
if (index !== -1) {
processStore.splice(index, 1);
}
reject();
});
});
}
const processStore = ;
await execCommandLine({
cmd: 'ffmpeg',
options: [
'-i',
'/path/to/input',
'-c:v',
'libvpx-vp9',
'-strict',
'-2',
'-crf',
'30',
'-b:v',
'0',
'-vf',
'scale=1920:1080',
'/path/to/output',
],
processStore,
});
During the conversion, the following code is called to kill all process into the processStore
, including the FFmpeg
process that is triggered.
// getProcessStore() returns the const processStore array of the above script
getProcessStore().forEach(x => x.kill());
process.exit();
After the program exit, when i run ps -ef | grep ffmpeg
, there is still some FFmpeg
process running.
root 198 1 0 09:26 ? 00:00:00 ffmpeg -i /path/to/input -ss 00:01:47 -vframes 1 /path/to/output
root 217 1 0 09:26 ? 00:00:00 ps -ef
Do you have an idea about the way to kill a ffmpeg process properly ?
node.js ffmpeg spawn kill-process
node.js ffmpeg spawn kill-process
asked Nov 22 at 9:56
Alrick
1057
1057
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
As stated in the node.js documentation of subprocess.kill([signal])
, the default sent signal is SIGTERM
.
Ffmpeg do not terminature receiving SIGTERM
as explained by @sashoalm in here.
Newer versions of ffmpeg don't use 'q' anymore, at least on Ubuntu
Oneiric, instead they say to press Ctrl+C to stop them. So with a
newer version you can simply use 'killall -INT' to send them SIGINT
instead of SIGTERM, and they should exit cleanly.
So call x.kill('SIGINT');
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
As stated in the node.js documentation of subprocess.kill([signal])
, the default sent signal is SIGTERM
.
Ffmpeg do not terminature receiving SIGTERM
as explained by @sashoalm in here.
Newer versions of ffmpeg don't use 'q' anymore, at least on Ubuntu
Oneiric, instead they say to press Ctrl+C to stop them. So with a
newer version you can simply use 'killall -INT' to send them SIGINT
instead of SIGTERM, and they should exit cleanly.
So call x.kill('SIGINT');
add a comment |
up vote
1
down vote
As stated in the node.js documentation of subprocess.kill([signal])
, the default sent signal is SIGTERM
.
Ffmpeg do not terminature receiving SIGTERM
as explained by @sashoalm in here.
Newer versions of ffmpeg don't use 'q' anymore, at least on Ubuntu
Oneiric, instead they say to press Ctrl+C to stop them. So with a
newer version you can simply use 'killall -INT' to send them SIGINT
instead of SIGTERM, and they should exit cleanly.
So call x.kill('SIGINT');
add a comment |
up vote
1
down vote
up vote
1
down vote
As stated in the node.js documentation of subprocess.kill([signal])
, the default sent signal is SIGTERM
.
Ffmpeg do not terminature receiving SIGTERM
as explained by @sashoalm in here.
Newer versions of ffmpeg don't use 'q' anymore, at least on Ubuntu
Oneiric, instead they say to press Ctrl+C to stop them. So with a
newer version you can simply use 'killall -INT' to send them SIGINT
instead of SIGTERM, and they should exit cleanly.
So call x.kill('SIGINT');
As stated in the node.js documentation of subprocess.kill([signal])
, the default sent signal is SIGTERM
.
Ffmpeg do not terminature receiving SIGTERM
as explained by @sashoalm in here.
Newer versions of ffmpeg don't use 'q' anymore, at least on Ubuntu
Oneiric, instead they say to press Ctrl+C to stop them. So with a
newer version you can simply use 'killall -INT' to send them SIGINT
instead of SIGTERM, and they should exit cleanly.
So call x.kill('SIGINT');
answered Nov 22 at 10:05
Grégory NEUT
8,17621437
8,17621437
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428263%2fkilling-a-ffmpeg-process-triggered-by-spawn-in-nodejs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown