From fcadadefa429e6fa4c6d43d5a0d9cc4aaef50a82 Mon Sep 17 00:00:00 2001 From: Sean Pollock Date: Thu, 19 Sep 2024 14:52:46 -0400 Subject: [PATCH] [RSDK-8764] - Add Darwin support (#14) * Add darwin make flow * Use int64_t instead of long * Test on darwin * Use 8vcpu * Try 4 vcpu * Try github runner * Install deps in makefile * Remove x264 install * Fix indent * Remove gitlfs install * Use spaces * Tab * reset * Move * Add darwin logic back in * Add darwin publish --- .github/workflows/lint.yml | 5 ----- .github/workflows/publish.yml | 9 +++------ .github/workflows/test.yml | 7 ++----- Makefile | 20 +++++++++++++++++--- cam/encoder.go | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5c29b5c..e8746c5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,10 +26,5 @@ jobs: with: go-version: 1.21 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y libx264-dev - - name: Run linter run: make lint diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4879e4a..15a585d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,9 @@ jobs: runs-on: ubuntu-latest - platform: linux/arm64 runs-on: buildjet-8vcpu-ubuntu-2204-arm - + - platform: darwin/arm64 + runs-on: macos-latest + runs-on: ${{ matrix.runs-on }} steps: @@ -24,11 +26,6 @@ jobs: with: go-version: 1.21.13 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y libx264-dev - - name: Build and package run: make module diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b9e7b05..431897a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,8 @@ jobs: runs-on: ubuntu-latest - platform: linux/arm64 runs-on: buildjet-8vcpu-ubuntu-2204-arm + - platform: darwin/arm64 + runs-on: macos-latest runs-on: ${{ matrix.runs-on }} steps: @@ -34,10 +36,5 @@ jobs: with: go-version: 1.21.13 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y libx264-dev git-lfs - - name: Run tests run: make test diff --git a/Makefile b/Makefile index aaa78ad..860ec72 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,14 @@ FFMPEG_OPTS ?= --prefix=$(FFMPEG_BUILD) \ --enable-protocol=crypto \ --enable-bsf=h264_mp4toannexb -CGO_LDFLAGS := "-L$(FFMPEG_BUILD)/lib -lavcodec -lavutil -lavformat -l:libjpeg.a -l:libx264.a -lz" +CGO_LDFLAGS := -L$(FFMPEG_BUILD)/lib -lavcodec -lavutil -lavformat -lz +ifeq ($(SOURCE_OS),linux) + CGO_LDFLAGS += -l:libjpeg.a -l:libx264.a +endif +ifeq ($(SOURCE_OS),darwin) + CGO_LDFLAGS += $(HOMEBREW_PREFIX)/Cellar/x264/r3108/lib/libx264.a -liconv +endif + CGO_CFLAGS := -I$(FFMPEG_BUILD)/include GOFLAGS := -buildvcs=false export PKG_CONFIG_PATH=$(FFMPEG_BUILD)/lib/pkgconfig @@ -43,7 +50,7 @@ export PKG_CONFIG_PATH=$(FFMPEG_BUILD)/lib/pkgconfig $(BIN_OUTPUT_PATH)/video-store: *.go cam/*.go $(FFMPEG_BUILD) go mod tidy - CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_CFLAGS=$(CGO_CFLAGS) go build -o $(BIN_OUTPUT_PATH)/video-store main.go + CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS=$(CGO_CFLAGS) go build -o $(BIN_OUTPUT_PATH)/video-store main.go $(FFMPEG_VERSION_PLATFORM): git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch $(FFMPEG_TAG) $(FFMPEG_VERSION_PLATFORM) @@ -51,9 +58,17 @@ $(FFMPEG_VERSION_PLATFORM): $(FFMPEG_BUILD): $(FFMPEG_VERSION_PLATFORM) # Only need nasm to build assembly kernels for amd64 targets. ifeq ($(SOURCE_OS),linux) +ifeq ($(shell dpkg -l | grep -w x264 > /dev/null; echo $$?), 1) + sudo apt update && sudo apt install -y libx264-dev +endif ifeq ($(SOURCE_ARCH),amd64) which nasm || (sudo apt update && sudo apt install -y nasm) endif +endif +ifeq ($(SOURCE_OS),darwin) +ifeq ($(shell brew list | grep -w x264 > /dev/null; echo $$?), 1) + brew update && brew install x264 +endif endif cd $(FFMPEG_VERSION_PLATFORM) && ./configure $(FFMPEG_OPTS) && $(MAKE) -j$(NPROC) && $(MAKE) install @@ -67,7 +82,6 @@ lint: tool-install $(FFMPEG_BUILD) go mod tidy CGO_CFLAGS=$(CGO_CFLAGS) GOFLAGS=$(GOFLAGS) $(TOOL_BIN)/golangci-lint run -v --fix --config=./etc/.golangci.yaml - test: $(BIN_OUTPUT_PATH)/video-store git lfs pull cp $(BIN_OUTPUT_PATH)/video-store bin/video-store diff --git a/cam/encoder.go b/cam/encoder.go index 0d645df..2699c00 100644 --- a/cam/encoder.go +++ b/cam/encoder.go @@ -49,7 +49,7 @@ func newEncoder( return nil, errors.New("failed to allocate codec context") } - enc.codecCtx.bit_rate = C.long(bitrate) + enc.codecCtx.bit_rate = C.int64_t(bitrate) enc.codecCtx.pix_fmt = C.AV_PIX_FMT_YUV422P enc.codecCtx.time_base = C.AVRational{num: 1, den: C.int(framerate)} enc.codecCtx.gop_size = C.int(framerate)