fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.96k stars 881 forks source link

Camera Recording #351

Open timkendall opened 9 years ago

timkendall commented 9 years ago

Has anybody used this library with recording a live video stream from a connected camera? Ideally it would be as easy as -

ffmpeg('/dev/video0', { timeout: 40000 })
  .format('mov')
  .save('camera-recording.mov');

I've used ffmpeg -f avfoundation -i "0" ffmpeg-facetime.mpg to record from the built in Facetime HD camera on my mac but I can't get this to work with the library.

Is this even close?

var command = ffmpeg({ timeout: 432000 })
  .addOption('-f', 'avfoundation')
  .addOption('-i', '"0"')
  .output('ffmpeg-factime.mpg')
  .run();
njoyard commented 9 years ago

Maybe the issue is that -i "0" maps to something other than /dev/video0.

Could you please try the following :

timkendall commented 9 years ago

Alright so it turns out that my issue was me being ignorant of how the library works. Got live recording from both Facetime Camera and a connected USB camera with the following -

It came down to just following the instructions here for each OS.

On OSX:

var capture = ffmpeg('default') // See above article
    // Set input format (depends on OS, will not work if this isn't correct!)
    .inputFormat('avfoundation')
    // Set output format
    .format('mp4')
    // Set size
    .size(SIZE)
    // Set FPS
    .fps(FPS)
    // Set video codec
    .videoCodec('libx264')
    // Record stream for 15sec
    .duration('0:15')
    .save('camera-recording.mp4');

On Ubuntu (14.04.1):

var capture = ffmpeg('/dev/video0') 
    // Set input format (depends on OS, will not work if this isn't correct!)
    .inputFormat('v4l2')
    // Set output format
    .format('mp4')
    // Set size
    .size(SIZE)
    // Set FPS
    .fps(FPS)
    // Set video codec
    .videoCodec('libx264')
    // Record stream for 15sec
    .duration('0:15')
    .save('camera-recording.mp4');
njoyard commented 9 years ago

Nice to see you solved your problem, and thanks for the hints on how to get it to work. You shouldn't need to set the format explicitly, though, as ffmpeg is able to determine it automatically based on the output file extension.

njoyard commented 9 years ago

Oh, and I'm keeping this one open as I would like to be able to pass capture device indices as inputs.

crosofg commented 8 years ago

How to end a stream recording, If I dont want to set a timeout? Is there any api call to be made?

njoyard commented 8 years ago

Yes @crosofg, you can call command.kill().

crosofg commented 8 years ago

@njoyard But that does not get into the callback on"end" .

njoyard commented 8 years ago

Nope, that calls 'error' instead (which is the right thing to do, as ffmpeg did not terminate normally).

crosofg commented 8 years ago

@njoyard Can you tell me the clean to terminate the process?

njoyard commented 8 years ago

Yes @crosofg, you can call command.kill().

This is the only way to terminate the process when the source does not end and no video duration was set on the command.

Csushma08 commented 7 years ago

can any one tell me how to capture the video for the webcam through fluent ffmpeg in windows?

LeandroLoiacono commented 2 years ago

Hi everybody, is there a way to capture having a realtime preview in a video tag?

thanx to anybody who will answer