C プログラミングも *nix も、ほとんど理解していない [twitter:@riocampos] です。
Mac ユーザーで ffmpeg を使いたければ homebrew で作れば良いですし、もしくは FFmpeg Binary からダウンロードしてくればだいたい済みます。しかし、プログラムに組み込みたい& SSL が使いたい、となると、残念ながら自分で作るしか方法がありません。
ライブラリとか pkg-config とかぜーんぜん分かっていない状況から、なんとか GnuTLS 入り FFmpeg を作れましたので、記録として残しておきます。
多分、問題なくインストールできると思います(LionとMavericksで確認済み)。
もし上手くインストール出来たら、環境を含めてコメントいただければ幸いです。失敗した場合は…コメントいただいても多分返答出来ないですゴメンナサイ。
なぜGnuTLSを使うのか
SSL を使うときにはだいたい OpenSSL を使うと思います。ですが、よく分かっていませんが OpenSSL はライセンス的にややこしいようです。
オープンソースと特許が混じって、やや混乱状態になっているソフトウェアに、「openssl」がある。名前の通り、ソースコードはオープンになっていて、無償で手に入る。しかしここで使われている技術は米国ではRSA社の特許になっている。特許は基本的に属地主義をとっているので、米国を離れると特許に関する問題はこの限りではないなど、さらに混乱に輪をかける結果となっている。
ビジネスとオープンソースライセンス(後編)
なので、互換性のある GnuTLS を使います。
SSL/TLSプロトコルの実装としてはOpenSSLが有名ですが、OpenSSLのライセンスはGPLに対し非互換のため、GPLの下にあるソフトウェアはOpenSSLを使うことができませんでした。
GnuTLSは、その問題を解決しGNUプロジェクトのアプリケーションでもTLSのようなプロトコルを扱えることを目的として開発されました。
kamonama@Blogger: GnuTLSの使い方(第1回)
FFmpeg作成手順
スパースバンドル・ディスクイメージを作成
システムに組み込むものを作るわけでは無いので、作成場所を用意します。 RAM ディスクでの作成というのもありますが、 Mac だとディスクイメージを作るのが簡単なので、ディスクイメージ内で作成します。
ディスクユーティリティを起動し、「新規イメージ…」ボタンを押して、空の新規スパースバンドル・ディスクイメージ "ffmpeg_gnutls.sparsebundle" 5GBを作成します。変更点は
- ファイル名(ffmpeg_gnutls.sparsebundle)
- 名前(ffmpeg_gnutls)
- サイズ(5GB/5000MB)
- パーティション(ハードディスク)
- イメージフォーマット(スパースバンドル・ディスクイメージ)
です。ファイル名と名前はあとでも変更できますが、その他は変更が難しいので注意してください。
このディスクイメージをダブルクリックしてマウントし、直下に
- src
- sw
両フォルダを作成します。
このあとは Finder とターミナルとブラウザを使って作業していきます。
- ソースをブラウザで /Volumes/ffmpeg_gnutls/src にダウンロード
- Finder で圧縮ソースを展開
- ターミナルで make 作業
環境の前準備
作業環境を設定します。
以降ではプロンプト($)は略して、コピペしやすいように表記しておきます。
CMPL=/Volumes/ffmpeg_gnutls/src TARGET=/Volumes/ffmpeg_gnutls/sw PATH=${TARGET}/bin:$PATH export LDFLAGS=-L${TARGET}/lib export CFLAGS="-I${TARGET}/include -m64" export CC=clang
このあとはターミナルを変更しないでください。もし別のターミナルを使う場合には上記環境設定を実行してください。
pkg-configインストール
ダウンロード元:pkg-config
現在のファイル名(バージョン):pkg-config-0.28
cd /Volumes/ffmpeg_gnutls/src/pkg-config-0.28 ./configure --prefix=${TARGET} --with-pc-path=${TARGET}/lib/pkgconfig --with-internal-glib && make -j 4 && make install
pkg-configなど環境設定
作成環境の pkg-config ではなくスパースバンドル・ディスクイメージ内のpkgconfigを使う設定をします。
export PKG_CONFIG_PATH=${TARGET}/lib/pkgconfig
このあとはターミナルを変更しないでください。もし別のターミナルを使う場合には上記環境設定を実行してください。
Yasmインストール
ダウンロード元:The Yasm Modular Assembler Project
現在のファイル名(バージョン):yasm-1.3.0
cd ../yasm-1.3.0 ./configure --prefix=${TARGET} && make -j 4 && make install
Libtasn1インストール
ダウンロード元:Libtasn1 - GNU Project - Free Software Foundation
現在のファイル名(バージョン):libtasn1-4.2
cd ../libtasn1-4.2 ./configure --prefix=${TARGET} --disable-shared --enable-static && make -j 4 && make install
GMPインストール
ダウンロード元:The GNU MP Bignum Library
現在のファイル名(バージョン):gmp-6.0.0a
cd ../gmp-6.0.0 ./configure --prefix=${TARGET} --disable-shared --enable-static && make -j 4 && make install
Nettleインストール
本家サイト:Nettle - a low-level crypto library
ダウンロード元:Nettle-2.7.1
現在のファイル名(バージョン):nettle-2.7.1(本家での最新は 3.0 ですが、 GnuTLS が 3.0 未対応なので 2.7.1 をインストールしてください)
cd ../nettle-2.7.1 ./configure --prefix=${TARGET} --disable-shared --enable-static --with-include-path=${TARGET}/include --with-lib-path=${TARGET}/lib && make -j 4 && make install
GnuTLSインストール
依存:GMP と Nettle は必須です。Libtasn1 はオプションだけど要るようです。
ダウンロード元:GnuTLS
現在のファイル名(バージョン):gnutls-3.3.9
アーカイブが xz 形式なので Mac App Store - The Unarchiver などを使って展開してください。
cd ../gnutls-3.3.9 env LDFLAGS=-L${TARGET}/lib LIBS=-lgmp ./configure --prefix=${TARGET} --disable-shared --enable-static --without-p11-kit --disable-cxx --with-included-libtasn1 && make -j 4 && make install
lameインストール(MP3用)
ここからは FFmpeg で使う音楽ライブラリ(エンコーダ)のインストールです。
ダウンロード元:LAME MP3 Encoder
現在のファイル名(バージョン):lame-3.99.5
cd ../lame-3.99.5 ./configure --prefix=${TARGET} --disable-shared --enable-static && make -j 4 && make install
libfaacインストール(AAC用)
本家サイト:AudioCoding.com - FAAC
ダウンロード元:Freeware Advanced Audio Coder - Browse /faac-src at SourceForge.net
現在のファイル名(バージョン):faac-1.28
cd ../faac-1.28 ./configure --prefix=${TARGET} --disable-shared --enable-static --with-mp4v2 && make -j 4 && make install
libvorbisインストール
Ogg Vorbis を使いたい人だけ入れてください。
libogg と libvorbis をインストールします。
本家サイト:Xiph.org
ダウンロード元:Xiph.org: Downloads
現在のファイル名(バージョン):libogg-1.3.2 libvorbis-1.3.4
cd ../libogg-1.3.2 ./configure --prefix=${TARGET} --disable-shared --enable-static && make -j 4 && make install cd ../libvorbis-1.3.4 ./configure --prefix=${TARGET} --disable-shared --enable-static && make -j 4 && make install
xz(liblzma)インストール
FFmpeg のインストールに必要です。
ダウンロード元:XZ Utils
現在のファイル名(バージョン):xz-5.0.7
cd ../xz-5.0.7 ./configure --prefix=${TARGET} --disable-shared --enable-static && make -j 4 && make install
FFmpegインストール
# ffmpeg https://www.ffmpeg.org/
本家サイト:FFmpeg
ダウンロード元:Download FFmpeg
現在のファイル名(バージョン):ffmpeg-2.4.2
なお、Ogg Vorbisを入れない方は ./configure
から--enable-libvorbis
を外してください。
cd ../ffmpeg-2.4.2 ./configure --prefix=${TARGET} --libdir=${TARGET}/lib --enable-gpl --enable-nonfree --enable-libfaac --enable-pthreads --enable-libmp3lame --enable-libvorbis --enable-gnutls --pkg-config-flags=--static --disable-shared --enable-static --arch=x86_64 && make -j 4 && make install
インストール完了、確認
おつかれさまでした。これで /Volumes/ffmpeg_gnutls/sw/bin/ に GnuTLS 入り FFmpeg のバイナリファイルが出来ているはずです。確認してみましょう。
FFmpeg のバージョン表示と、otool -L ffmpeg
で表示される共有ライブラリを見てみます。
(otoolについての解説:LINKS 実行ファイルの依存ライブラリを調べる)
- Lion で作成した FFmpeg
$ ./ffmpeg -version ffmpeg version 2.4.2 Copyright (c) 2000-2014 the FFmpeg developers built on Oct 12 2014 22:47:43 with llvm-gcc 4.2.1 (LLVM build 2336.11.00) configuration: --prefix=/Volumes/ffmpeg_gnutls/sw --libdir=/Volumes/ffmpeg_gnutls/sw/lib --enable-gpl --enable-nonfree --enable-libfaac --enable-pthreads --enable-libmp3lame --enable-libvorbis --enable-gnutls --pkg-config-flags=--static --disable-shared --enable-static --arch=x86_64 libavutil 54. 7.100 / 54. 7.100 libavcodec 56. 1.100 / 56. 1.100 libavformat 56. 4.101 / 56. 4.101 libavdevice 56. 0.100 / 56. 0.100 libavfilter 5. 1.100 / 5. 1.100 libswscale 3. 0.100 / 3. 0.100 libswresample 1. 1.100 / 1. 1.100 libpostproc 53. 0.100 / 53. 0.100 $ otool -L ffmpeg ffmpeg: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0) /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.7.0) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5) /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0) /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5) /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.7.0)
$ ./ffmpeg -version ffmpeg version 2.4.2 Copyright (c) 2000-2014 the FFmpeg developers built on Oct 13 2014 17:46:04 with Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) configuration: --prefix=/Volumes/ffmpeg_gnutls/sw --libdir=/Volumes/ffmpeg_gnutls/sw/lib --enable-gpl --enable-nonfree --enable-libfaac --enable-pthreads --enable-libmp3lame --enable-libvorbis --enable-gnutls --pkg-config-flags=--static --disable-shared --enable-static --arch=x86_64 libavutil 54. 7.100 / 54. 7.100 libavcodec 56. 1.100 / 56. 1.100 libavformat 56. 4.101 / 56. 4.101 libavdevice 56. 0.100 / 56. 0.100 libavfilter 5. 1.100 / 5. 1.100 libswscale 3. 0.100 / 3. 0.100 libswresample 1. 1.100 / 1. 1.100 libpostproc 53. 0.100 / 53. 0.100 $ otool -L ffmpeg ffmpeg: /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1056.16.0) /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0) /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0) /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0) /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.17.0) /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5) /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
Mavericks で作ると、 Lion では使われていなかった共有ライブラリをいろいろたくさん使うようです。なので Mavericks で作った FFmpeg を Lion で使おうとすると残念ながら使えない…。 -mmacosx-version-min
とか -isysroot
を使って、 OS 別バージョンでも動作するようにするらしいのだが、わからんかったです。
GnuTLS入りスタティックFFmpeg作成のポイント
どうやら FFmpeg の ./configure
のオプションに--pkg-config-flags=--static
を使うのが重要なようです。pkg-config のライブラリを取り込んで --disable-shared --enable-static
で make するときに必要なのかな、と思っています。
参考:FFmpegのコンパイル (2014/02/17) お気に入りの動画を携帯で見ようのコメント欄、管理人(あべちん)さん2014年04月22日 23:52投稿。
参考リンク
- How To | FFmpeg Binary for Mac (WebArchive 2018/1/11)
Mac 関連 Tips: ffmpegコンパイルガイド→ffmpegコンパイルガイド – 桃源老師のつぶやき- FFmpegのコンパイル (2014/02/17) お気に入りの動画を携帯で見よう
- osx - How to compile a static FFmpeg binary on OS X - Stack Overflow
- homebrew-core/ffmpeg.rb at master · Homebrew/homebrew-core
- Building GnuTLS on Mac OS X
- FFmpeg License and Legal Considerations License Compliance Checklistが載っているので確認に使おう