record a video with isight using ffmpeg
Asked Answered
M

3

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.

Marshy answered 23/9, 2013 at 19:13 Comment(0)
P
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.

Persse answered 22/10, 2013 at 16:59 Comment(10)
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 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.Marshy
What the frame size do you use?Persse
Im currently using 600x480Marshy
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.Marshy
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.Persse
BTW the sdp file should be saved (exported) after every change of QTB settings.Persse
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?Marshy
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 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.Persse
I tried ffmpeg-2.4.7z from evermeet.cx/ffmpeg but that didn't work ("Unknown input format: 'qtkit'"). Is there a special version somewhere?Ape
Ok, turns out you need a HEAD version. For Homebrew, just type: brew upgrade --HEAD ffmpegApe
C
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.

Checkerboard answered 21/7, 2014 at 17:27 Comment(0)
C
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!

Cymograph answered 20/10, 2013 at 23:18 Comment(5)
Can I use wacaw to live stream my isight to ffserver like video4linux2?Marshy
or just live streaming in generalMarshy
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: 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.Cymograph
There's also Apple's own QTSS, though I believe that's a paid offering. VLC app has GUI based streaming ( see: autonome.wordpress.com/2009/05/31/… ), but if you're going that route, you could probably hack something together with web technologies since Flash also provides video capture.Cymograph
As an example for how live-streaming with ffmpeg works: ffmpeg -f avfoundation -i "0" -s 320x240 -f flv -r 30.0 "<rtmp-url>"Brimful

© 2022 - 2024 — McMap. All rights reserved.