简体   繁体   English

使用ffmpeg录制带有isight的视频

[英]record a video with isight using ffmpeg

So to record webcam video with ffmpeg on linux you may use something like... 因此,要在Linux上使用ffmpeg录制网络摄像头视频,您可以使用类似...

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? 但是在Mac上这不起作用,所以我想知道你如何用mac上的ffmpeg与isight进行记录?

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. 我已经研究了很多人说它无法完成,但大多数这些帖子都很老了所以我想知道从那以后它是否有所改变。

Updated: current (Aug 2014) version of ffmpeg supports QTKit and AVKit frameworks: 更新:当前(2014年8月)ffmpeg版本支持QTKit和AVKit框架:

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. 我用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. 它是一个小实用程序,它捕获视频和音频,压缩它,打包rtp数据包中的压缩流并将它们传输到网络。

So the workaround is pretty cumbersome, and requires double encoding but it works: 所以解决方法非常麻烦,需要双重编码,但它的工作原理如下:

  1. Setup streams in QuickTime Broadcaster's Audio and Video tabs 在QuickTime Broadcaster的AudioVideo选项卡中设置流

  2. Go to Network tab, set Transmission to "Manual Unicast", Address to "127.0.0.1", Ports to something like "6000, 6002" 转到Network选项卡,将Transmission设置为“手动单播”,将Address为“127.0.0.1”,将Ports为“6000,6002”

  3. File -> Save Broadcast Settings As... to some file (eg Untitled.qtbr) File -> Save Broadcast Settings As...到某个文件(例如Untitled.qtbr)

  4. Export SDP file: File -> Export -> SDP . 导出SDP文件: File -> Export -> SDP SDP stands for "Session Description Protocol", that contains information about where to find stream, its parameters and codec options, etc. SDP代表“会话描述协议”,其中包含有关在何处查找流,其参数和编解码器选项等的信息。

  5. Now you can start/stop QTB from command line: 现在您可以从命令行启动/停止QTB:

     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 ). 启动QTB后,ffmpeg将能够使用您在步骤4中导出的sdp文件读取压缩流(实际上,您可以在VLC或QuickTime播放器中打开它: open -a vlc stream.sdp )。

So QTB works as "capturing agent" which makes conversion "iSight-to-UDP socket". 因此QTB作为“捕获代理”工作,使转换成“iSight-to-UDP socket”。

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

or transmit it to ffserver: 或者将其传送给ffserver:

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

(imho) It's pretty hard to add iSight support to ffmpeg/libavdevice. (imho)将iSight支持添加到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. iSight有基于ObjC的API(QTKit),它必须包装在C静态库中,ffmpeg也必须与所有OS X特定的框架链接 - 这是可行的,但需要相当多的工作。

Using the latest ffmpeg, you can record iSight video with microphone audio to a file: 使用最新的ffmpeg,您可以将带麦克风音频的iSight视频录制到文件中:

# 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 . 写作时,在录制带有音频的视频时,您仍然可能遇到AVFoundation同步问题

On Linux 'ffmpeg' uses the ' video4linux2 ' capture API, and on Windows there is a version called 'video4windows.' 在Linux上'ffmpeg'使用' video4linux2 '捕获API,在Windows上有一个名为'video4windows'的版本。 Unforunately nobody has made a version for the Mac. 不幸的是,没有人为Mac制作过版本。


Fortunately, you can still record video from your iSight camera from the commandline using this free software: 幸运的是,您仍然可以使用此免费软件从命令行录制iSight摄像头的视频:

Wacaw - Webcam Tools for Mac OS X Wacaw - 适用于Mac OS X的网络摄像头工具


Here is an example of its usage. 以下是其用法示例。

  • Step 1) See what video hardware is present : 步骤1) 查看存在的视频硬件

wacaw -L wacaw -L

  • Step 2) Capture your video to file. 步骤2)将您的视频捕获到文件。 On my MacBook, it reports my internal iSight camera as a USB device of ID '2' with an input of ID '0'. 在我的MacBook上,它将我的内部iSight摄像头报告为ID为'2'的USB设备,输入ID为'0'。 Here's how it looks for my MacBook. 以下是它对我的MacBook的看法。 The 'video-device' may differ for your computer, and you might also be able to omit the '--video-input 0' section: 您的计算机的“视频设备”可能有所不同,您也可以省略“--video-input 0”部分:

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


Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM