Skip to content

Recording Live Camera and Desktop on Linux using Blackmagic Decklink

Charles Forman edited this page Dec 21, 2020 · 2 revisions

Recording Live Camera and Desktop on Linux using Blackmagic Decklink

When I record videos, I wanted a way to record the video from the camera, the computer, and vr at the same time so I don't have to go back and try to sync them. I also don't want to have to transfer the videos from each device.

Needs:

  • Sync videos
  • Don't have to transfer them off the device
  • All the videos in the right format

So instead of recording in camera, I decided to buy a capture card so I can record everything on the computer.

I use Linux, an Ubuntu based distro called: PopOS.

So I bought: Blackmagic Design DeckLink Quad HDMI Recorder 4K PCIe Capture Card. It works with Linux and and DaVinci Resolve, which I also use. It has 4 HDMI inputs, so I could use multiple cameras in the future.

I thought it might be as simple as just installing the card and it working as a video input device. With Linux, this is almost never the case, and this is no exception.

Installation

Put in computer

Download Linux apps and drivers

https://www.blackmagicdesign.com/support/family/capture-and-playback

Download Blackmagic Desktop Video 11.7

Install the 3 .debs in there

Check:

lspci | grep Blackmagic   
01:00.0 Multimedia video controller: Blackmagic Design DeckLink Mini Recorder 4K   

lsmod | grep blackmagic   
blackmagic_io 1843200 1   

Build custom FFMPEG with Decklink Enabled

Download FFMPEG Source

mkdir -p ~/ffmpeg_sources ~/bin

Download source snapshot: https://ffmpeg.org/download.html Copy it to: ~/ffmpeg_sources

cd ~/ffmpeg_sources
tar -xvf ffmpeg-*.tar.bz2

Download Desktop Video 11.7 SDK

https://www.blackmagicdesign.com/support/family/capture-and-playback

Download Desktop Video 11.7 SDK

sudo apt install unzip
unzip Blackmagic_DeckLink_SDK_*.zip
cp -r Blackmagic\ DeckLink\ SDK\ */Linux/ ~/ffmpeg_sources/BMD_SDK

Install Dependencies

sudo apt-get update -qq && sudo apt-get -y install \
  autoconf \
  automake \
  build-essential \
  cmake \
  git-core \
  libass-dev \
  libfreetype6-dev \
  libtool \
  libvorbis-dev \
  pkg-config \
  texinfo \
  wget \
  zlib1g-dev \
  libpulse-dev
sudo apt-get -y install \
  nasm yasm libx264-dev libx265-dev libnuma-dev libvpx-dev \
  libfdk-aac-dev libmp3lame-dev libopus-dev

sudo apt-get install libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev libxcb-xfixes0-dev

Install nvidia support

sudo apt install system76-cuda-latest

https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/

git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git

Configure

cd ffmpeg-*/

PATH="$HOME/bin:$PATH:/usr/lib/cuda/bin" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include -I$HOME/ffmpeg_sources/BMD_SDK/include -I/usr/lib/cuda/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib -L/usr/lib/cuda/lib64" \
  --extra-libs="-lpthread -lm" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree \
  --enable-decklink \
  --enable-libpulse \
  --enable-libxcb \
  --enable-libxcb-shm \
  --enable-libxcb-xfixes \
  --enable-nvenc \
  --enable-libnpp

Compile it

PATH="$HOME/bin:$PATH" make -j8
sudo cp ffmpeg ffprobe /usr/local/bin/

Testing

Camera recording

List devices:

ffmpeg -f decklink -list_devices 1 -i dummy

List supported formats:

ffmpeg -f decklink -list_formats 1 -i 'DeckLink Quad HDMI Recorder (1)'

Capture Camera at 23.976fps to h264:

ffmpeg -y -thread_queue_size 90 -hwaccel cuda \
-channels 2 -raw_format yuv422p10 -format_code 23ps -f decklink -i 'DeckLink Quad HDMI Recorder (1)' \
-c:a pcm_s16le -c:v libx264 -preset ultrafast -crf 10  ~/camera264.mov

Desktop Recording

List the pulse sound devices to see which one to use. One my computer they change everytime I restart, because Linux.

pacmd list-sources

Record a 4k screen with default pulse audio input:

ffmpeg -thread_queue_size 90 -hwaccel cuda -y \
-f x11grab -framerate 23.976 -video_size 3840x2160 -i :1+1440,194 -f pulse -ac 2 -i default \
-vcodec libx264 -crf 0 -preset ultrafast -acodec copy ~/4kscreen.mov

Record a smaller second screen with default pulse audio input:

ffmpeg -thread_queue_size 90 -hwaccel cuda -y \
-f x11grab -framerate 23.976 -video_size 2560x1440 -i :1+5280,493 -f pulse -ac 2 -i default \
-vcodec libx264 -crf 10 -preset ultrafast -acodec copy ~/output.mov

Recording everything at the same time

Record camera, 4k desktop, and secondary monitor for the VR stream:

ffmpeg -y -thread_queue_size 90 -hwaccel cuda \
-channels 2 -raw_format yuv422p10 -format_code 23ps -f decklink -i 'DeckLink Quad HDMI Recorder (1)' \
-f x11grab -framerate 23.976 -video_size 3840x2160 -i :1+1440,194 -f pulse -ac 2 -i default \
-f x11grab -framerate 23.976 -video_size 2560x1440 -i :1+5280,493 -f pulse -ac 2 -i default \
-f pulse -ac 2 -i default \
-map 0 -c:a pcm_s16le -c:v libx264 -preset ultrafast -crf 10  ~/camera.mov \
-map 1 -vcodec libx264 -crf 0 -preset ultrafast ~/screen.mov \
-map 2 -map 3 -vcodec libx264 -crf 0 -preset ultrafast -acodec copy ~/vr.mov

BUT! Performance is not so good. I think it's better to use smaller screens. Also it's better to record video at 29.976 and screen capture at closer to 60fps so it will look better on Youtube.

So:

  1. Run: pacmd list-sources to make sure you have the right audio from the computer
  2. Change the resolution for the displays to: 2560x1440, 1920x1080 and make sure the refresh rate is 60hz.
ffmpeg -y -hwaccel cuda \
-channels 2 -raw_format yuv422p10 -format_code Hp29 -f decklink -i 'DeckLink Quad HDMI Recorder (1)' -thread_queue_size 90 \
-f x11grab -framerate 60 -video_size 2560x1440 -i :1+1440,0 -thread_queue_size 90 \
-f x11grab -framerate 60 -video_size 1920x1080 -i :1+4000,0 -thread_queue_size 90 \
-f pulse -ac 2 -i 1 \
-map 0 -c:a pcm_s16le -c:v libx264 -preset ultrafast -crf 10  ~/camera.mov \
-map 1 -vcodec libx264 -crf 0 -preset ultrafast ~/screen.mov \
-map 2 -map 3 -vcodec libx264 -crf 0 -preset ultrafast -acodec copy ~/vr.mov
Clone this wiki locally