hkrn / nanoem

nanoem is an MMD (MikuMikuDance) compatible implementation and its like cross-platform application mainly built for macOS.
https://nanoem.rtfd.io
Other
296 stars 41 forks source link

[BUG] Cannot use plugin_ffmpeg on macOS #298

Closed mityu closed 1 year ago

mityu commented 1 year ago

Describe the bug Cannot use plugin_ffmpeg when exporting a video on macOS even whenplugin_ffmpeg.dylib exists at nanoem.app/Contents/PlugIns.

To Reproduce

  1. Open nanoem.app
  2. Select "動画" menu via "ファイル→書き出し→動画"
  3. See available plugin list

Expected behavior

plugin_ffmpeg appears in plugin list at step 3.

Screenshots

スクリーンショット 2023-03-28 22 50 12 スクリーンショット 2023-03-28 22 45 49

Desktop (please complete the following information):

Additional context

It seems that the reason is that some paths of the shared libraries which plugin_ffmpeg.dylib depends on are incorrect:

$ cd /Applications/nanoem.app/Contents/PlugIns
$ otool -L ./plugin_ffmpeg.dylib
./plugin_ffmpeg.dylib (architecture x86_64):
    @rpath/plugin_ffmpeg.dylib (compatibility version 0.0.0, current version 0.0.0)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libavutil.56.dylib (compatibility version 56.0.0, current version 56.31.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libavformat.58.dylib (compatibility version 58.0.0, current version 58.29.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.54.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libswresample.3.dylib (compatibility version 3.0.0, current version 3.5.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libswscale.5.dylib (compatibility version 5.0.0, current version 5.5.100)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1953.255.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.255.0)
./plugin_ffmpeg.dylib (architecture arm64):
    @rpath/plugin_ffmpeg.dylib (compatibility version 0.0.0, current version 0.0.0)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libavutil.56.dylib (compatibility version 56.0.0, current version 56.31.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libavformat.58.dylib (compatibility version 58.0.0, current version 58.29.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.54.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libswresample.3.dylib (compatibility version 3.0.0, current version 3.5.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libswscale.5.dylib (compatibility version 5.0.0, current version 5.5.100)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1953.255.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)

Probably, for libavutil.56.dylib, libavformat.58.dylib, libavcodec.58.dylib, libswresample.3.dylib and libswscale.5.dylib shared libraries, nanoem.app/Contents/Frameworks directory should be their parent directory, but another directory is there.

Note that I tried a workaround that modifies these paths, and this successfully fixed this problem just for arm64:

#!/bin/bash

# Run this script at nanoem.app/Contents/PlugIns directory.
install_name_tool -change "/Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libavutil.56.dylib"  "@executable_path/../Frameworks/libavutil.56.dylib" ./plugin_ffmpeg.dylib
install_name_tool -change "/Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libavformat.58.dylib"  "@executable_path/../Frameworks/libavformat.58.dylib" ./plugin_ffmpeg.dylib
install_name_tool -change "/Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libavcodec.58.dylib"  "@executable_path/../Frameworks/libavcodec.58.dylib" ./plugin_ffmpeg.dylib
install_name_tool -change "/Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libswresample.3.dylib"  "@executable_path/../Frameworks/libswresample.3.dylib" ./plugin_ffmpeg.dylib
install_name_tool -change "/Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/arm64/install-root/lib/libswscale.5.dylib"  "@executable_path/../Frameworks/libswscale.5.dylib" ./plugin_ffmpeg.dylib

otool -L ./plugin_ffmpeg.dylib result after running script:

./plugin_ffmpeg.dylib (architecture x86_64):
    @rpath/plugin_ffmpeg.dylib (compatibility version 0.0.0, current version 0.0.0)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libavutil.56.dylib (compatibility version 56.0.0, current version 56.31.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libavformat.58.dylib (compatibility version 58.0.0, current version 58.29.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.54.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libswresample.3.dylib (compatibility version 3.0.0, current version 3.5.100)
    /Users/hkrn/Library/Developer/build/nanoem/main/dependencies/ffmpeg/out/darwin/clang/ub/release/interm/x86_64/install-root/lib/libswscale.5.dylib (compatibility version 5.0.0, current version 5.5.100)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1953.255.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.255.0)
./plugin_ffmpeg.dylib (architecture arm64):
    @rpath/plugin_ffmpeg.dylib (compatibility version 0.0.0, current version 0.0.0)
    @executable_path/../Frameworks/libavutil.56.dylib (compatibility version 56.0.0, current version 56.31.100)
    @executable_path/../Frameworks/libavformat.58.dylib (compatibility version 58.0.0, current version 58.29.100)
    @executable_path/../Frameworks/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.54.100)
    @executable_path/../Frameworks/libswresample.3.dylib (compatibility version 3.0.0, current version 3.5.100)
    @executable_path/../Frameworks/libswscale.5.dylib (compatibility version 5.0.0, current version 5.5.100)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1953.255.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)

plugin_ffmpeg appeared in plugin list and a video with transparent background is successfully exported.

image

P.S. I report this on issue because I don't know much about dylibs and what is the proper fix. Sorry.

hkrn commented 1 year ago

As you are already aware of it, this is due to a failure to resolve the library path of plugin_ffmpeg in the package.

By way of background, up to 34.7, the "wrong package" was being done. Therefore, a fix #274 was made in 34.8.1 to make it the "correct package". However, for some reason plugin_ffmpeg was released with the wrong path resolution (maybe caused by #274).

Of course this is not the intentded behavior and will be fixed in the next release with high priority.

mityu commented 1 year ago

Oh, I didn't noticed this is a known issue. By the way, I confirmed that this problem is fixed by the latest v34.9 release. Thank you!