0

I am using nodejs. The idea is to launch a bash script using exec. I can do it. In my bash script I am doing a video conversion using mencoder. For exemple:

mencoder Videoinput.ogv -o videouput.avi   -oac lavc -ovc lavc -lavcopts vbitrate=3000 vcodec=mpeg4

The problem I have: If I try to convert a huge video, the conversion is ok until a specific time. In my case 1minute 47 seconds..... So it seems like node has a time maximum to execute a bash script using exec and then it cuts it. Am I right? Does anyone know how to add more time to the exec command? If that is possible, I would be able to finish the video conversion ... thanks for your answer.

1
  • 2
    According to the fine manual, timeout is 0, meaning that Node will allow the process all the time it needs. But, if for example your script isn't reading the output generated by mencoder, it might fill up the output buffer and Node will kill your process once the buffer is full (see maxBuffer). Please post how you're calling your script from Node. Commented May 17, 2013 at 10:50

1 Answer 1

1

It makes sense that js does not allow subprocesses to run more than a specific time. Otherwise the browser can easily become unresponsive.

I'd propose to run a command which terminates quickly but has started the mencoder in a split-off parallel process. It could be enough to append a & to the mencode command, putting it into the background by this. Maybe you would like to send all its output in a specific file (or at least to /dev/null to suppress it completely). Use > outputfilename for this. Probably redirecting the error message also makes sense, so also use 2> errormessagesfilename or just use 2>&1 after redirecting the standard output to send both streams into the same file.

Maybe you have to create a subshell to fool js into believing the subprocess is finished early. This can eb done by putting the command into parentheses ((mencoder …)).

So you might end up with sth like this:

(mencoder Videoinput.ogv \
    -o videouput.avi \
    -oac lavc \
    -ovc lavc \
    -lavcopts vbitrate=3000 vcodec=mpeg4 \
    >/tmp/mencoder.output 2>&1 &) > /dev/null
Sign up to request clarification or add additional context in comments.

6 Comments

Node will run external programs asynchronously, so it won't become unresponsive if the program takes some time.
thanks for your answer... I have been able to run my bash script changing the max buffer to {maxBuffer: 500*1024}... Now it works. It was memory problem...
@anraT I think that will only temporarily solve your problem, once the output generated by mencoder reaches 500K one day, the problem will reappear. I think the best solution would be to just read the output generated by mencoder (and just don't do anything with it). Or use the -really-quiet command line option to limit the output that's generated.
I have tested -really-quiet converting a video of 1.2 Go mpeg to avi. I have used the default values of maxbuffer... thanks, it works...
Redirecting all output to /dev/null as described in my answer will also work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.