From 0aa421a04287a0b423f3aa5d64682d0590bf1e18 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 18 Nov 2020 17:34:32 -0700 Subject: [PATCH] add ffmpeg --- ffmpeg/README.md | 27 +++++++++++++++++++++++++ ffmpeg/install.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++++++ ffmpeg/install.sh | 41 +++++++++++++++++++++++++++++++++++++ ffmpeg/releases.js | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 ffmpeg/README.md create mode 100644 ffmpeg/install.sh create mode 100644 ffmpeg/releases.js diff --git a/ffmpeg/README.md b/ffmpeg/README.md new file mode 100644 index 0000000..4373ab0 --- /dev/null +++ b/ffmpeg/README.md @@ -0,0 +1,27 @@ +--- +title: ffmpeg +homepage: https://ffmpeg.org/ +tagline: | + FFmpeg: A complete, cross-platform solution to record, convert and stream audio and video. +--- + +## Updating `ffmpeg` + +```bash +webi ffmpeg@stable +``` + +Disclaimer: ffmpeg does not provide official binaries, so + is used. + +## Cheat Sheet + +> FFmpeg is useful for converting between various audio, video, and image +> formats. + +Many simple conversions can be auto-detected by file extension and the options +that produce the most similar quality by default. + +```bash +ffmpeg -i input.m4a output.mp3 +``` diff --git a/ffmpeg/install.ps1 b/ffmpeg/install.ps1 index 8b13789..d11bc0f 100644 --- a/ffmpeg/install.ps1 +++ b/ffmpeg/install.ps1 @@ -1 +1,51 @@ +#!/usr/bin/env pwsh +################## +# Install ffmpeg # +################## + +# Every package should define these variables +$pkg_cmd_name = "ffmpeg" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\ffmpeg.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\ffmpeg-v$Env:WEBI_VERSION\bin\ffmpeg.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\ffmpeg-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\ffmpeg-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading ffmpeg from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + Move-Item -Path "$pkg_download.part" -Destination "$pkg_download" -Force +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing ffmpeg" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\win32-*" -Recurse -ErrorAction Ignore + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force + Move-Item -Path "$pkg_download" -Destination "$pkg_src_cmd" -Force + + # Exit tmp + popd +} + +echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/ffmpeg/install.sh b/ffmpeg/install.sh new file mode 100644 index 0000000..fb0ef78 --- /dev/null +++ b/ffmpeg/install.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +{ + set -e + set -u + + ################## + # Install ffmpeg # + ################## + + # Every package should define these 6 variables + pkg_cmd_name="ffmpeg" + + pkg_dst_cmd="$HOME/.local/bin/ffmpeg" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/ffmpeg-v$WEBI_VERSION/bin/ffmpeg" + pkg_src_dir="$HOME/.local/opt/ffmpeg-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # ~/.local/opt/ffmpeg-v4.3.1/bin + mkdir -p "$(dirname $pkg_src_cmd)" + + # mv ./linux-x86 ~/.local/opt/ffmpeg-v4.3.1/bin/ffmpeg + mv ./*-* "$pkg_src_cmd" + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'ffmpeg -version' has output in this format: + # ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers + # built with Apple LLVM version 10.0.0 (clang-1000.11.45.5) + # ... + # This trims it down to just the version number: + # 4.3.1 + echo $(ffmpeg -version 2>/dev/null | head -n 1 | cut -d ' ' -f 3) + } + +} diff --git a/ffmpeg/releases.js b/ffmpeg/releases.js new file mode 100644 index 0000000..c3c2661 --- /dev/null +++ b/ffmpeg/releases.js @@ -0,0 +1,40 @@ +'use strict'; + +var path = require('path'); + +var github = require('../_common/github.js'); +var owner = 'eugeneware'; +var repo = 'ffmpeg-static'; + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + all.releases = all.releases + .filter(function (rel) { + // remove README and LICENSE + return !['.README', '.LICENSE'].includes(path.extname(rel.name)); + }) + .map(function (rel) { + rel.version = rel.version.replace(/^b/, ''); + + if (/win32/.test(rel.name)) { + rel.os = 'windows'; + rel.ext = 'exe'; + } + if (/ia32/.test(rel.name)) { + rel.arch = '386'; + } else if (/x64/.test(rel.name)) { + rel.arch = 'amd64'; + } + + return rel; + }); + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + console.info(JSON.stringify(all)); + }); +} -- 2.25.1