add capnp and ffmpeg (#4)
This commit is contained in:
94
ffmpeg/build.sh
Normal file
94
ffmpeg/build.sh
Normal file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
|
||||
cd "$DIR"
|
||||
|
||||
FFMPEG_VERSION="7.1"
|
||||
INSTALL_DIR="$DIR/ffmpeg/install"
|
||||
|
||||
# Idempotent: skip if already built
|
||||
if [ -x "$INSTALL_DIR/bin/ffmpeg" ]; then
|
||||
echo "ffmpeg already present, skipping build."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
|
||||
PREFIX="$DIR/build/prefix"
|
||||
mkdir -p "$DIR/build"
|
||||
|
||||
# --- Build x264 (static) ---
|
||||
if [ ! -d "x264-src" ]; then
|
||||
git clone --depth 1 --branch stable https://code.videolan.org/videolan/x264.git x264-src
|
||||
fi
|
||||
|
||||
cd x264-src
|
||||
./configure \
|
||||
--prefix="$PREFIX" \
|
||||
--enable-static \
|
||||
--disable-shared \
|
||||
--disable-cli \
|
||||
--disable-opencl \
|
||||
--enable-pic
|
||||
make -j"$NJOBS"
|
||||
make install
|
||||
cd "$DIR"
|
||||
|
||||
# --- Build FFmpeg ---
|
||||
if [ ! -d "ffmpeg-src" ]; then
|
||||
git clone --depth 1 --branch "n${FFMPEG_VERSION}" https://github.com/FFmpeg/FFmpeg.git ffmpeg-src
|
||||
fi
|
||||
|
||||
cd ffmpeg-src
|
||||
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" \
|
||||
./configure \
|
||||
--prefix="$PREFIX" \
|
||||
--enable-gpl \
|
||||
--enable-static \
|
||||
--disable-shared \
|
||||
--enable-libx264 \
|
||||
--enable-pic \
|
||||
--disable-doc \
|
||||
--disable-ffplay \
|
||||
--disable-autodetect \
|
||||
--disable-everything \
|
||||
--enable-encoder=libx264,aac,ffvhuff,rawvideo,png \
|
||||
--enable-decoder=h264,hevc,ffvhuff,aac,rawvideo,png,mjpeg,mp3,pcm_s16le \
|
||||
--enable-muxer=mpegts,matroska,mp4,hevc,rawvideo,image2,null,mov \
|
||||
--enable-demuxer=hevc,matroska,mpegts,mov,rawvideo,image2,aac,concat \
|
||||
--enable-parser=h264,hevc,aac,mpegaudio \
|
||||
--enable-protocol=file,pipe \
|
||||
--enable-filter=blend,vflip,format,scale,aformat,anull,aresample,null \
|
||||
--enable-bsf=extract_extradata,h264_mp4toannexb,hevc_mp4toannexb \
|
||||
--extra-cflags="-I$PREFIX/include" \
|
||||
--extra-ldflags="-L$PREFIX/lib"
|
||||
make -j"$NJOBS"
|
||||
make install
|
||||
cd "$DIR"
|
||||
|
||||
# Copy to package install dir
|
||||
rm -rf "$INSTALL_DIR"
|
||||
mkdir -p "$INSTALL_DIR"/{bin,lib,include}
|
||||
|
||||
# Binaries
|
||||
cp "$PREFIX/bin/ffmpeg" "$INSTALL_DIR/bin/"
|
||||
cp "$PREFIX/bin/ffprobe" "$INSTALL_DIR/bin/"
|
||||
|
||||
# Libraries
|
||||
for lib in libavformat.a libavcodec.a libavutil.a libswresample.a libx264.a; do
|
||||
cp "$PREFIX/lib/$lib" "$INSTALL_DIR/lib/"
|
||||
done
|
||||
|
||||
# Headers
|
||||
for dir in libavformat libavcodec libavutil libswresample; do
|
||||
cp -r "$PREFIX/include/$dir" "$INSTALL_DIR/include/"
|
||||
done
|
||||
|
||||
# Strip binaries
|
||||
strip "$INSTALL_DIR/bin/ffmpeg" "$INSTALL_DIR/bin/ffprobe" 2>/dev/null || true
|
||||
|
||||
# Clean up
|
||||
rm -rf x264-src ffmpeg-src "$DIR/build"
|
||||
|
||||
echo "Installed ffmpeg to $INSTALL_DIR"
|
||||
du -sh "$INSTALL_DIR"
|
||||
20
ffmpeg/ffmpeg/__init__.py
Normal file
20
ffmpeg/ffmpeg/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
DIR = os.path.join(os.path.dirname(__file__), "install")
|
||||
BIN_DIR = os.path.join(DIR, "bin")
|
||||
LIB_DIR = os.path.join(DIR, "lib")
|
||||
INCLUDE_DIR = os.path.join(DIR, "include")
|
||||
|
||||
|
||||
def _run(name):
|
||||
binary = os.path.join(BIN_DIR, name)
|
||||
os.execvp(binary, [binary] + sys.argv[1:])
|
||||
|
||||
|
||||
def _run_ffmpeg():
|
||||
_run("ffmpeg")
|
||||
|
||||
|
||||
def _run_ffprobe():
|
||||
_run("ffprobe")
|
||||
19
ffmpeg/pyproject.toml
Normal file
19
ffmpeg/pyproject.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=64", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "ffmpeg"
|
||||
version = "7.1.0"
|
||||
description = "FFmpeg media tools and libraries (minimal build for openpilot)"
|
||||
requires-python = ">=3.8"
|
||||
|
||||
[project.scripts]
|
||||
ffmpeg = "ffmpeg:_run_ffmpeg"
|
||||
ffprobe = "ffmpeg:_run_ffprobe"
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
include = ["ffmpeg*"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
ffmpeg = ["install/**/*"]
|
||||
61
ffmpeg/setup.py
Normal file
61
ffmpeg/setup.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
|
||||
from setuptools.command.build_py import build_py
|
||||
|
||||
try:
|
||||
from wheel.bdist_wheel import bdist_wheel
|
||||
except ImportError:
|
||||
bdist_wheel = None
|
||||
|
||||
|
||||
class BuildFFmpeg(build_py):
|
||||
"""Run build.sh to compile ffmpeg before collecting package data."""
|
||||
|
||||
def run(self):
|
||||
pkg_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
marker = os.path.join(pkg_dir, "ffmpeg", "install", "bin", "ffmpeg")
|
||||
|
||||
if not os.path.exists(marker):
|
||||
build_script = os.path.join(pkg_dir, "build.sh")
|
||||
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
|
||||
|
||||
super().run()
|
||||
|
||||
|
||||
cmdclass = {"build_py": BuildFFmpeg}
|
||||
|
||||
if bdist_wheel is not None:
|
||||
|
||||
class PlatformWheel(bdist_wheel):
|
||||
"""Produce a platform-specific, Python-version-agnostic wheel."""
|
||||
|
||||
def finalize_options(self):
|
||||
super().finalize_options()
|
||||
self.root_is_pure = False
|
||||
|
||||
def get_tag(self):
|
||||
system = platform.system()
|
||||
machine = platform.machine()
|
||||
|
||||
if system == "Linux":
|
||||
plat = f"linux_{machine}"
|
||||
elif system == "Darwin":
|
||||
plat = "macosx_11_0_arm64"
|
||||
else:
|
||||
plat = f"{system.lower()}_{machine}"
|
||||
|
||||
return "py3", "none", plat
|
||||
|
||||
cmdclass["bdist_wheel"] = PlatformWheel
|
||||
|
||||
|
||||
def setup():
|
||||
from setuptools import setup as _setup
|
||||
|
||||
_setup(cmdclass=cmdclass)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup()
|
||||
Reference in New Issue
Block a user