Skip to content

Instantly share code, notes, and snippets.

@ritiek
Forked from kefir-/capture.sh
Last active April 25, 2021 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritiek/a73a1a6f551c75495578bd769e5e65e3 to your computer and use it in GitHub Desktop.
Save ritiek/a73a1a6f551c75495578bd769e5e65e3 to your computer and use it in GitHub Desktop.
Screen capture with audio and webcam overlay with microphone using ffmpeg
# $ pacmd list-sources|awk '/index:/ {print $0}; /name:/ {print $0}; /device\.description/ {print $0}'
# index: 0
# name: <alsa_output.pci-0000_00_02.0-platform-hdmi-lpe-audio.stereo-fallback.monitor>
# device.description = "Monitor of Atom Processor Z36xxx/Z37xxx Series Graphics & Display Stereo"
# index: 1
# name: <alsa_output.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__sink.monitor>
# device.description = "Monitor of Built-in Audio MonoSpeaker playback + Speaker playback + Headphones playback"
# * index: 2
# name: <alsa_input.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__source>
# device.description = "Built-in Audio Internal IN3 analog Mic capture + Internal IN1 analog Mic capture + Headset Mic capture + DigitalMics capture"
# Single merged output stream for both Pulseaudio and Mic.
ffmpeg -f x11grab -thread_queue_size 64 -video_size 1366x768 -framerate 30 -i :0 \
-f v4l2 -thread_queue_size 64 -video_size 320x180 -framerate 30 -i /dev/video0 \
-f pulse -i alsa_output.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__sink.monitor \
-f pulse -i alsa_input.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__source \
-acodec aac -strict experimental \
-filter_complex 'overlay=main_w-overlay_w:main_h-overlay_h:format=yuv444' \
-filter_complex amerge \
-vcodec libx265 -preset ultrafast -qp 0 -pix_fmt yuv444p \
video.mkv
# Two audio streams - one for Pulseaudio and one for Mic.
ffmpeg -f x11grab -thread_queue_size 64 -video_size 1366x768 -framerate 30 -i :0 \
-f v4l2 -thread_queue_size 64 -video_size 320x180 -framerate 30 -i /dev/video0 \
-f pulse -i alsa_output.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__sink.monitor \
-f pulse -i alsa_input.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__source \
-map 2:0 -map 3:0 -acodec aac -strict experimental \
-metadata:s:a:0 title="Pulseaudio" \
-metadata:s:a:1 title="Mic" \
-filter_complex 'overlay=main_w-overlay_w:main_h-overlay_h:format=yuv444' \
-vcodec libx265 -preset ultrafast -qp 0 -pix_fmt yuv444p \
video.mkv
# Three audio streams - one for Pulseaudio and one for Mic, and third with previous two merged.
ffmpeg -f x11grab -thread_queue_size 64 -video_size 1366x768 -framerate 30 -i :0 \
-f v4l2 -thread_queue_size 64 -video_size 320x180 -framerate 30 -i /dev/video0 \
-f pulse -i alsa_output.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__sink.monitor \
-f pulse -i alsa_input.platform-bytcr_rt5640.HiFi__hw_bytcrrt5640__source \
-acodec aac -strict experimental \
-map 2:0 -map 3:0 -map '[a]' \
-filter_complex 'overlay=main_w-overlay_w:main_h-overlay_h:format=yuv444' \
-filter_complex 'amerge=inputs=2[a]' \
-metadata:s:a:0 title="Pulseaudio" \
-metadata:s:a:1 title="Mic" \
-metadata:s:a:2 title="Pulseaudio & Mic" \
-vcodec libx265 -preset ultrafast -qp 0 -pix_fmt yuv444p \
video.mkv
############################################
# Personally for my 1920x1080 lappy:
ffmpeg -f x11grab -thread_queue_size 256 -probesize 42M -video_size 1920x1080 -framerate 30 -i :0 \
-f v4l2 -thread_queue_size 128 -video_size 320x240 -framerate 30 -i /dev/video0 \
-f pulse -thread_queue_size 3072 -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor \
-f pulse -thread_queue_size 512 -i alsa_input.pci-0000_00_1f.3.analog-stereo \
-acodec aac -strict experimental \
-filter_complex 'overlay=main_w-overlay_w:main_h-overlay_h:format=yuv444' \
-filter_complex amerge \
-vcodec libx265 -preset superfast -qp 0 -pix_fmt yuv444p \
video.mkv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment