Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg screen recording with camera overlay on OSX

I would like to use ffmpeg to record my desktop as well as my camera as an overlay on top of the desktop.

So basically I will have two input sources that need to be recorded

$ ffmpeg -f avfoundation -list_devices true -i ''
[AVFoundation input device @ 0x7fded1c223e0] AVFoundation video devices:
[AVFoundation input device @ 0x7fded1c223e0] [0] FaceTime HD Camera
[AVFoundation input device @ 0x7fded1c223e0] [1] Capture screen 0
[AVFoundation input device @ 0x7fded1c223e0] AVFoundation audio devices:
[AVFoundation input device @ 0x7fded1c223e0] [0] Built-in Microphone

From the above, I need [0] FaceTime HD Camera as an overlay and [1] Capture screen 0 as the main video.

Is this even possible?

UPDATE (2015-10-06):

I found the following command from ffscreencast:

ffmpeg \
-f avfoundation -i "1" \
-f avfoundation -r 30 -video_size 640x480 -i "0" \
-c:v libx264 -crf 0 -preset ultrafast \
-filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' "out.mkv"

Unfortunately the output has a pretty slow framerate (i7 Macbook Pro 2014)

Output #0, matroska, to 'out.mkv':
  Metadata:
encoder         : Lavf56.40.101
Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 3840x2400, q=-1--1, 1000k fps, 1k tbn, 1000k tbc (default)
Metadata:
  encoder         : Lavc56.60.100 libx264
Stream mapping:
  Stream #0:0 (rawvideo) -> overlay:main
  Stream #1:0 (rawvideo) -> overlay:overlay
  overlay -> Stream #0:0 (libx264)

frame=  756 fps=9.1 q=-1.0 Lsize=  193660kB time=00:01:21.86 bitrate=19378.5kbits/s
Press [q] to stop, [?] for help

Anyone an idea of how to get a higher framerate? My camera is only able to record at 30 frames per second, but the output seems to only have around 9 frames. Why the difference?

like image 681
lockdoc Avatar asked Sep 30 '15 09:09

lockdoc


Video Answer


1 Answers

For me this works, ffmpeg version 2.8:

ffmpeg -thread_queue_size 50 \
-f avfoundation -framerate 30 -i "1" \
-thread_queue_size 50 -f avfoundation -framerate 30 -video_size 640x480 -i "0" \
-c:v libx264 -crf 18 -preset ultrafast \
-filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' -r 30 ~/Desktop/out.mkv

NOTE: i read in the documentation that the '-r' option is for the output so you have it on the wrong place in your command. The '-crf' value you give seems exaggerated, if the documentation says that a value of 18 is visually lossless video. You will also probably need to play with the '-thread_queue_size' value for your specific system.

like image 197
Felipe Ignacio Noriega Alcaraz Avatar answered Sep 27 '22 18:09

Felipe Ignacio Noriega Alcaraz