1
1

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 1 year has passed since last update.

ffmpegによる動画からの音声抽出

Last updated at Posted at 2022-01-21

メモ集です。

ffmpegのダウンロードと解凍(windows PC)

https://ffmpeg.org/download.html#build-windows 公式のダウンロードページ
https://www.gyan.dev/ffmpeg/builds/ 公式からのリンクのwindows用ビルド済み

ビルド済みの中から、ffmpeg-git-full.7zをダウンロードする。
image.png

windowsでは、標準で7zに対応していない。今回は、wsl2上で解凍ツールを使った。
wsl2のコマンドラインで 7z と打ち込むと、
Command '7z' not found, but can be installed with:
sudo apt install p7zip-full
と丁寧に、教えてくれるので、sudo apt install p7zip-fullを実行。
もう一度 7z と打ち込むと、使い方を教えてくれる。xはフォルダを作って解凍。
7z x ffmpeg-2023-02-04-git-bdc76f467f-full_build.7z で解凍した。
 

ffmpegによる抽出

フォルダ中の動画から一括で音声抽出

ffmpegはWindowsのGUIツールだと思っていたが、マルチプラットフォームのコマンドラインツールだった。

検索したところ、

https://sutasutashiki.blogspot.com/2021/03/Windows10-FFmpeg-Convert-mp4-to-mp3.html
https://qiita.com/cha84rakanal/items/e84fe4eb6fbe2ae13fd8

を参考に簡単なバッチファイルを書けばいいことがわかった。
以下のバッチファイルを動画フォルダに作成し、直下にoutputフォルダを作成して実行。

mp4_to_mp3.bat
for %%f in (*.mp4) do (
c:\ffmpeg\bin\ffmpeg -i "%%~nf".mp4 -ar 22050 -b:a 64k -f mp3 "output\%%~nf".mp3
)

REM このバッチファイルがあるフォルダのmp4ファイルをすべて検索し、直下のoutputフォルダにmp3で出力する
REM arビットレート44100の半分 音声のみなので。64k レート i入力 f出力

選んだファイルだけを処理するバッチ

フォルダ名は適当に変更。
ダブルクォーテーションで囲っているので日本語ファイル名もOK
%1はバッチファイルにドラッグして放り込む動画ファイル。%~n1は拡張子除いたファイル名。

"D:\オンライン講演会の映像と音声\ffmpeg-2023-02-04-git-bdc76f467f-full_build\bin\ffmpeg.exe" -i %1 -ar 22050 -b:a 64k -f mp3 "D:\オンライン講演会の映像と音声\mp3_output\%~n1.mp3"

同じ行を追加して、%2,3..9まで書けば、一度に9個までのファイルを放り込める。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?