record a video with isight using ffmpeg

纵饮孤独 提交于 2019-11-29 22:39:02

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.

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.

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!