record a video with isight using ffmpeg

alex picture alex · Sep 23, 2013 · Viewed 10.5k times · Source

So to record webcam video with ffmpeg on linux you may use something like...

ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 out.avi

But on a mac this doesn't work, so i was wondering how do you record with the isight with ffmpeg on a mac?

I've researched and a lot of people said it can't be done, but most of these posts are really old so i'm wondering if it's changed since then.

Answer

Vadim Kalinsky picture Vadim Kalinsky · Oct 22, 2013

Updated: current (Aug 2014) version of ffmpeg supports QTKit and AVKit frameworks:

ffmpeg -f qtkit -video_device_index 0 -i "" out.mpg

or

ffmpeg -f qtkit -i "default" out.mpg

also you can obtain list of available devices:

ffmpeg -f qtkit -list_devices true -i ""

Old answer:

I solved this problem with QuickTime Broadcaster. It is small utility which captures video and audio, compress it, packetizes compressed stream in rtp packets and transmits them to the network.

So the workaround is pretty cumbersome, and requires double encoding but it works:

  1. Setup streams in QuickTime Broadcaster's Audio and Video tabs

  2. Go to Network tab, set Transmission to "Manual Unicast", Address to "127.0.0.1", Ports to something like "6000, 6002"

  3. File -> Save Broadcast Settings As... to some file (e.g. Untitled.qtbr)

  4. Export SDP file: File -> Export -> SDP. SDP stands for "Session Description Protocol", that contains information about where to find stream, its parameters and codec options, etc.

  5. Now you can start/stop QTB from command line:

    osascript -e 'tell application "QuickTime Broadcaster" to start document "Untitled.qtbr"'
    
    osascript -e 'tell application "QuickTime Broadcaster" to stop document "Untitled.qtbr"'
    

After you start QTB, ffmpeg will able to read compressed stream using that sdp file you exported on step 4 (actually, you can open it in VLC or QuickTime player: open -a vlc stream.sdp).

So QTB works as "capturing agent" which makes conversion "iSight-to-UDP socket".

ffmpeg -i stream.sdp -vcodec mjpeg -an -vf vflip -y /tmp/q.avi

or transmit it to ffserver:

ffmpeg -i stream.sdp http://localhost:1881/feed1.ffm

(imho) It's pretty hard to add iSight support to ffmpeg/libavdevice. iSight has ObjC-based API (QTKit), which has to be wrapped in C static library, also ffmpeg has to be linked with all OS X specific frameworks - that's doable, but requires quite a lot of work.