4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ffmpegとSoXを使って、音声を比較する動画をちゃちゃっと作る

Last updated at Posted at 2019-09-10

目的とゴール

 音声合成などで生成した音声を比較して、SNSでちゃちゃっと共有したい。でも大体のSNSは音声のみの共有ができない。soundcloudに投稿するのもめんどくさい。ということで、ffmpegとSoXを使ってちゃちゃっと動画にするコマンドをメモがてら書き記します。

↓こういうのが作れます

コマンド(シェルスクリプト)

ffmpegSoXが必要です。

function make_audio_comparison {
  first_file="$1"
  first_label="$2"
  first_label_color="$3"
  second_file="$4"
  second_label="$5"
  second_label_color="$6"
  output_file="$7"
  normalize="${8:-}"

  if [ -z "$normalize"]; then
    cp "$first_file" /tmp/first.wav
    cp "$second_file" /tmp/second.wav
  else
    sox "$first_file" -r 48000 -b 32 /tmp/first.wav norm
    sox "$second_file" -r 48000 -b 32 /tmp/first.wav norm
  fi
  sox -M /tmp/input.wav /tmp/result.wav /tmp/merged.wav

  ffmpeg -y \
    -i /tmp/input.wav \
    -i /tmp/result.wav \
    -i /tmp/merged.wav \
    -filter_complex "
    [0:0][1:0][2:0]concat=n=3:v=0:a=1[a_all];
    [0:0]showwaves=s=640x480:mode=p2p:colors=$first_label_color,drawtext=text=$first_label:x=10:y=10:fontcolor=$first_label_color:fontsize=48,format=yuv420p[v0];
    [1:0]showwaves=s=640x480:mode=p2p:colors=$second_label_color,drawtext=text=$second_label:x=10:y=10:fontcolor=$second_label_color:fontsize=48,format=yuv420p[v1];
    [0:0]showwaves=s=640x240:mode=p2p:colors=$first_label_color,drawtext=text=$first_label:x=10:y=10:fontcolor=$first_label_color:fontsize=48,format=yuv420p[vt];
    [1:0]showwaves=s=640x240:mode=p2p:colors=$second_label_color,drawtext=text=$second_label:x=10:y=10:fontcolor=$second_label_color:fontsize=48,format=yuv420p[vb];
    [vt][vb]vstack[v2];
    [v0][v1][v2]concat=n=3:v=1:a=0[v_all]
    "\
    -map "[a_all]" \
    -map "[v_all]" \
    "$output_file"
}

使い方

make_audio_comparison \
  "1つ目に提示する音声ファイル" \
  "1つ目に提示する音声のラベル" \
  "1つ目に提示する音声のラベルの色" \
  "2つ目に提示する音声ファイル" \
  "2つ目に提示する音声のラベル" \
  "2つ目に提示する音声のラベルの色" \
  "出力ファイルのパス(mp4)" \
  "音声を正規化するかどうか(Trueもしくは無指定)" \

その他

 ffmpegのfilter_complexの扱い方が難しい。。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?