日本のテレビ番組で表示されるARIB(アライブ)字幕を動画のエンコードと一緒に字幕も扱うことができる。今までは映像と音声のエンコードと字幕を同時に扱うことはできなかった。

2023年3月にlibaribcaptionにも対応しよりきれいにレンダリングできるようになった。

ARIB字幕をVTTにしてHLSで視聴する

標準規格概要(STD-B24)|一般社団法人 電波産業会
ARIB外字 – Wikipedia

ffmpeg 4.2 から対応し、VLC 3.0 から動画再生に字幕を表示できるようになった。
ffmpeg 4.2 リリース
VLC 3.0 がリリースし ARIB 字幕や AV1 デコードに対応

ARIB字幕を扱うツール。

対応した ffmpeg が配布されている。

字幕ファイルから映像に焼き付けるハードサブは以下のフィルタを使う。
ass の字幕ファイルを動画に焼き付ける ass
字幕ファイルを動画に焼き付ける subtitles

インストール

git clone https://github.com/nkoriyama/aribb24
cd aribb24
autoreconf -fiv
./configure --enable-static --disable-shared
make
make install

m-ab-s/media-autobuild_suite未対応なので手動で64bit用にインストールする。msys64 フォルダにある、mingw64.exe を起動してインストールする

未対応と書いたが手動でインストールしたものは対応していたので上のように手動でインストールして、以下を ffmpeg_options.txt に追記する。

--enable-version3
--enable-gpl
--enable-libaribb24

手動で ffmpeg にリンクする。

PKG_CONFIG_PATH="/local64/lib/pkgconfig" ./configure --enable-version3 --enable-gpl --enable-libaribb24 --pkg-config-flags=--static --extra-ldflags=-static

基本コマンド

TSファイルからremuxして再びTSに字幕をコピーすることはできない。2022年時点ではできる。-fix_sub_durationをつけないと字幕の表示時間がおかしくなるので必ずつける。2022年時点では必ずつけなくてもうまくいくみたい。
ffmpeg -analyzeduration 10MB -probesize 10MB -fix_sub_duration -i input.ts -map 0:v -map 0:a -map 0:s -c:v libx264 -c:a copy -c:s mov_text output.mp4

ARIB字幕を保持して映像をエンコードする。
ffmpeg -analyzeduration 10MB -probesize 10MB -fix_sub_duration -i input.ts -map 0:v -map 0:a -map 0:s -c:v libx264 -c:a copy -c:s copy output.ts

ASS字幕に出力する。
ffmpeg -analyzeduration 10MB -probesize 10MB -fix_sub_duration -i input.ts -c:s ass output.ass

字幕の表示時間を一律にずらすなら-itsoffsetをつける。2秒遅らせる例。
ffmpeg -analyzeduration 10MB -probesize 10MB -fix_sub_duration -itsoffset 2 -i input.ts -c:s ass output.ass

字幕ファイルを1行テキストで出力する。字幕フォーマットはコーデックで指定する。
ffmpeg -analyzeduration 10MB -probesize 10MB -fix_sub_duration -i input.ts -an -vn -c:s text -f rawvideo oneline.txt

mp4の字幕に使うmov_text字幕はass字幕からのポジションを引き継げないので、Caption2Assなどで変換した同時刻に2段表示する最初の字幕を表示できない。よって先にTSからスタイルのない1行にまとめた字幕を出力してからmov_textに入れ直す。
ffmpeg.exe -analyzeduration 10MB -probesize 10MB -fix_sub_duration -i input.ts -c:s text sub.srt
ffmpeg -i video.mp4 -i sub.srt -map 0:v -map 0:a -map 1:s -c:v copy -c:a copy -c:s mov_text output.mp4

Can ffmpeg extract closed caption data – Stack Overflow

公式ドキュメント
FFmpeg Codecs Documentation : libaribb24
ffmpeg Documentation : Subtitle options

オプション

オプション指定してどのように変化があるのかよくわかっていない。
ffmpeg -h decoder=libaribb24

  • -aribb24-base-path[string]
    Sets the base path for the libaribb24 library. This is utilized for reading of configuration files (for custom unicode conversions), and for dumping of non-text symbols as images under that location.
    既定値:無指定
  • -aribb24-skip-ruby-text[boolean]
    Tells the decoder wrapper to skip text blocks that contain half-height ruby text.
    既定値:1
  • -default_profile[int]
    default profile to use if not specified in the stream parameters.
    • 0, a
    • 1, c

2 thoughts on “ARIB字幕をdemuxする libaribb24

  • 匿名

    「ARIB字幕を保持して映像をエンコードする。」
    のコードをm2tsで試したところ、以下のようなエラーが出ました。

    [mpegts @ 000002012844ec40] Cannot automatically assign PID for stream 2
    [out#0/mpegts @ 00000201a9bbd800] Could not write header (incorrect codec parameters ?): Invalid argument
    Invalid argument

    • admin

      m2tsで検証したことはないですが、
      コンソールログをすべて貼り付けていただけますか?

admin へ返信する コメントをキャンセル

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

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