ffmpeg screen recording with camera overlay on OSX
Asked Answered
T

1

9

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?

Tl answered 30/9, 2015 at 9:42 Comment(5)
ffmpeg does have an overlay filter, so I'd guess it is.Interlocutory
Yes I just found it, but seems still slow.Tl
Hi lockdoc, which OS X version u are using. I am using 10.10.5 and the command "ffmpeg -f avfoundation -list_devices true -i ''" only show 1 input devices (Camera).Tsarism
Hi i am using command : 'ffmpeg -f avfoundation -framerate 30 -i "1" -f avfoundation -framerate 30 -video_size 640x480 -i "0" -r 30 /Users/admin/Documents/Swati/test/test.flv': Error >>>Output file #0 does not contain any stream from my mac APPIndecision
ffmpeg version : 3.2.1Indecision
D
11

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.

Drunk answered 8/11, 2015 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.