Jira Courses, Training and Consulting: Sparxsys Trainings
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. At Sparxsys we provide Atlassian consultancy services, reach out to me at ravi at sparxsys dot com

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

Subscribe

* indicates required

Please confirm that you would like to from Sparxsys:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices.

Want to contact me?