Ffmpeg在Electron沙盒应用程序中中止
我有一个Electron应用程序,已在Mac AppStore上发布,并已沙箱化.
I have an Electron app, published on the Mac AppStore, and sandboxed.
我正在尝试添加一项新功能,该功能将即时对视频进行编码/解码,以便在电子环境中流式传输更多视频格式.
I'm trying to add a new feature that will encode/decode videos on the fly so I can stream more video formats in an Electron context.
我正在使用 fluent-ffmpeg 和 ffmpeg的静态执行程序.
一切正常,我已将沙盒应用程序上传到Apple,但遭到拒绝,因为ffmpeg默认情况下使用的是使用非公开API的安全传输协议,这就是他们向我发送的拒绝消息:
Everything works awesomely, I've uploaded the sandboxed app to Apple, and got rejected because ffmpeg is using by default a secure transport protocol which is using non-public API, this is what they've sent me with the rejection:
您的应用使用或引用了以下非公开API:
Your app uses or references the following non-public API(s):
'/System/Library/Frameworks/Security.framework/Versions/A/Security'
'/System/Library/Frameworks/Security.framework/Versions/A/Security'
:SecIdentityCreate
: SecIdentityCreate
好的,经过大量研究,看来我必须使用--disable-securetransport
标志来编译ffmpeg我自己.足够简单,我使用与下载的静态版本相同的配置来完成该任务,只需添加新标志即可.
Alright, after much investigation, it appears that I have to compile ffmpeg myself with a --disable-securetransport
flag. Easy enough, I do it using the same config as the static build I've downloaded simply adding the new flag.
我设法安装了所需的所有依赖项,除了libxavs
,我想没什么大不了的,只需从configure命令中删除其标志即可:
I manage to install every dependencies needed, except libxavs
, no big deal I guess and simply remove its flag from the configure command:
./configure \
--cc=/usr/bin/clang \
--prefix=/opt/ffmpeg \
--extra-version=tessus \
--enable-avisynth \
--enable-fontconfig \
--enable-gpl \
--enable-libass \
--enable-libbluray \
--enable-libfreetype \
--enable-libgsm \
--enable-libmodplug \
--enable-libmp3lame \
--enable-libopencore-amrnb \
--enable-libopencore-amrwb \
--enable-libopus \
--enable-libsnappy \
--enable-libsoxr \
--enable-libspeex \
--enable-libtheora \
--enable-libvidstab \
--enable-libvo-amrwbenc \
--enable-libvorbis \
--enable-libvpx \
--enable-libwavpack \
--enable-libx264 \
--enable-libx265 \
--enable-libxvid \
--enable-libzmq \
--enable-libzvbi \
--enable-version3 \
--pkg-config-flags=--static \
--disable-securetransport \
--disable-ffplay
使用新的ffmpeg exec,一切仍然可以按预期进行.但是,一旦我打包,签名并对该应用程序进行沙箱处理,ffmpeg会在尝试启动它时立即停止工作,并抛出以下错误:
With the new ffmpeg exec, everything still works as expected. But once I'm packaging, signing and sandboxing the app, ffmpeg stops working as soon as I try to launch it throwing this error:
An error occurred ffmpeg was killed with signal SIGABRT Error: ffmpeg was killed with signal SIGABRT
at ChildProcess.eval (webpack:///../node_modules/fluent-ffmpeg/lib/processor.js?:180:22)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
我试图删除--disable-securetransport
标志,看它是否可能被某些东西弄乱了,结果还是一样.
I've tried to remove the --disable-securetransport
flag, see if it could have messed with something, same result.
我试图在Linux机器上进行编译,只是为了看看它是否可以起到帮助作用.
I've tried to compile on a Linux machine, just to see if it could help, same thing.
一旦我使用自定义编译的exec,它就不会在沙箱中运行,但是当使用静态沙箱时,一切正常(在我xattr
之后,因为
As soon as I'm using my custom compiled exec it doesn't work in the sandbox, but when using the static one, everything is ok (after I xattr
it, because it's quarantined and blocked in sandbox).
我注意到的唯一一件奇怪的事情是,我的自定义编译只有20mo左右,而当我下载的静态安装为43mo时.
The only thing I've noticed that seems odd is that my custom compilation is only 20mo or so, when the static install I've downloaded is 43mo.
我真的很坚持.
所以我终于能够编译我的静态ffmpeg可执行文件.
So I finally was able to compile my static ffmpeg executable.
由于此答案,我找到了解决方案.
I've found my solution thanks to this answer.
显然,OSX在/usr/local/bin
中具有动态库,该库优先于其他所有库.因此,即使您尝试将ffmpeg编译为静态,也不会在这些库中使用它们.
Apparently, OSX has dynamic libraries located in /usr/local/bin
which take precedence over everything else. So even if you try to compile your ffmpeg to be static, it won't work with these libraries on the way.
一旦我删除了所有这些/usr/local/bin/*.dylib
,我的构建就变得完全静态并且可以在沙箱中完美运行.
Once I've removed all those /usr/local/bin/*.dylib
my build became fully static and worked perfectly in the sandbox.