Skip to content

Prebuild #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
09874c1
experimental prebuild
marcello3d Oct 28, 2020
7e67fe4
skip preinstall, install native deps on linux
marcello3d Oct 28, 2020
f2ce2cc
npm run lint
marcello3d Oct 28, 2020
98190e7
run install_ffmpeg, prebuild differently?
marcello3d Oct 28, 2020
19e7ec0
try to fix mac (update homebrew) and windows builds (gh token)
marcello3d Oct 28, 2020
a1ddb14
maybe fix macos build, add electron builds
marcello3d Oct 28, 2020
12c6321
update deps, files list, install script
marcello3d Oct 28, 2020
1e717ea
update package version
marcello3d Oct 28, 2020
6664cd1
include dll files in build, remove electron ones (doesn't seem like w…
marcello3d Oct 28, 2020
fc4a280
try to get build working on windows, cleanup github action script
marcello3d Oct 28, 2020
67311b2
try another approach to prebuilding
marcello3d Oct 28, 2020
ecf5f26
copy mac libraries in
marcello3d Oct 28, 2020
94fd102
try caret escape
marcello3d Oct 28, 2020
2f59f82
let's go windows
marcello3d Oct 28, 2020
a236dd1
come onnnnn
marcello3d Oct 28, 2020
80b8449
if this doesn't work…
marcello3d Oct 28, 2020
ed0ff8d
update copy_mac_libs to recurse
marcello3d Oct 28, 2020
a587cda
change logging in copy_mac_libs
marcello3d Oct 28, 2020
82f4056
do not try to rebuild with prebuild version
marcello3d Oct 28, 2020
e7b7baf
set -id in copy_mac_libs
marcello3d Oct 29, 2020
a0feafa
better log output in copy_mac_libs
marcello3d Oct 29, 2020
e698b36
disable copy_mac_libs to test
marcello3d Oct 29, 2020
ce8ff52
use loader_path instead of rpath (to search for library relative to t…
srubin Nov 30, 2020
d24ec26
fix stream.metadata type definition
marcello3d Dec 2, 2020
90b230a
try arm64 build
marcello3d Dec 2, 2020
2066bf2
0.6.10-rc.8
marcello3d Dec 2, 2020
0f02350
Use custom shared libraries from ffmpeg-build-scripts fork instead of…
srubin Dec 7, 2020
577d1dd
Attempt to fix types for paths
srubin Dec 7, 2020
73d1d55
...
srubin Dec 7, 2020
eba9ae0
treat warnings as errors
marcello3d Dec 9, 2020
9f1f9c8
fix config error
marcello3d Dec 9, 2020
4b4b4c8
bump version number
marcello3d Dec 10, 2020
bc4b7ec
do not add .exe to beamcoder.node on windows
marcello3d Dec 10, 2020
4ab8b58
bump versions (#5)
srubin Dec 16, 2020
5e65e5a
ffmpeg-ffprobe-static update (#6)
srubin Feb 3, 2021
03f8d22
Cvanwink/arm 3 (#9)
cvanwinkle May 25, 2023
e0f79f0
Merge branch 'master' into mbf/prebuild
srubin May 25, 2023
4caa6cf
update package lock
srubin May 25, 2023
e959710
Merge branch 'mbf/prebuild' of https://github.com/descriptinc/beamcod…
srubin May 25, 2023
ba522ca
Update package-lock.json
srubin May 25, 2023
a0ffd43
try including libzimg and checking deps
srubin May 25, 2023
e7e2f20
Update prebuild.yml
srubin May 25, 2023
43404a2
Update install_ffmpeg.js
srubin May 25, 2023
d8e7ecb
Update install_ffmpeg.js
srubin May 25, 2023
c60c497
force latest node-gyp to fix incompat between python 3.11 and node-gyp 6
srubin May 25, 2023
67a1d5f
try statically linking libstdc++
srubin May 26, 2023
baa4320
Update package.json
srubin May 26, 2023
a9c0c85
Update binding.gyp
srubin May 26, 2023
364aa49
Update package.json
srubin May 26, 2023
e02e9d2
build on ubuntu 20
srubin May 26, 2023
91e01fd
i don't think these were doing anything
srubin May 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/prebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: prebuild
on: [push]

jobs:
package:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
with:
lfs: true

- name: Use nodejs
uses: actions/setup-node@v1
with:
node-version: 16.13.0

- name: npm install
run: npm install
env:
PREBUILD: true

- name: install Linux dependencies
run: |
sudo add-apt-repository ppa:savoury1/ffmpeg4
sudo apt-get update
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev libzimg-dev
if: ${{ runner.os == 'Linux' }}

- name: check Linux dependencies
run: node ./install_ffmpeg.js
if: ${{ runner.os == 'Linux'}}

- name: install Mac build dependencies (brew)
run: brew install nasm pkg-config
if: ${{ runner.os == 'macOS'}}

- name: install Mac dependencies (shared release x64)
run: node ./install_ffmpeg.js --arch x64
if: ${{ runner.os == 'macOS'}}

- name: install Mac dependencies (shared release arm64)
run: node ./install_ffmpeg.js --arch arm64
if: ${{ runner.os == 'macOS'}}

- name: install Windows dependencies
run: node ./install_ffmpeg.js
if: ${{ runner.os == 'Windows'}}

- name: prebuild Release for macOS (x64)
run: npx prebuild --runtime napi --arch x64 --include-regex '(\.node|\.dylib|ffmpeg|ffprobe)$' --verbose --upload ${{ secrets.GITHUB_TOKEN }}
if: ${{ runner.os == 'macOS'}}

# - name: prebuild Debug for macOS (x64)
# run: npx prebuild --debug --runtime napi --arch x64 --include-regex '(\.node|\.dylib|ffmpeg|ffprobe)$' --upload ${{ secrets.GITHUB_TOKEN }}
# if: ${{ runner.os == 'macOS'}}

- name: clean build directory for cross-compiling
run: rm ./build/Release/*.dylib
if: ${{ runner.os == 'macOS'}}

- name: prebuild Release for macOS (arm64)
run: npx prebuild --runtime napi --arch arm64 --include-regex '(\.node|\.dylib|ffmpeg|ffprobe)$' --verbose --upload ${{ secrets.GITHUB_TOKEN }}
if: ${{ runner.os == 'macOS'}}

- name: prebuild for Windows
run: npx prebuild --runtime napi --include-regex '.node|.dll|.exe' --verbose --upload ${{ secrets.GITHUB_TOKEN }}
shell: bash
if: ${{ runner.os == 'Windows'}}

- name: prebuild for Linux (x64)
run: npx prebuild --runtime napi --arch x64 --include-regex '(\.node|\.dylib|ffmpeg|ffprobe)$' --upload ${{ secrets.GITHUB_TOKEN }}
if: ${{ runner.os == 'Linux'}}

- name: prebuild for Linux (arm64)
run: npx prebuild --runtime napi --arch arm64 --include-regex '(\.node|\.dylib|ffmpeg|ffprobe)$' --upload ${{ secrets.GITHUB_TOKEN }}
if: ${{ runner.os == 'Linux'}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typings/

# Native module build dir
build/
prebuilds/

# FFmpeg install folder
ffmpeg/
Expand All @@ -73,3 +74,5 @@ ffmpeg/
# Editors and IDE's
*.swp
.vscode/

.DS_Store
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ On Linux, use the appropriate package manager to install the FFmpeg 4.1 developm

sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt-get update
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev libzimg-dev

An example for Debian / Redhat / Fedora / CentOs will follow.

Expand Down
77 changes: 71 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
"src/packet.cc", "src/frame.cc",
"src/codec_par.cc", "src/format.cc",
"src/codec.cc", "src/hwcontext.cc" ],
"defines": [
"NAPI_VERSION=<(napi_build_version)"
],
"conditions": [
['OS!="win"', {
['OS=="linux"', {
"defines": [
"__STDC_CONSTANT_MACROS"
],
Expand All @@ -30,16 +33,76 @@
"-lavutil",
"-lpostproc",
"-lswresample",
"-lswscale"
"-lswscale",
"-lzimg"
]
},
"copies": [
{
"destination": "<(PRODUCT_DIR)",
"files": [
"node_modules/ffmpeg-ffprobe-static/ffmpeg",
"node_modules/ffmpeg-ffprobe-static/ffprobe",
]
}
]
}
}],
["OS=='mac'", {
"variables": {
"ffmpeg_version": "1.33rc3",
"target_arch_override": "<!(node -p \"'<(target_arch)' === 'x64' ? 'x86_64' : '<(target_arch)'\")",
},
"defines": [
"__STDC_CONSTANT_MACROS"
],
"cflags_cc!": [
"-fno-rtti",
"-fno-exceptions"
],
"cflags_cc": [
"-std=c++11",
"-fexceptions"
],
"include_dirs": [
"<(module_root_dir)/ffmpeg/ffmpeg-ffprobe-shared-darwin-<(target_arch_override).<(ffmpeg_version)/include/"
],
"link_settings": {
"library_dirs": [
"<(module_root_dir)/ffmpeg/ffmpeg-ffprobe-shared-darwin-<(target_arch_override).<(ffmpeg_version)/"
],
"libraries": [
"-Wl,-rpath,@loader_path",
"-lavcodec",
"-lavdevice",
"-lavfilter",
"-lavformat",
"-lavutil",
"-lpostproc",
"-lswresample",
"-lswscale",
"-lzimg"
],
},
'xcode_settings': {
'MACOSX_DEPLOYMENT_TARGET': '10.11',
},
"copies": [
{
"destination": "<(PRODUCT_DIR)",
"files": [
"<!@(node -p \"require('fs').readdirSync('ffmpeg/ffmpeg-ffprobe-shared-darwin-<(target_arch_override).<(ffmpeg_version)').map(f => 'ffmpeg/ffmpeg-ffprobe-shared-darwin-<(target_arch_override).<(ffmpeg_version)/' + f).join(' ')\")"
]
}
]
}
],
['OS=="win"', {
"configurations": {
"Release": {
"msvs_settings": {
"VCCLCompilerTool": {
"RuntimeTypeInfo": "true"
"RuntimeTypeInfo": "true",
"AdditionalOptions": ['/WX']
}
}
}
Expand All @@ -59,7 +122,7 @@
],
"copies": [
{
"destination": "build/Release/",
"destination": "<(PRODUCT_DIR)",
"files": [
"ffmpeg/ffmpeg-4.x-win64-shared/bin/avcodec-58.dll",
"ffmpeg/ffmpeg-4.x-win64-shared/bin/avdevice-58.dll",
Expand All @@ -68,7 +131,9 @@
"ffmpeg/ffmpeg-4.x-win64-shared/bin/avutil-56.dll",
"ffmpeg/ffmpeg-4.x-win64-shared/bin/postproc-55.dll",
"ffmpeg/ffmpeg-4.x-win64-shared/bin/swresample-3.dll",
"ffmpeg/ffmpeg-4.x-win64-shared/bin/swscale-5.dll"
"ffmpeg/ffmpeg-4.x-win64-shared/bin/swscale-5.dll",
"node_modules/ffmpeg-ffprobe-static/ffmpeg.exe",
"node_modules/ffmpeg-ffprobe-static/ffprobe.exe"
]
}
]
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ https://github.com/Streampunk/beamcoder/blob/master/LICENSE`;
console.log(splash);
console.log('Using FFmpeg version', beamcoder.avVersionInfo());

if (Object.values(beamcoder.configurations()).some(value => value.includes('--enable-small'))) {
console.error('beamcoder will crash because ffmpeg is compiled' +
' with --enable-small (because, for example, codec->long_name is ' +
'NULL and beamcoder expects it to be defined)');
}

beamcoder.demuxerStream = beamstreams.demuxerStream;
beamcoder.muxerStream = beamstreams.muxerStream;

Expand Down
5 changes: 5 additions & 0 deletions install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const {execSync} = require('child_process');

if (!process.env.PREBUILD) {
execSync('npx prebuild-install --runtime napi');
}
80 changes: 50 additions & 30 deletions install_ffmpeg.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const fs = require('fs');
const util = require('util');
const https = require('https');
const cp = require('child_process');
const { argv } = require('process');
const [ mkdir, access, rename, execFile, exec ] = // eslint-disable-line
[ fs.mkdir, fs.access, fs.rename, cp.execFile, cp.exec ].map(util.promisify);

Expand Down Expand Up @@ -83,7 +84,7 @@ async function inflate(rs, folder, name) {
return new Promise((comp, err) => {
console.log(`Unzipping '${folder}/${name}.zip'.`);
rs.pipe(unzip.Extract({ path: folder }).on('close', () => {
fs.rename(`./${folder}/${directoryName}`, `./${folder}/${name}`, () => {
fs.rename(`${folder}/${directoryName}`, `${folder}/${name}`, () => {
console.log(`Unzipping of '${folder}/${name}.zip' completed.`);
comp();
});
Expand Down Expand Up @@ -166,46 +167,65 @@ async function linux() {
console.error('libswscale.so.5 is not installed.');
result = 1;
}
if (stdout.indexOf('libzimg.so.2') < 0) {
console.error('libzimg.so.2 is not installed.');
result = 1;
}

if (result === 1) {
console.log(`Try running the following (Ubuntu/Debian):
sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev`);
sudo add-apt-repository ppa:savoury1/ffmpeg4
sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev libzimg-dev`);
process.exit(1);
}
return result;
}

async function darwin() {
console.log('Checking for FFmpeg dependencies via HomeBrew.');
let output;
let returnMessage;
console.log('Checking/downloading ffmpeg shared libraries');

await mkdir('ffmpeg').catch(e => {
if (e.code === 'EEXIST') return;
else throw e;
});

const version = '1.33rc3';

// default to platform-architecture
let arch = os.arch()

// but if the '--arch' argument is provided
// use the next argument as the value (e.g. 'x64' or 'arm64')
const overrideArchIndex = process.argv.indexOf('--arch');
if (0 < overrideArchIndex && overrideArchIndex < process.argv.length - 1) {
arch = process.argv[overrideArchIndex + 1];
}

try {
output = await exec('brew list ffmpeg');
returnMessage = 'FFmpeg already present via Homebrew.';
} catch (err) {
if (err.stderr !== 'Error: No such keg: /usr/local/Cellar/ffmpeg\n') {
console.error(err);
console.log('Either Homebrew is not installed or something else is wrong.\nExiting');
process.exit(1);
}

console.log('FFmpeg not installed. Attempting to install via Homebrew.');
try {
output = await exec('brew install nasm pkg-config texi2html ffmpeg');
returnMessage = 'FFmpeg installed via Homebrew.';
} catch (err) {
console.log('Failed to install ffmpeg:\n');
console.error(err);
process.exit(1);
}
if (arch === 'x64') {
arch = 'x86_64';
}

console.log(output.stdout);
console.log(returnMessage);
const ffmpegFilename = `ffmpeg-ffprobe-shared-darwin-${arch}.${version}`;
const tag = `v${version}`

return 0;
await access(`ffmpeg/${ffmpegFilename}`, fs.constants.R_OK).catch(async () => {
const ws = fs.createWriteStream(`ffmpeg/${ffmpegFilename}.zip`);
await get(
ws,
`https://github.com/descriptinc/ffmpeg-build-script/releases/download/${tag}/${ffmpegFilename}.zip`,
`${ffmpegFilename}.zip`
).catch(async (err) => {
if (err.name === 'RedirectError') {
const redirectURL = err.message;
await get(ws, redirectURL, `${ffmpegFilename}.zip`);
} else {
console.error(err);
throw err;
}
});

await exec(`unzip ffmpeg/${ffmpegFilename}.zip -d ffmpeg/${ffmpegFilename}/`);
});
}

switch (os.platform()) {
Expand All @@ -218,15 +238,15 @@ case 'win32':
}
break;
case 'linux':
if (os.arch() != 'x64') {
if (os.arch() != 'x64' && os.arch() != 'arm64') {
console.error('Only 64-bit platforms are supported.');
process.exit(1);
} else {
linux();
}
break;
case 'darwin':
if (os.arch() != 'x64') {
if (os.arch() != 'x64' && os.arch() != 'arm64') {
console.error('Only 64-bit platforms are supported.');
process.exit(1);
} else {
Expand Down
Loading