Skip to content

Instantly share code, notes, and snippets.

@matiaspl
Last active November 5, 2023 21:04
Show Gist options
  • Save matiaspl/4fd885bc988f5aaf11a6301c55aa0adb to your computer and use it in GitHub Desktop.
Save matiaspl/4fd885bc988f5aaf11a6301c55aa0adb to your computer and use it in GitHub Desktop.
Stream RTMP with FFMPEG + BMD Ultrastudio Recorder on OSX (hardware accelerated encoding)

You might ask why would anyone do it in the first place? Well, OBS is the only reasonable free tool for OSX for streaming but it has a flaw which makes it impossible to stream 1080p50/p60 on my i5 MacBook Pro. It works if you disable preview, but then if you can't see the video there's no reason for using OBS ;)

You need ffmpeg-dl from ffmpegdecklink brew package by AMIA Open Source (brew install ffmpegdecklink). It's worth noting that unlike brew's regular ffmpeg this one allows building ffmpeg with additional libraries (e.g. brew install ffmpegdecklink -with-srt in case you need SRT).

/usr/local/opt/ffmpegdecklink/bin/ffmpeg-dl -f decklink -i 'UltraStudio Mini Recorder' -video_input hdmi -format_code Hi50 -audio_input embedded -channels 2 -vf yadif=1 -c:v h264_videotoolbox -profile:v main -b:v 6M -pix_fmt yuv420p -color_range 1 -coder cabac -c:a aac_at -b:a 192k -f flv rtmp://your_server/app/key

What this does is capture 1080i50 signal from HDMI input (use -video_input sdi for SDI) deinterlaced with Yadif x2 algo (1080p50 output), convert colorspace to YUV 4:2:0 (the default is mobile-unfriendly 4:2:2) and encode the video stream to H.264 using Apple's wrapper for Intel CPU QSV hardware encoding engine. CABAC enabled for better quality. All this with broadcast luma levels in mind - no luma range scaling, just setting proper metadata. As far as audio goes AAC 2-channel audio (using Apple's AudioToolbox AAC codec) with a slightly higher than default bitrate (192k vs 128k). All this wrapped into FLV and sent to external server.

For the complete set of options of decklink input module head to https://www.ffmpeg.org/ffmpeg-devices.html#decklink, and for videotoolbox options

In case anyone's interested the default ffmpegdecklink build parameters are:

--prefix=/usr/local/Cellar/ffmpegdecklink/4.1.3 --disable-shared --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.3.1/include/openjpeg-2.3 --enable-nonfree --enable-decklink --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/include

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment