13

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.

alex
  • 545
  • 2
  • 6
  • 18

3 Answers3

20

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.

Vadim Kalinsky
  • 928
  • 8
  • 18
  • The quality of the stream is very very poor, and low fps. I tested stream.sdp on vlc: 'open -a vlc stream.sdp' and on ffserver: 'ffmpeg -i stream.sdp http://localhost:8090/feed1.ffm', and both had terrible quality. So it must be something wrong with QTB. I set the settings in QTB to be 30 fps, and 1000 kbps, and it isn't making any difference. – alex Oct 22 '13 at 19:04
  • What the frame size do you use? – Vadim Kalinsky Oct 22 '13 at 19:31
  • Im currently using 600x480 – alex Oct 22 '13 at 20:16
  • most of the screen is gray and there might be a pixel here and there that isn't. Im certain my isight is working also, because it works fine on photobooth, and such. – alex Oct 22 '13 at 20:21
  • Hm I used 1024x768@15 2000 mbps, it worked just fine (as fine as it can be with iSight). There's issue with frame rate in QTB: seems like it just do 15 fps regardless of users's settings. – Vadim Kalinsky Oct 22 '13 at 20:45
  • BTW the sdp file should be saved (exported) after every change of QTB settings. – Vadim Kalinsky Oct 22 '13 at 20:46
  • Thanks alot it seems to be working now! Just curious is the low fps due to the iSight, or is it QTB making the fps slow? – alex Oct 22 '13 at 21:58
  • BTW it was not so hard to add iSight support into ffmpeg. It looks scary because of the mixture objC and plain C, but it works. Checkout iSight_support branch from github repository https://github.com/vkalinsky/FFmpeg and use "-f isight -i qq" as ffmpeg source. Have no idea whether ffmpeg team will accept this pull request or not, but it works at least in this branch. – Vadim Kalinsky Oct 28 '13 at 01:21
  • I tried ffmpeg-2.4.7z from http://www.evermeet.cx/ffmpeg/ but that didn't work ("Unknown input format: 'qtkit'"). Is there a special version somewhere? – Michael Böckling Sep 22 '14 at 22:17
  • Ok, turns out you need a HEAD version. For Homebrew, just type: brew upgrade --HEAD ffmpeg – Michael Böckling Sep 23 '14 at 14:16
12

Using the latest ffmpeg, you can record iSight video with microphone audio to a file:

# List available AVFoundation input devices:
ffmpeg -f avfoundation -list_devices true -i ""

# Record video at 30 fps from device 0:
ffmpeg -r 30 -f avfoundation -i 0 out.mp4

# Record from video device 0 and audio device 0:
ffmpeg -r 30 -f avfoundation -i 0:0 out.mp4

As of writing, when recording video with audio, you could still encounter AVFoundation sync problems.

Duvrai
  • 3,398
  • 3
  • 20
  • 21
4

On Linux 'ffmpeg' uses the 'video4linux2' capture API, and on Windows there is a version called 'video4windows.' Unforunately nobody has made a version for the Mac.


Fortunately, you can still record video from your iSight camera from the commandline using this free software:

Wacaw - Webcam Tools for Mac OS X


Here is an example of its usage.

  • Step 1) See what video hardware is present:

wacaw -L

  • Step 2) Capture your video to file. On my MacBook, it reports my internal iSight camera as a USB device of ID '2' with an input of ID '0'. Here's how it looks for my MacBook. The 'video-device' may differ for your computer, and you might also be able to omit the '--video-input 0' section:

wacaw --video --video-device 2 --video-input 0 --duration 3 --VGA ~/MyMovie


Hope this helps!

original_username
  • 2,398
  • 20
  • 24
  • Can I use wacaw to live stream my isight to ffserver like video4linux2? – alex Oct 21 '13 at 19:27
  • or just live streaming in general – alex Oct 21 '13 at 23:22
  • If you need to livestream, you will need to use something else. I have not used chazlever's 'creepycam', but it might work depending on your needs. It's located over here: http://github.com/chazlever/creepycam It requires 'imagesnap' to be installed (and therefore also 'HomeBrew'). I don't think 'creepycam' will get anywhere near 24fps though, because it works by repeatedly making calls to 'imagesnap' for single images. – original_username Oct 22 '13 at 02:36
  • There's also Apple's own QTSS, though I believe that's a paid offering. VLC app has GUI based streaming ( see: http://autonome.wordpress.com/2009/05/31/streaming-your-isight-camera-to-the-web-with-the-video-tag/ ), but if you're going that route, you could probably hack something together with web technologies since Flash also provides video capture. – original_username Oct 22 '13 at 02:40
  • 1
    As an example for how live-streaming with ffmpeg works: ffmpeg -f avfoundation -i "0" -s 320x240 -f flv -r 30.0 "" – Christof Nov 15 '14 at 11:41