Skip to content

Instantly share code, notes, and snippets.

@MichaelKreil
Last active April 7, 2024 23:22
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save MichaelKreil/0dffd8e5062e2dcfb7ea to your computer and use it in GitHub Desktop.
Save MichaelKreil/0dffd8e5062e2dcfb7ea to your computer and use it in GitHub Desktop.
using ffmpeg to stream videos, gifs, the webcam or the screen to matelight
# Stream a video
ffmpeg -re -i video.avi -vf "scale=40:ih*40/iw, crop=40:16" -f rawvideo -vcodec rawvideo -sws_flags bilinear -pix_fmt rgb24 - > /dev/udp/matelight.cbrp3.c-base.org/1337
# Loop a gif
ffmpeg -re -ignore_loop 0 -i image.gif -vf "scale=40:ih*40/iw, crop=40:16" -f rawvideo -vcodec rawvideo -sws_flags bilinear -pix_fmt rgb24 - > /dev/udp/matelight.cbrp3.c-base.org/1337
# Stream webcam
# Mac
ffmpeg -re -f avfoundation -r 30 -s 1280x720 -i "0" -vf "scale=40:ih*40/iw, crop=40:16, pp=autolevels:f, eq=1.5" -f rawvideo -vcodec rawvideo -sws_flags bilinear -pix_fmt rgb24 - > /dev/udp/matelight.cbrp3.c-base.org/1337
# Stream screen center (for e.g. YouTube videos)
# Mac retina
ffmpeg -re -f avfoundation -r 25 -i "1" -vf "crop=1200:480, scale=40:16, eq=1.5" -f rawvideo -vcodec rawvideo -sws_flags bilinear -pix_fmt rgb24 - > /dev/udp/matelight.cbrp3.c-base.org/1337
# Mac normal
ffmpeg -re -f avfoundation -r 25 -i "1" -vf "crop=600:240, scale=40:16, eq=1.5" -f rawvideo -vcodec rawvideo -sws_flags bilinear -pix_fmt rgb24 - > /dev/udp/matelight.cbrp3.c-base.org/1337
# Linux
ffmpeg -re -video_size 600x240 -f x11grab -r 25 -i :0.0+100,200 -vf "scale=40:16, eq=1.5" -f rawvideo -vcodec rawvideo -sws_flags bilinear -pix_fmt rgb24 - > /dev/udp/matelight.cbrp3.c-base.org/1337;
# prepare video for matelight ...
ffmpeg -r 25 -i video.mp4 -sws_flags bilinear -pix_fmt rgb24 -vf "scale=40:ih*40/iw, crop=40:16" -an -vcodec libx264 -crf 6 -preset veryslow video.mov
# ... and play it
ffmpeg -re -i video.mov -f rawvideo -vcodec rawvideo -pix_fmt rgb24 - > /dev/udp/matelight.cbrp3.c-base.org/1337
# Code is used in e.g. https://github.com/MichaelKreil/mateplay
# convert video to gif by first generate a palette and then use it to generate gif:
ffmpeg -i video.mov -vf "scale=40:ih*40/iw, crop=40:16,palettegen" -y palette.png
ffmpeg -i video.mov -i palette.png -lavfi "scale=40:ih*40/iw, crop=40:16,fps=25[x]; [x][1:v] paletteuse" -y sequence2.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment