Today I mixed my desktop audio along with the mic audio in my existing #ffmpeg #shell #script Now I think I have a near perfect solution to completely replace #obs which I haven't used in a week now.
#ffmpeg #obs #audiomix
Script to record or stream
Replace "~/$TIMESTAMP.$OUTPUT_EXTENSION" in the last line with "-f flv "$YOUTUBE_URL/$KEY"" to stream instead of recording.
-
#! /bin/bash
-
-
#Configurations
-
VBR="1500k"
-
FPS="24"
-
BUFSIZE="3000k" #twice of bitrate
-
QUAL="ultrafast"
-
SIZE=1366x768
-
WEBCAMSIZE=320x240
-
AUDIO_ENCODER="aac"
-
CURRENT_DIRECTORY=${PWD}
-
OUTPUT_EXTENSION=$1
-
echo "Recording to path: $1 "
-
TIMESTAMP=$(date "+%Y-%m-%d-%H-%M-%S")
-
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"
-
KEY="111-111-222"
-
AUDIO_FILE="/home/ravisagar/projects/ffmpeg-livestreamer/songs/allsongs.mp3"
-
# Use - pactl list sources, to check desktop audio source
-
DESKTOP_AUDIO="alsa_output.pci-0000_00_1b.0.analog-stereo.monitor"
-
MIC=$(arecord -l | grep "Samson" | cut -d ':' -f 1 | cut -d ' ' -f 2)
-
#command starts here
-
ffmpeg \
-
-video_size $SIZE -framerate $FPS -f x11grab -probesize 10M -thread_queue_size 8192 -i :0.0+1920,0 \
-
-f alsa -ac 2 -thread_queue_size 8192 -i hw:$MIC \
-
-f pulse -ac 2 -thread_queue_size 8192 -i $DESKTOP_AUDIO \
-
-filter_complex \
-
"[1:a]channelsplit=channel_layout=stereo:channels=FR, \
-
showfreqs=s=240x200:ascale=sqrt:cmode=combined:colors=#330000@0.5[right]; \
-
[1:a]channelsplit=channel_layout=stereo:channels=FL, \
-
showfreqs=s=240x200:ascale=sqrt:cmode=combined:colors=#330000@0.5,vflip[left]; \
-
[right][left]vstack[w]; \
-
[0:v][w]overlay=x=W-w-30-10:y=H-h-30+200-10[bg2]; \
-
[bg2]drawtext=text='<a href="https://www.d10.ravisagar.in/%3Cspan%20style%3D"color: #000000; font-weight: bold;">//www.ravisagar.in':">www.ravisagar.in':</a> \
-
fontcolor=white:fontsize=18:box=1: \
-
boxcolor=#330000@0.5:boxborderw=10: \
-
x=30:y=(h-text_h-30),format=yuv420p[v]; \
-
[1:a]adelay=500|500,volume=2[a1]; \
-
[2:a]adelay=750|750[delayed]; \
-
[delayed][a1]amix=inputs=2[a]" \
-
-map "[v]" -map "[a]" \
-
-c:v libx264 -preset $QUAL -r $FPS -g $(($FPS *2)) -b:v $VBR -bufsize 3000k -maxrate $VBR \
-
-c:a $AUDIO_ENCODER -ar 44100 -b:a 128k -pix_fmt yuv420p \
-
~/$TIMESTAMP.$OUTPUT_EXTENSION
-
-
# -f flv "$YOUTUBE_URL/$KEY"
For showing my webcam I don't use ffmpeg, instead I used another script to display my webcam on the desktop using mpv, good thing about this script is that I can zoom in , zoom out, move the webcam window (which is mpv playing directly from my webcam) and I have a keybindings for all this. Take a look at this video for more explanation.