Thanks for coming here, I hope you are enjoying learning here, I have also written some books in case you want to learn a bit more :)
If you need my help with Drupal, Linux, Jira, Scripting, Automation or want to contact me then raise a ticket for me please :) and I will get back to you, promise

Completely replaced OBS with ffmpeg

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.

  1. #! /bin/bash
  2.  
  3. #Configurations
  4. VBR="1500k"
  5. FPS="24"
  6. BUFSIZE="3000k" #twice of bitrate
  7. QUAL="ultrafast"
  8. SIZE=1366x768
  9. WEBCAMSIZE=320x240
  10. AUDIO_ENCODER="aac"
  11. CURRENT_DIRECTORY=${PWD}
  12. OUTPUT_EXTENSION=$1
  13. echo "Recording to path: $1 "
  14. TIMESTAMP=$(date "+%Y-%m-%d-%H-%M-%S")
  15. YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"
  16. KEY="111-111-222"
  17. AUDIO_FILE="/home/ravisagar/projects/ffmpeg-livestreamer/songs/allsongs.mp3"
  18. # Use - pactl list sources, to check desktop audio source
  19. DESKTOP_AUDIO="alsa_output.pci-0000_00_1b.0.analog-stereo.monitor"
  20. MIC=$(arecord -l | grep "Samson" | cut -d ':' -f 1 | cut -d ' ' -f 2)
  21. #command starts here
  22. ffmpeg \
  23.     -video_size $SIZE -framerate $FPS -f x11grab -probesize 10M -thread_queue_size 8192 -i :0.0+1920,0 \
  24.     -f alsa -ac 2 -thread_queue_size 8192 -i hw:$MIC \
  25.     -f pulse -ac 2 -thread_queue_size 8192 -i $DESKTOP_AUDIO \
  26.     -filter_complex \
  27.     "[1:a]channelsplit=channel_layout=stereo:channels=FR, \
  28.    showfreqs=s=240x200:ascale=sqrt:cmode=combined:colors=#330000@0.5[right]; \
  29.    [1:a]channelsplit=channel_layout=stereo:channels=FL, \
  30.    showfreqs=s=240x200:ascale=sqrt:cmode=combined:colors=#330000@0.5,vflip[left]; \
  31.    [right][left]vstack[w]; \
  32.    [0:v][w]overlay=x=W-w-30-10:y=H-h-30+200-10[bg2]; \
  33.    [bg2]drawtext=text='<a href="https://www.ravisagar.in/%3Cspan%20style%3D"color: #000000; font-weight: bold;">//www.ravisagar.in':">www.ravisagar.in':</a> \
  34.     fontcolor=white:fontsize=18:box=1: \
  35.     boxcolor=#330000@0.5:boxborderw=10: \
  36.     x=30:y=(h-text_h-30),format=yuv420p[v]; \
  37.     [1:a]adelay=500|500,volume=2[a1]; \
  38.     [2:a]adelay=750|750[delayed]; \
  39.     [delayed][a1]amix=inputs=2[a]" \
  40.    -map "[v]" -map "[a]" \
  41.    -c:v libx264 -preset $QUAL -r $FPS -g $(($FPS *2)) -b:v $VBR -bufsize 3000k -maxrate $VBR \
  42.    -c:a $AUDIO_ENCODER -ar 44100 -b:a 128k -pix_fmt yuv420p \
  43.    ~/$TIMESTAMP.$OUTPUT_EXTENSION
  44.  
  45.    #     -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.

Syndications

Ravi Sagar Newsletter

Honestly I hardly send out mails but I guess there is no harm in at least having a newsletter. I will only send newsletter when I have something important to share or an update. People are busy and no one has time to read emails these days. If you really like my content then I guess you will remember my site and come back for more.

Want to contact me?