labunix's blog

labunixのラボUnix

ffmpegでsrt字幕の位置を上部中央に変更する。

■ffmpegでsrt字幕の位置を上部中央に変更する。
 「subtitles」をダブルクォーテーションで囲む必要があるのと、
 「Alignment」は番号で指定する。

$ ffmpeg -i target.mp4 -vf "subtitles=target.srt:force_style='FontSize=20,Alignment=6'" output3.mp4

■環境と上記コマンドの前提は以下と同じ。

 ffmpegで無音、静止画からsrtを埋め込んだ動画を生成する。
 http://labunix.hateblo.jp/entry/20170821/1503254189

 debian stretch+ffmpegで字幕ファイルsrt/assをなるべく簡単に作成してみる。
 labunix.hateblo.jp/entry/20170821/1503254189

■「Alignment」で指定するべき番号の説明は以下にあった。

$ w3m -dump http://docs.aegisub.org/3.2/ASS_Tags/ | \
    grep -A 23 "Line alignment (legacy)"
Line alignment (legacy)

\a<pos>

Specify the alignment of the line using legacy alignment codes from SubStation
Alpha. This tag is supported but considered deprecated; you should usually use
\an in new scripts instead, as it is more intuitive.

The exception is that \a6 should be used for lazy sign translating, because if
you're going to be lazy you should do it right and save the extra character.

Calculate pos as follows: Use 1 for left-alignment, 2 for center alignment and
3 for right-alignment. If you want sub-titles you're done. To get top-titles,
add 4 to the number, to get mid-titles add 8 to the number:

  • 1: Bottom left
  • 2: Bottom center
  • 3: Bottom right
  • 5: Top left
  • 6: Top center
  • 7: Top right
  • 9: Middle left
  • 10: Middle center
  • 11: Middle right