Skip to content
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

Update downloadsUrl to prioritize .npmrc variable #126

Closed
wants to merge 1 commit into from

Conversation

LZQCN
Copy link

@LZQCN LZQCN commented Aug 14, 2023

This commit updates the downloadsUrl variable to prioritize the value from the .npmrc file if it exists. The updated code checks process.env.npm_config_ffmpeg_binaries_url first and if it's not set, then it falls back to process.env[BINARIES_URL_ENV_VAR] or the default value if none of the variables are set. This change allows for more flexibility and customization when it comes to configuring the download URL for ffmpeg binaries.

This commit updates the `downloadsUrl` variable to prioritize the value from the `.npmrc` file if it exists. The updated code checks `process.env.npm_config_ffmpeg_binaries_url` first and if it's not set, then it falls back to `process.env[BINARIES_URL_ENV_VAR]` or the default value if none of the variables are set. This change allows for more flexibility and customization when it comes to configuring the download URL for ffmpeg binaries.
@derhuerst
Copy link
Collaborator

Thanks for the contribution!

Can you tell me about the use case? Why is passing in $FFMPEG_BINARIES_URL/$FFPROBE_BINARIES_URL not an option for you?

@LZQCN
Copy link
Author

LZQCN commented Aug 14, 2023

Thank you for reviewing this PR.

In my project, there are team members from China who have restricted access to GitHub and are using different operating systems. In order to install dependencies, we need to set the $FFPROBE_BINARIES_URL before running npm install to ensure that FFMPEG binaries can be downloaded from a mirror site. However, writing complex scripts to handle environment variable settings for each system is a time-consuming task.

To optimize this process, I have used the .npmrc file to easily configure the FFPROBE_BINARIES_URL option. This approach is simpler and customizable, allowing for easy configuration of the download URL for ffmpeg binaries.

@derhuerst
Copy link
Collaborator

derhuerst commented Aug 14, 2023

$FFMPEG_BINARIES_URL/$FFROBE_BINARIES_URL are agnostic to the OS & CPU architecture because they are only base URLs that a release tag & filename get appended to:

ffmpeg-static/install.js

Lines 169 to 174 in 7407c14

const downloadsUrl = (
process.env[BINARIES_URL_ENV_VAR] ||
'https://github.com/eugeneware/ffmpeg-static/releases/download'
)
const baseUrl = `${downloadsUrl}/${release}`
const downloadUrl = `${baseUrl}/${executableBaseName}-${platform}-${arch}.gz`

@luoway
Copy link

luoway commented Oct 12, 2023

ffmpeg-static/install.js

Lines 167 to 172 in 7407c14

const arch = process.env.npm_config_arch || os.arch()
const platform = process.env.npm_config_platform || os.platform()
const downloadsUrl = (
process.env[BINARIES_URL_ENV_VAR] ||
'https://github.com/eugeneware/ffmpeg-static/releases/download'
)

I think .npmrc file is used to configure downloadsUrl, rather than the arch & platform, which should be changed by environment vars.

@derhuerst
Copy link
Collaborator

I think there's some confusion here.

ffmpeg-static is written so that the (base) URL, which the actual binary download URLs get computed from, is configurable using the $FFMPEG_BINARIES_URL environment variable. Then, the release (e.g. b6.0, but also customisable via $FFMPEG_BINARY_RELEASE ) as well as the architecture- and platform-specific file name (e.g. ffmpeg-linux-x64.gz) get appended. This file is then being downloaded.

process.env.npm_config_* might be set by different tools/places:

  • For cross-platform building, Electron sets npm_config_arch & npm_config_platform to let npm packages build itself for the intended target platform. This convention seems to have become the de-facto standard to cross-platform builds in the npm packages ecosystem; For example, the well-known sharp package also uses them.
  • As explained in the sharp docs, npm_config_* can also be set by passing CLI flags to npm scripts (e.g. npm install --foo=bar).
  • When configuring foo=bar in ~/.npmrc, it will appear as process.env.npm_config_foo in the install script.

This means that, when installing ffmpeg-static (or ffprobe-static, see #19), you have lots of options to configure the downloads (base) URL, the ffmpeg binary release, and the CPU architecture & platform/OS.

Is this PR's intention to allow permanently changing (system-wide) ffmpeg-static's downloads (base) URL using .npmrc?

@LZQCN
Copy link
Author

LZQCN commented Oct 21, 2023

I apologize for any misunderstanding caused by the translation software, as my English is not very good. The reason I raised this PR is simply because .npmrc is easier to set up than environment variables.

@derhuerst
Copy link
Collaborator

derhuerst commented Dec 21, 2023

If you add an entry to .npmrc, it will also be set as an environment variable by npm, which ffmpeg-static then picks up.

@derhuerst derhuerst closed this Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants