このページでは

macOS での iOS 向け FFmpeg のソースからのビルド

このページでは、iOS 向けのFFmpeg をフレームワークとして設定・ビルドする方法について説明します。iOS 向けのコンパイルはクロスコンパイルであり、ホストシステムとして macOS を使用することを前提としています。必要な手順は以下の通りです:

  • FFmpegのソースコードを入手します。
  • 必要な依存関係をインストールします。
  • コマンドラインからFFmpegを構成します。
  • 開発用ライブラリをビルドする。
  • FFmpegライブラリからiOSフレームワークを作成する。
  • XCFrameworks を作成します。
  • フレームワークをアプリケーションバンドルに組み込みます。

FFmpegのソースコードを入手する

FFmpegのソースコードは、以下の方法で入手できます。

  • FFmpegのダウンロードページからダウンロードします。
  • Gitからクローンする。たとえば、次のコマンドを実行すると、FFmpegのバージョン9.0.1のソースコードが~/ffmpeg にクローンされます。
    git clone --branch n9.0.1 https://git.ffmpeg.org/ffmpeg.git ffmpeg

Qt Multimedia のメインページに記載されているのと同じバージョンの FFmpeg を使用することをお勧めします。

以下の説明では、FFmpegのソースコードを~/ffmpeg に保存していることを前提としています。

前提条件

FFmpeg をビルドするには、以下のツールとパッケージが必要です。

  • Xcode:ビルドおよびリンクに使用するツールチェーン(コンパイラ、リンカ、その他のツール)と、iOSプラットフォームSDK(ヘッダーおよびライブラリ)を提供します。

FFmpegの設定とビルド

~/ffmpeg ディレクトリ内にbuild およびinstalled ディレクトリを作成し、build に移動します:

mkdir ~/ffmpeg/build
mkdir ~/ffmpeg/installed
cd ~/ffmpeg/build

FFmpeg を設定するには、次のコマンドを実行します:

../ffmpeg_src/configure --disable-programs --disable-doc --enable-network --enable-shared --disable-static \
    --sysroot="$(xcrun --sdk iphoneos --show-sdk-path)" \
    --enable-cross-compile \
    --arch=arm64 \
    --prefix=../installed \
    --cc="xcrun --sdk iphoneos clang -arch arm64" \
    --cxx="xcrun --sdk iphoneos clang++ -arch arm64" \
    --extra-cflags="-miphoneos-version-min=16.0" \
    --extra-cxxflags="-miphoneos-version-min=16.0" \
    --extra-objcflags="-miphoneos-version-min=16.0" \
    --extra-ldflags="-miphoneos-version-min=16.0" \
    --install-name-dir='@rpath' \
    --disable-audiotoolbox

コマンドラインプログラムやドキュメントは不要です。ネットワーク機能は有効にしておく必要があります。ここでは共有ライブラリをビルドするため、静的ライブラリは必要ありません(静的ライブラリをビルドする場合は `--disable-static ` を省略してください)。`--sysroot ` はクロスビルドツリーのルートを指定します。`--prefix ` 引数は、ビルド後に FFmpeg ライブラリがインストールされるパスを指定します。 iOS ターゲット向けに macOS ホスト上でビルドするため、クロスコンパイルを有効にします。--extra-ldflags は iOS の最小バージョンを設定します。--install-name-dir は、インストール済みターゲット向けの Apple プラットフォーム上の共有ライブラリの「install_name」フィールドのディレクトリ部分を指定する文字列です。 AudioToolBoxは無効化されています。これは、FFmpegがAudioToolBoxフレームワークの一部を使用していますが、それらはiOSでは利用できないためです。

注: 上記の例で 、「iphoneos」を「iphonesimulator」に、「miphoneos-version」を「mios-simulator-version-min」に置き換えると、FFmpeg が iOS シミュレータに適したライブラリとしてビルドされるように設定されます。

その他の設定オプションに関するヘルプを表示するには、次のコマンドを実行してください:

../ffmpeg_src/configure --help

設定が完了したら、FFmpeg ライブラリをビルドします:

make -j install

FFmpegライブラリからのiOSフレームワークの作成

iOSアプリケーションで動作させるには、FFmpegのダイナミックライブラリをフレームワークに変換し、アプリケーションバンドルに組み込む必要があります。フレームワークとは、ダイナミックライブラリ、画像ファイル、ローカライズされた文字列、ヘッダーファイル、参照ドキュメントなどのリソースを単一のパッケージにカプセル化した階層的なディレクトリ構造のことです。 今回の場合、FFmpegフレームワークには動的ライブラリと対応するInfo.plistファイルのみが含まれます。例えば、フレームワークに変換されたlibavcodecは、次のような内容を持つlibavcodec.framework ディレクトリになります:

  • Info.plist(フレームワークの説明を含む)
  • libavcodec(ダイナミックライブラリ)

前の手順でビルドしたダイナミックライブラリとは異なり、iOSフレームワーク内のダイナミックライブラリにはバージョン番号がなく、「dylib」という拡張子もありません。そのため、ダイナミックライブラリ内のライブラリ識別名と依存関係を修正する必要があります。otool ユーティリティを使用すると、そのような名前を見つけることができます。例えば:

otool -L ../installed/lib/libavcodec.dylib

これにより、以下の名前が得られます(ここでは FFmpeg に関連する名前のみを示します):

@rpath/libavcodec.61.dylib (compatibility version 61.0.0, current version 61.19.100)
@rpath/libswresample.5.dylib (compatibility version 5.0.0, current version 5.3.100)
@rpath/libavutil.59.dylib (compatibility version 59.0.0, current version 59.39.100)

これらの名前を修正するには、install_name_tool ユーティリティを使用します。このユーティリティのオプションは以下の通りです:

  • -id - 共有ライブラリの識別名を変更できます。
  • -change - 依存する共有ライブラリのインストール名を変更できます。

このスクリプトは、以前にビルドされたダイナミックライブラリをフレームワークに変換します。このコードは、build ディレクトリから実行され、フレームワークが~/ffmpeg/installed/framework にあることを前提としています:

#!/usr/bin/env bash

# Creates an Info.plist file for a given framework:
build_info_plist() {
    local file_path="$1"
    local framework_name="$2"
    local framework_id="$3"

    # Minimum version must be the same we used when building FFmpeg.
    local minimum_version_key="MinimumOSVersion"
    local minimum_os_version="16.0"

    local supported_platforms="iPhoneOS"

    info_plist="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>${framework_name}</string>
    <key>CFBundleIdentifier</key>
    <string>${framework_id}</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${framework_name}</string>
    <key>CFBundlePackageType</key>
    <string>FMWK</string>
    <key>CFBundleShortVersionString</key>
    <string>9.0.1</string>
    <key>CFBundleVersion</key>
    <string>9.0.1</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>${minimum_version_key}</key>
    <string>${minimum_os_version}</string>
    <key>CFBundleSupportedPlatforms</key>
    <array>
        <string>${supported_platforms}</string>
    </array>
    <key>NSPrincipalClass</key>
    <string></string>
</dict>
</plist>"
    echo $info_plist | tee ${file_path} 1>/dev/null
}

dylib_regex="^@rpath/.*\.dylib$"

# Creates framework from a dylib file:
create_framework() {
    local framework_name="$1"
    local ffmpeg_library_path="../installed"
    local framework_complete_path="${ffmpeg_library_path}/framework/${framework_name}.framework/${framework_name}"

    # Create framework directory and copy dylib file to this directory:
    mkdir -p "${ffmpeg_library_path}/framework/${framework_name}.framework"
    cp "${ffmpeg_library_path}/lib/${framework_name}.dylib" "${ffmpeg_library_path}/framework/${framework_name}.framework/${framework_name}"

    # Change the shared library identification name, removing version number and 'dylib' extension;
    # \c Frameworks part of the name is needed since this is where frameworks will be installed in
    # an application bundle:
    install_name_tool -id @rpath/Frameworks/${framework_name}.framework/${framework_name} "${framework_complete_path}"

    # Add Info.plist file into the framework directory:
    build_info_plist "${ffmpeg_library_path}/framework/${framework_name}.framework/Info.plist" "${framework_name}" "io.qt.ffmpegkit."${framework_name}
    otool -L "$framework_complete_path" | awk '/\t/ {print $1}' | egrep "$dylib_regex" | while read -r dependency_path; do
        found_name=$(tmp=${dependency_path/*\/}; echo ${tmp/\.*})
        if [ "$found_name" != "$framework_name" ]
        then
            # Change the dependent shared library install name to remove version number and 'dylib' extension:
            install_name_tool -change "$dependency_path" @rpath/Frameworks/${found_name}.framework/${found_name} "${framework_complete_path}"
        fi
    done
}

ffmpeg_libs="libavcodec libavformat libavutil libswresample libswscale"

for name in $ffmpeg_libs; do
    create_framework $name
done

マルチプラットフォームバイナリフレームワークバンドルの作成

XCFrameworkバンドルとは、iOSやiOSシミュレータなど、複数のプラットフォーム向けにビルドするために必要なフレームワークやライブラリを含むパッケージのことです。このようなフレームワークを作成するには、xcodebuild ユーティリティを使用します。たとえば、iOSおよびシミュレータ用のフレームワークが~/ffmpeg/installed/arm64 および~/ffmpeg/installed/arm64-simulator ディレクトリにある場合、ユーティリティの引数は次のようになります:

xcodebuild -create-xcframework -framework ../installed/arm64/libavcodec.framework -framework ../installed/arm64-simulator/libavcodec.framework -output ../installed/framework/libavcodec.xcframework

フレームワークの埋め込み

FFmpeg フレームワークをアプリケーションバンドルに埋め込みます。Xcode を使用してフレームワークを埋め込む方法については、

「アプリへのフレームワークの組み込み」を参照してください。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.