macosffmpegelectronmac-app-storeelectron-packager

electron ffmpeg mas build "Illegal instruction: 4"


I am trying to release an electron app on the Mac Apple Store (mas), my electron app uses ffmpeg to render videos. In order to release my app on the mac apple store, It needs to be sandboxed, and by default ffmpeg makes calls to external libraries so I need to statically build ffmpeg and package it with my app. My code is on the 'mas-ffmpeg-fix' branch: https://github.com/MartinBarker/digify/tree/mas-ffmpeg-fix

My static ffmpeg build works before I build my app, but after running electron-builder build --mac, the ffmpeg executable now fails with Illegal instruction: 4

This is the full timeline of building/packaging/submitting my app to the mac apple store and where the error first appears:

Using ffmpeg with electron UI: works Using Ffmpeg with command-line command: /Users/martinbarker/Documents/projects/digify-new/ffmpeg-mac/ffmpeg -h Works

This is the first place the error appears, after building my mac mac-apple-store app, ffmpeg fails with this err.

Once this app gets published in the store, if you download it and try to run an ffmpeg command with the electron UI, it fails with this error:

/Applications/Digify.app/Contents/Resources/app.asar/node_modules/execa/lib/error.js:59 Uncaught (in promise) Error: Command failed with exit code 1: /Applications/Digify.app/Contents/Resources/ffmpeg -i /Users/martinbarker/Downloads/Felix Lebarty - Bobo/01. Bobo.mp3 -y -filter_complex concat=n=1:v=0:a=1 -c:a libmp3lame -b:a 320k /Users/martinbarker/Downloads/Felix Lebarty - Bobo/output-064237.mp3
ffmpeg version N-101191-g51a9f487ae-ntd_20150128 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  configuration: pkg_config='pkg-config --static' --pkg-config-flags=--static --libdir=/usr/local/lib --extra-version=ntd_20150128 --disable-shared --disable-lzma --enable-gpl --enable-pthreads --enable-nonfree --disable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libx264 --enable-static --enable-filters --enable-runtime-cpudetect
  libavutil      56. 65.100 / 56. 65.100
  libavcodec     58.125.100 / 58.125.100
  libavformat    58. 68.100 / 58. 68.100
  libavdevice    58. 12.100 / 58. 12.100
  libavfilter     7.107.100 /  7.107.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
[mp3 @ 0x7feeae809c00] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '/Users/martinbarker/Downloads/Felix Lebarty - Bobo/01. Bobo.mp3':
  Metadata:
    comment         : 
    album           : Bobo
    artist          : Felix Lebarty
    title           : Funkytown Eklablog
    genre           : Boogie
    date            : 1984
  Duration: 00:05:19.53, start: 0.000000, bitrate: 320 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
/Users/martinbarker/Downloads/Felix Lebarty - Bobo/output-064237.mp3: Operation not permitted
    at makeError (/Applications/Digify.app/Contents/Resources/app.asar/node_modules/execa/lib/error.js:59)
    at handlePromise (/Applications/Digify.app/Contents/Resources/app.asar/node_modules/execa/index.js:114)
    at async file:/Applications/Digify.app/Contents/Resources/app.asar/src/js/newindex.js:1162

Command failed with exit code 1: Operation not permitted


Solution

  • Turns out in electron you need to pick the output folder directory first with a file browser window before ffmpeg can write any files