保有しているIntensity Proをffmpegで入力したり、出力したりする。ずいぶん昔のハードウェアなのでキャプチャー解像度は1080p30まで。音声は6チャンネルのサラウンドも読み込める(実際に音が含まれているかは未確認)。接続方法にHDMIとコンポーネント端子、RCA端子(黄白赤)がある。解像度やフレームレート、インターレースなど対応内容に一致しないと扱えない。HDMI以外のアナログ入力はffmpegで扱う方法がよくわからなかった。OBSではアナログでも出力を480iに入力解像度を合わせれば表示できた。RCA端子(黄白赤)入力には8(緑)、14(白)、 15(赤)に接続。

現在のffmpegでは出力に使う–enable-decklinkをつけるには–enable-nonfreeも必要なので配布バイナリには含まれていない。用意するだけならmedia-autobuild_suiteを使うのが手軽。SDKの利用にm-ab-s / decklink-headers · GitLabを使っている。

扱う方法は映像と音声を合わせた–enable-decklink-f decklinkと、-f dshowの映像2種類Decklink Video Captureと、Blackmagic WDM Capture。音声2種類ライン入力 (Blackmagic Audio)Decklink Audio Captureがある。

まずはドライバを現在の最新版である、Desktop Video 11.6をインストールする。古いバージョンをインストールしていれば先にアンインストールする。

サポートセンター | Blackmagic Design

Nintendo SwitchをHDMIに入力し、HDMIの出力からPCモニターに接続したところ、入力映像をアクティブ、例えばffplayやffmpeg、OBSでデバイスを読み込むと入力と同時に出力も行う。

decklinkデバイスで使う

接続しているデバイス名を表示する。
ffmpeg -sinks decklink

Auto-detected sinks for decklink:
  30:00000000:001e0300 [Intensity Pro]

映像と音声が同時に入力できる。対応した映像のフォーマット一覧。-sinks decklinkで表示した内容を入力デバイスに指定する。これらに揃えた映像を入出力できる。
ffmpeg -f decklink -list_formats 1 -i "Intensity Pro"

Supported formats for 'Intensity Pro':
        format_code     description
        ntsc            720x486 at 30000/1001 fps (interlaced, lower field first)
        nt23            720x486 at 24000/1001 fps
        pal             720x576 at 25000/1000 fps (interlaced, upper field first)
        ntsp            720x486 at 60000/1001 fps
        palp            720x576 at 50000/1000 fps
        23ps            1920x1080 at 24000/1001 fps
        24ps            1920x1080 at 24000/1000 fps
        Hp25            1920x1080 at 25000/1000 fps
        Hp29            1920x1080 at 30000/1001 fps
        Hp30            1920x1080 at 30000/1000 fps
        Hi50            1920x1080 at 25000/1000 fps (interlaced, upper field first)
        Hi59            1920x1080 at 30000/1001 fps (interlaced, upper field first)
        Hi60            1920x1080 at 30000/1000 fps (interlaced, upper field first)
        hp50            1280x720 at 50000/1000 fps
        hp59            1280x720 at 60000/1001 fps
        hp60            1280x720 at 60000/1000 fps

接続した映像と-format_codeが一致しないとエラーになる。
ffmpeg -f decklink -format_code hp60 -i "Intensity Pro" output

出力ならピクセルフォーマットと解像度、フレームレートを揃える。以下テストソースを出力する例。
ffmpeg -re -f lavfi -i testsrc2=s=1280x720:r=60 -pix_fmt uyvy422 -format_code hp60 -f decklink "Intensity Pro"

それぞれ無圧縮データになり、音声のサンプリング周波数は48KHz。

Found Decklink mode 1280 x 720 with rate 60.00
Output #0, decklink, to 'Intensity Pro':
  Metadata:
    encoder         : Lavf58.62.100
    Stream #0:0: Video: wrapped_avframe, uyvy422(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 60 fps, 60
 tbn, 60 tbc
    Metadata:
      encoder         : Lavc58.111.101 wrapped_avframe
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc58.111.101 pcm_s16le

入力オプション

ffmpeg -h demuxer=decklink

公式ドキュメント:FFmpeg Filters Documentation : Input Device decklink

  • -list_devices[boolean]
    decklinkデバイスで扱えるデバイス名の表示
    例:ffmpeg -list_devices 1 -f decklink -i “Intensity Pro”
  • -list_formats[int]
    decklinkデバイスで扱えるフォーマットの表示
    例:ffmpeg -f decklink -list_formats 1 -i “Intensity Pro”
  • -format_code[string]
    扱うフォーマットの指定。-list_formatsの一覧から選ぶ
  • -raw_format[int]
    扱うピクセルフォーマットの指定。ハードウェアが対応してないとエラーになる
    • 0、 auto:既定値
    • 1, uyvy422
    • 2, yuv422p10
    • 3, argb
    • 4, bgra
    • 5, rgb10
  • -enable_klv[boolean]
  • -teletext_lines[int64]
  • -channels[int]
    音声チャンネルの指定。2、8、16しか選べない
    既定値:2
  • -duplex_mode[int]
  • -timecode_format[int]
  • -video_input[int]
    映像入力のデバイス指定。通常は無指定でよい
    • 0, unset:既定値。複数接続しているときに指定する
    • 1, sdi
    • 2, hdmi
    • 3, optical_sdi
    • 4, component
    • 5, composite
    • 6, s_video
  • -audio_input[int]
    音声入力のデバイス指定。通常は無指定でよい
    • 0, unset:既定値。複数接続しているときに指定する
    • 1, embedded
    • 2, aes_ebu
    • 3, analog
    • 4, analog_xlr
    • 5, analog_rca
    • 6, microphone
  • -audio_pts[int]
  • -video_pts[int]
  • -draw_bars[boolean]
    入力信号を失ったらカラーバーを表示する
    既定値:1(表示する)
  • -queue_size[int64]
  • -audio_depth[int]
    音声のビット深度の指定
    既定値:16
    範囲:16と32
  • -decklink_copyts[boolean]
  • -timestamp_align[duration]
  • -wait_for_tc[boolean]

出力オプション

ffmpeg -h muxer=decklink

公式ドキュメント:FFmpeg Filters Documentation : Output Device decklink

  • -list_devices[int]
    decklinkデバイスで扱えるデバイス名の表示
    例:ffmpeg -list_devices 1 -f decklink -i “Intensity Pro”
  • -list_formats[int]
    decklinkデバイスで扱えるフォーマットの表示
    例:ffmpeg -f decklink -list_formats 1 -i “Intensity Pro”
  • -preroll[double]
    映像が表示するまでの遅延
    既定値:0.5
    範囲:0から5まで
  • -duplex_mode[int]
  • -timing_offset[int]

dshowデバイスで使う

映像と音声は別入力になる。こちらも対応フォーマットに揃えないと入出力できない。

扱えるデバイス名の取得。映像と音声ともに2種類あり扱える内容が少し異なる。
ffmpeg -f dshow -list_devices 1 -i dummy

DirectShow video devices (some may be both video and audio devices)
 "Blackmagic WDM Capture"
    Alternative name "@device_pnp_\\?\decklink#avstream#5&347363ba&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\decklinkcapture1"
 "Decklink Video Capture"
    Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{44A8B5C7-13B6-4211-BD40-35B629D9E6DF}"
DirectShow audio devices
 "ライン入力 (Blackmagic Audio)"
    Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\ライン入力 (Blackmagic Audio)"
 "Decklink Audio Capture"
    Alternative name "@device_sw_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\{AAA22F7E-5AA0-49D9-8C8D-B52B1AA92EB7}"

コマンド例。
ffmpeg rtbufsize 10MB -f dshow -video_size 1280x720 -pixel_format uyvy422 -framerate 60 -channels 2 -i video="Decklink Video Capture":audio="Decklink Audio Capture" -pix_fmt yuv420p output

-channels 6で5.1チャンネルサラウンドも入力できるが、3チャンネル以降の音がのってない。abitscopeフィルタで映像化している。
ffmpeg rtbufsize 10MB -f dshow -video_size 1280x720 -pixel_format uyvy422 -framerate 60 -channels 6 -i video="Decklink Video Capture":audio="Decklink Audio Capture" -pix_fmt yuv420p -t 10 output.mp4
ffmpeg -i output.mp4 -filter_complex abitscope,realtime -f sdl -

各チャンネルの音声のビットスコープを映像化する abitscope

デバイス毎の扱えるフォーマットの表示。
ffmpeg -list_options true -f dshow -i video="Blackmagic WDM Capture"

DirectShow video device options (from video devices)
 Pin "Video Capture" (alternative pin name "0")
  pixel_format=uyvy422  min s=720x480 fps=23.976 max s=720x486 fps=23.976
  vcodec=v210  min s=720x480 fps=23.976 max s=720x486 fps=23.976
  pixel_format=uyvy422  min s=720x480 fps=29.97 max s=720x486 fps=29.9701
  vcodec=v210  min s=720x480 fps=29.97 max s=720x486 fps=29.9701
  pixel_format=uyvy422  min s=720x480 fps=59.9402 max s=720x486 fps=59.9402
  vcodec=v210  min s=720x480 fps=59.9402 max s=720x486 fps=59.9402
  pixel_format=uyvy422  min s=720x576 fps=25 max s=720x576 fps=25
  vcodec=v210  min s=720x576 fps=25 max s=720x576 fps=25
  pixel_format=uyvy422  min s=720x576 fps=50 max s=720x576 fps=50
  vcodec=v210  min s=720x576 fps=50 max s=720x576 fps=50
  pixel_format=uyvy422  min s=1280x720 fps=50 max s=1280x720 fps=50
  pixel_format=uyvy422  min s=1280x720 fps=59.9402 max s=1280x720 fps=59.9402
  pixel_format=uyvy422  min s=1280x720 fps=59.9999 max s=1280x720 fps=60.0002
  pixel_format=uyvy422  min s=1920x1080 fps=25 max s=1920x1080 fps=25
  pixel_format=uyvy422  min s=1920x1080 fps=29.97 max s=1920x1080 fps=29.9701
  pixel_format=uyvy422  min s=1920x1080 fps=30 max s=1920x1080 fps=30
  pixel_format=uyvy422  min s=1920x1080 fps=23.976 max s=1920x1080 fps=23.976
  pixel_format=uyvy422  min s=1920x1080 fps=24 max s=1920x1080 fps=24
 Pin "Audio Capture" (alternative pin name "1")

Technical Note TN2162: Uncompressed Y´CbCr Video in QuickTime Files
How can I set a Clean Aperture on a QuickTime file in ffmpeg? – Stack Overflowより。

  • rawvideo pix_fmt uyvy422
  • rawvideo pix_fmt yuyv422
  • v308 (uncompressed packed 8-bit YUV 444)
  • v408 (uncompressed packed 8-bit YUV 4444)
  • v410 (uncompressed packed 10-bit YUV 444)
  • v210 (uncompressed packed 8 or 10-bit YUV 422)

ffmpeg -list_options true -f dshow -i video="Decklink Video Capture"

DirectShow video device options (from video devices)
 Pin "Capture" (alternative pin name "1")
  pixel_format=uyvy422  min s=720x486 fps=29.97 max s=720x486 fps=29.97
  pixel_format=uyvy422  min s=720x486 fps=23.976 max s=720x486 fps=23.976
  pixel_format=uyvy422  min s=720x576 fps=25 max s=720x576 fps=25
  pixel_format=uyvy422  min s=720x486 fps=59.9402 max s=720x486 fps=59.9402
  pixel_format=uyvy422  min s=720x576 fps=50 max s=720x576 fps=50
  pixel_format=uyvy422  min s=1920x1080 fps=23.976 max s=1920x1080 fps=23.976
  pixel_format=uyvy422  min s=1920x1080 fps=24 max s=1920x1080 fps=24
  pixel_format=uyvy422  min s=1920x1080 fps=25 max s=1920x1080 fps=25
  pixel_format=uyvy422  min s=1920x1080 fps=29.97 max s=1920x1080 fps=29.97
  pixel_format=uyvy422  min s=1920x1080 fps=30 max s=1920x1080 fps=30
  pixel_format=uyvy422  min s=1280x720 fps=50 max s=1280x720 fps=50
  pixel_format=uyvy422  min s=1280x720 fps=59.9402 max s=1280x720 fps=59.9402
  pixel_format=uyvy422  min s=1280x720 fps=60.0002 max s=1280x720 fps=60.0002
video=Decklink Video Capture: Immediate exit requested

44.1KHzまでステレオだけの制限がある。
ffmpeg -list_options true -f dshow -i audio="ライン入力 (Blackmagic Audio)"

min ch=1 bits=8 rate= 11025 max ch=2 bits=16 rate= 44100

モノラルやサラウンドを入力するならこちら。48KHzしか選べない。
ffmpeg -list_options true -f dshow -i audio="Decklink Audio Capture"

DirectShow audio only device options (from audio devices)
 Pin "Capture" (alternative pin name "1")
  min ch=1 bits=16 rate= 48000 max ch=1 bits=16 rate= 48000
  min ch=2 bits=16 rate= 48000 max ch=2 bits=16 rate= 48000
  min ch=4 bits=16 rate= 48000 max ch=4 bits=16 rate= 48000
  min ch=6 bits=16 rate= 48000 max ch=6 bits=16 rate= 48000
  min ch=8 bits=16 rate= 48000 max ch=8 bits=16 rate= 48000
  min ch=10 bits=16 rate= 48000 max ch=10 bits=16 rate= 48000
  min ch=12 bits=16 rate= 48000 max ch=12 bits=16 rate= 48000
  min ch=16 bits=16 rate= 48000 max ch=16 bits=16 rate= 48000

オプション

dshowでよく使うオプション。

公式ドキュメント:FFmpeg Filters Documentation : dshow

ffmpeg -h demuxer=dshow

すべて-list_optionsの一覧から選ぶ。

  • -video_size[image_size]
    解像度の指定
  • -pixel_format[pix_fmt]
    ピクセルフォーマットの指定
  • -framerate[string]
    フレームレートの指定
  • -sample_rate[int]
    サンプリング周波数の指定
  • -channels[int]
    音声チャンネル数の指定

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)