ffmpeg on MacOS with Blackmagic

Things are bleak when ffmpeg might make things BETTER than what you were doing before.

Lazyweb, earn your keep:

How do I get video out of a BlackMagic SDI-to-HDMI 4K MiniConverter using ffmpeg on MacOS?

I installed it like this:

port install ffmpeg +nonfree +librtmp +libdc1394

I gather that the following incantation should list available input devices, but it freaks out halfway through:

ffmpeg -list_devices true -f avfoundation -i dummy

ffmpeg version 2.3.3 Copyright (c) 2000-2014 the FFmpeg developers
built on Aug 21 2014 20:56:05 with Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libass --enable-libbluray --enable-gnutls --enable-fontconfig --enable-libfreetype --enable-libfribidi --disable-indev=jack --disable-outdev=xv --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --enable-vda --arch=x86_64 --enable-yasm --enable-libdc1394 --enable-librtmp --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid --enable-nonfree --enable-libfdk-aac --enable-libfaac
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 48.100 / 55. 48.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.100 / 4. 11.100
libavresample 1. 3. 0 / 1. 3. 0
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
[AVFoundation input device @ 0x7f935ac2d3e0] AVFoundation video devices:
[AVFoundation input device @ 0x7f935ac2d3e0] [0] Blackmagic
dummy: Input/output error
Exit 1

My reading of various cargo-cult droppings suggested that my command might look something like:

cmd="ffmpeg -f avfoundation"
cmd="$cmd -i video=Blackmagic"          #
cmd="$cmd -video_size 1280x720"         # input video size
cmd="$cmd -framerate 60"                # input video frame rate
cmd="$cmd -r 15"                        # output video fps
cmd="$cmd -g 30"                        # output motion estimation?
cmd="$cmd -maxrate 350k"                # output video rate
cmd="$cmd -bufsize 700k"                # output video rate
#cmd="$cmd  -rtbufsize 702000k"         # output video rate?
cmd="$cmd -vf scale=640:-1,format=yuv420p"     # output video size
cmd="$cmd -threads 4"                   # tune this?
cmd="$cmd -acodec libmp3lame"           # output audio codec
cmd="$cmd -ac 2"                        # output audio channels
cmd="$cmd -b:a 96k"                     # output audio bps
cmd="$cmd -ar 44100"                    # output audio Hz
cmd="$cmd -vcodec libx264"              # output video codec
cmd="$cmd -crf 23"                      # constant rate factor. 0 = lossless, 18 good, 23 default, 51 worst
cmd="$cmd -preset ultrafast"            # little compression, high bitrate
cmd="$cmd -f mpegts"                    # MPEG-TS packets, CBR MPEG
cmd="$cmd -f flv"
cmd="$cmd rtmp://a.rtmp.youtube.com/live2/[REDACTED]"

But that fails:

[avfoundation @ 0x7f8d3b82cc00] Failed to create AV capture input device: Cannot Use Blackmagic
Blackmagic: Input/output error

Also, how do I tell it to take video from Blackmagic but encode silence as audio? Not "no audio stream", but rather, "there is an audio stream and it is silent"?

Also, how do I tell it to take video from Blackmagic but audio from the Mac's built-in analog line-in jack?

Previously, previously, previously.

Tags: , , , , , ,

12 Responses:

  1. I can change the audio routing and embed it in the SDI stream via that new Roland VC-1DL frame sync.

  2. and the input device is "UltraStudio Mini Recorder"

    • jwz says:

      Not according to ffmpeg it's not.

      • Ben says:

        Is that the name of the physical device though?
        I have one and have never gotten it to produce video (under MacOS) for anything related to streaming except FMLE and Ustream Producer.
        It doesn't even enumerate for ffmpeg with either avfoundation or qtkit.

  3. Neil says:

    Assuming you are trying to connect hdmi from a board or a camera up into the internets, Media Express does everything you are asking for, except it's not headless and probably can't be run from a shell or from cron. But you can mix different audio sources (including silent ones), and it can be used to stream to youtube etc. I think it can even do scaling and squishing and color space conversions, but I've never done that.

    I don't have your hardware, but my understanding is that it runs with all Blackmagic capture hardware, which I think is what you are describing.

    • jwz says:

      except it's not headless and probably can't be run from a shell or from cron

      ...in case you were wondering when I stopped listening, this was when.

  4. Ewen McNeill says:

    This 2012 solution to OS X livecasting (via justin.tv) with ffmpeg seems to be piping audio in via sox via a FIFO (telling ffmpeg it is a wav file), and having ffmpeg remux it with the video (because they couldn't get audio input working on OS X in ffmpeg, at least at the time). Possibly that, plus something persuading sox just to ship constant bytes (or loop a small snippet of reorded silence) in place of audio would let you have mute audio? (Not tried, but maybe even /dev/zero would be enough? It is missing the WAV header though.)


    PS: The answer for audio into ffmpeg on OS X seems to be avfoundatin/openal, but as of a few months ago, it was unclear if the support for audio on OS X had been merged into the mainline. Given you don't actually want audio, building a version with random unmerged patches is probably not a useful use of time.

  5. eSyr says:

    Regarding silenced audio: i suppose "-af 'volume=0.0'" ("volume" audio filter) should work.

    Regarding I/O error: i suppose there there is some funky stuff regarding 1394 support in MacOS X/ffmpeg (even in linux, homeland of ffmpeg, 1394 interaction is heavily broken)

    Regarding audio from line-in: "ffmpeg -i video_input -i audio_input -c copy -map 0:v:0 -map 1:a:0 output" (meaning "map first video channel from first input and first audio channel from second input"), but, again, support of actual devices may differ.

    The main problem here, as far as i can see, is that ffmpeg can't correctly initialize 1394 device. Once it is solved, other things should be easier (but, again, interaction of ffmpeg with input devices usually tangled with desyncs, segfaults, buffer under/overruns and all the things).

  6. extra88 says:

    An Mini Converter SDI to HDMI 4K provides an HDMI output but you don't say what your Mac's HDMI input is, an Intensity Extreme, UltraStudio Mini Recorder, something else? It's the HDMI in to Thunderbolt hardware that AVFoundation is going to see. I assume including libdc1394 with ffmpeg is a leftover from previously using a FireWire camera or capture device, I don't see anything that the library will do with HDMI. I'm guessing the Mac is not a pre-2013 Mac Pro and you're not using PCI cards in a Thunderbolt chassis.

    I'd remove all 3rd party hardware to see if -list_devices will stop shitting the bed and list what's built into the Mac so you can find the index number for line-in. You may want to have a line-in source connected and making noise in case OS X won't let AVFoundation "see" it with nothing connected. Or you could just start trying index numbers -i "Blackmagic:0", -i "Blackmagic:1", etc.

    Looking at FFmpeg Devices Documentation, AVFoundation doesn't use "video=" or "audio=" in its parameters, it's just "video:audio" with the name or index number of the video and audio sources on either side of the colon. What's the default device for AVFoundation audio? Would -i "Blackmagic:default" just use the Blackmagic as the audio source as the default or would it be something else, possibly something silent?

    My next thought for silence is to install Soundflower but I don't know if AVFoundation would "see" Soundflower. I also don't know if Soundflower requires code run by a logged in console user; I know your solution can't be GUI-based but I don't know if your Mac also has to be run displaying only the OS X login prompt. Soundflower includes a .kext but it may also need it's menu bar app Soundflowerbed.app running.

  7. db48x says:

    I guess you've already managed it, but with sox you can specify -n in place of an input filename to use the internal null device; ffmpeg/avcodec can then mux that with your video stream.

  8. APB says:

    You might try installing the ffmpeg-devel port instead of vanilla ffmpeg. That would put you on the version 2.4 branch, which probably won't fare any better, but at least it's not much work to try. The device listing command would then become "-devices" (because a consistent UI is for suckers).

    In re, a silent audio stream, the "-af volume=0" suggestion above should work, or you could use the "generate silence" audio evaluation input if you want to really thoroughly discard any incoming audio.

  9. lu_zero says:

    You can try to use bmdtools and report me if they are not working for you.

  • Previously