cauchi
cauchi

Reputation: 1543

after 10M ffmpeg stops saving video on nodejs

I have a nodejs server running using express (express 4). I want to save the video from a few IP cameras on a lab on request. Everything works, but if the video is too long it doesn't get saved (the limit seems to be 11M).

I tried using only the command line:

ffmpeg -i rtsp://192.168.1.189:554/ch01_sub.264 -strict -2 -vcodec
copy -vcodec copy test.mp4

and this works. But I get into trouble as soon as I use node (note that this is in the node parser, no code in express. I get the same error when running the server) :

var child_process = require('child_process');
tmpProcess = child_process.spawn('ffmpeg',['-i','rtsp://192.168.1.189:554/ch01_sub.264','-strict','-2','-vcodec','copy','-vcodec','copy',"test.mp4"],{maxBuffer: 10000});

this runs until test.mp4 is around 11M. tmpProcess is not killed, it keeps running. But after test.mp4 is of certain size I cannot play it back. I get an error saying that "This file contains no playable streams." (this is from Totem, but VLC doesn't work either).

Changing maxBuffer doesn't help. I'm trying to understand what buffer am I overflooding but I cannot get much info from the manual on the api of node.

Upvotes: 0

Views: 581

Answers (1)

robertklep
robertklep

Reputation: 203304

If ffmpeg produces a lot of (debugging) output on stdout/stderr, you need to make sure that it gets read, or that you call child_process.spawn() with the option { stdio : 'ignore' }.

Otherwise, Node will keep collecting the data and at some point will block (at least, I think it will) the spawned process until all data has been read.

To read the data, attach data event listeners to both tmpProcess.stdout and tmpProcess.stderr. Or use the aforementioned ignore to have Node ignore all the output (which in your case is probably the best solution as you're not interested in the console output).

Upvotes: 1

Related Questions