Skip to content

Commit

Permalink
[RSDK-8764] - Add Darwin support (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
seanavery authored Sep 19, 2024
1 parent 38923e6 commit fcadade
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 3 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,17 +50,25 @@ 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)

$(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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cam/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fcadade

Please sign in to comment.