Skip to content

Commit e30b7d7

Browse files
MacduKhoraLeeshinra-electricsaturnsky
committed
FFMPEG setup
Contains the following squashed commits from the old branch: Initial commit Fix link order Add option to link against system ffmpeg, disable precompiled binaries for mingw Update macOS files for XCode 12 Update ffmpeg to 5.1.2 Add mjpeg encoder (#7) Add mjpeg2jpeg bitstream filter Add macOS-arm64 builds Add macOS arm64 to CMakeLists Add arm64-osx-release to build.yml dummy commit to trigger workflow Properly split macOS builds in build.yml Try to fix actions uploads Rename the builds Fix build.yml Fix typo in build.yml Amend CMakeLists using the correct check ci: change upload path to directly upload libraries ci: build and use universal binary on macOS ci: set macOS deployment target to macOS 11.0 ci: build FFMPEG prebuilt for each OS/architecture Add linux arm64 prebuilt. Add both x86_64 and arm64 prebuilts for macOS. ci: create release for pre-built FFMPEG cmake: download and use only necessary prebuilt FFMPEG Add arm64 windows prebuilt Co-authored-by: Seungyun Lee <[email protected]> Co-authored-by: shinra-electric <[email protected]> Co-authored-by: SaturnSky <[email protected]>
0 parents  commit e30b7d7

File tree

151 files changed

+35130
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+35130
-0
lines changed

.github/workflows/build.yml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: C/C++ CI
2+
3+
on: [push]
4+
5+
jobs:
6+
7+
build:
8+
name: ${{ matrix.build }} ${{ matrix.arch }}
9+
runs-on: ${{ matrix.os }}
10+
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
build: [linux, windows, macos]
15+
arch: [x64, arm64]
16+
include:
17+
- build: linux
18+
os: ubuntu-latest
19+
triplet: linux-release
20+
vcpkg-root: /usr/local/share/vcpkg
21+
extra-args: ""
22+
- build: windows
23+
os: windows-latest
24+
triplet: win-llvm-static-release
25+
vcpkg-root: C:\vcpkg
26+
extra-args: --overlay-triplets=./triplets
27+
- build: macos
28+
os: macos-latest
29+
triplet: osx-release
30+
vcpkg-root: /usr/local/share/vcpkg
31+
extra-args: ""
32+
- build: macos
33+
os: macos-latest
34+
arch: universal
35+
triplet: osx-release
36+
vcpkg-root: /usr/local/share/vcpkg
37+
extra-args: --overlay-triplets=./triplets
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- name: Set up build environment (macos-latest)
43+
run: |
44+
brew install nasm
45+
if: matrix.os == 'macos-latest'
46+
47+
- name: Set up build environment (ubuntu-latest)
48+
run: |
49+
sudo apt -y install nasm
50+
if: matrix.os == 'ubuntu-latest'
51+
52+
- name: Set up build environment (arm64 ubuntu-latest)
53+
run: |
54+
sudo apt-get install -qy binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
55+
if: matrix.os == 'ubuntu-latest' && matrix.arch == 'arm64'
56+
57+
- name: Patch vcpkg
58+
run: |
59+
(cd ${{ matrix.vcpkg-root }} && git fetch origin)
60+
(cd ${{ matrix.vcpkg-root }} && git reset --hard)
61+
(cd ${{ matrix.vcpkg-root }} && git checkout f6a5d4e8eb7476b8d7fc12a56dff300c1c986131)
62+
(cd ${{ matrix.vcpkg-root }} && git apply --ignore-space-change --ignore-whitespace --3way ${{ github.workspace }}/ffmpeg.patch)
63+
64+
- name: Build ffmpeg
65+
run: |
66+
vcpkg ${{ matrix.extra-args }} install ffmpeg[avcodec,avfilter,avdevice,avformat,swresample,swscale]:${{ matrix.arch }}-${{ matrix.triplet }}
67+
68+
- uses: actions/upload-artifact@v4
69+
with:
70+
name: ffmpeg-${{ matrix.build }}-${{ matrix.arch }}
71+
path: ${{ matrix.vcpkg-root }}/packages/ffmpeg_${{ matrix.arch }}-${{ matrix.triplet }}/lib
72+
if: ${{ always() }}
73+
74+
create-release:
75+
needs: [build]
76+
runs-on: "ubuntu-20.04"
77+
if: github.ref == 'refs/heads/master'
78+
permissions:
79+
contents: write
80+
81+
steps:
82+
- uses: actions/checkout@v4
83+
84+
- name: Download Artifacts
85+
uses: actions/download-artifact@v4
86+
87+
- name: Compute short git commit SHA
88+
run: |
89+
echo "COMMIT_SHORT_SHA=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
90+
echo ${{ env.COMMIT_SHORT_SHA }}
91+
92+
- name: Upload
93+
shell: bash
94+
run: |
95+
mkdir artifacts/
96+
files=$(find . -name "ffmpeg-*")
97+
for f in $files; do
98+
echo "Compressing $f"
99+
(cd $(basename $f) && zip -r ../artifacts/$(basename $f).zip *)
100+
done
101+
ls -al artifacts/
102+
wget -c https://github.com/tcnksm/ghr/releases/download/v0.14.0/ghr_v0.14.0_linux_amd64.tar.gz
103+
tar xfv ghr_v0.14.0_linux_amd64.tar.gz
104+
ghr_v0.14.0_linux_amd64/ghr -u Vita3K -r ffmpeg-core -n 'Automatic FFmpeg CI builds (${{ env.COMMIT_SHORT_SHA }})' -b "$(printf "Corresponding commit: ${{ github.sha }}")" ${{ env.COMMIT_SHORT_SHA }} artifacts/
105+
env:
106+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CMakeLists.txt

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
if (NOT DEFINED FFMPEG_CORE_NAME)
2+
set(FFMPEG_CORE_NAME ffmpeg)
3+
endif()
4+
5+
add_library(${FFMPEG_CORE_NAME} INTERFACE)
6+
7+
target_include_directories(${FFMPEG_CORE_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
8+
9+
# Detect OS
10+
if (WIN32 AND NOT MINGW)
11+
set(FFMPEG_PREBUILTS_NAME "ffmpeg-windows")
12+
elseif (APPLE)
13+
set(FFMPEG_PREBUILTS_NAME "ffmpeg-macos")
14+
elseif (UNIX)
15+
set(FFMPEG_PREBUILTS_NAME "ffmpeg-linux")
16+
else ()
17+
message(FATAL_ERROR "Unsupported OS.")
18+
endif ()
19+
20+
# Detect Architecture
21+
if(NOT DEFINED ARCHITECTURE)
22+
message(FATAL_ERROR "ARCHITECTURE variable is not set up")
23+
elseif (ARCHITECTURE STREQUAL "x86_64")
24+
set(FFMPEG_PREBUILTS_NAME "${FFMPEG_PREBUILTS_NAME}-x64.zip")
25+
elseif(ARCHITECTURE STREQUAL "arm64")
26+
set(FFMPEG_PREBUILTS_NAME "${FFMPEG_PREBUILTS_NAME}-arm64.zip")
27+
elseif(APPLE AND "x86_64" IN_LIST ARCHITECTURE AND "arm64" IN_LIST ARCHITECTURE) # macOS universal
28+
set(FFMPEG_PREBUILTS_NAME "${FFMPEG_PREBUILTS_NAME}-universal.zip")
29+
else ()
30+
message(FATAL_ERROR "Unsupported architecture.")
31+
endif()
32+
33+
# Compute current short git commit SHA
34+
execute_process(
35+
COMMAND git rev-parse --short HEAD
36+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
37+
OUTPUT_VARIABLE FFMPEG_GIT_SHA
38+
OUTPUT_STRIP_TRAILING_WHITESPACE)
39+
40+
# Download prebuilt ffmpeg
41+
if(NOT EXISTS "${CMAKE_BINARY_DIR}/external/ffmpeg.zip")
42+
message(STATUS "Downloading FFMPEG prebuilts...")
43+
file(DOWNLOAD https://github.com/Vita3K/ffmpeg-core/releases/download/${FFMPEG_GIT_SHA}/${FFMPEG_PREBUILTS_NAME}
44+
"${CMAKE_BINARY_DIR}/external/ffmpeg.zip" SHOW_PROGRESS
45+
STATUS FILE_STATUS)
46+
list(GET FILE_STATUS 0 STATUS_CODE)
47+
if (NOT STATUS_CODE EQUAL 0)
48+
file(REMOVE "${CMAKE_BINARY_DIR}/external/ffmpeg.zip") # CMake create 0 byte file even if URL is invalid. So need to delete it.
49+
message(FATAL_ERROR "No FFMPEG prebuilt found with corresponding commit SHA (${FFMPEG_GIT_SHA})")
50+
endif()
51+
endif()
52+
53+
if(NOT EXISTS "${CMAKE_BINARY_DIR}/external/ffmpeg/lib")
54+
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/external/ffmpeg/lib")
55+
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_BINARY_DIR}/external/ffmpeg.zip"
56+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external/ffmpeg/lib")
57+
endif()
58+
59+
set(LIB_PREFIX "lib")
60+
set(LIB_EXT "a")
61+
if (WIN32 AND NOT MINGW)
62+
set(LIB_PREFIX "")
63+
set(LIB_EXT "lib")
64+
target_link_libraries(${FFMPEG_CORE_NAME} INTERFACE
65+
"psapi;strmiids;uuid;oleaut32;shlwapi;ws2_32;ole32;user32;bcrypt")
66+
elseif (APPLE)
67+
target_link_libraries(${FFMPEG_CORE_NAME} INTERFACE
68+
"-framework CoreServices" "-framework CoreFoundation" "-framework AudioUnit"
69+
"-framework AudioToolbox" "-framework CoreAudio" "-framework CoreMedia"
70+
"-framework VideoToolbox" "-framework CoreVideo" "-framework Security")
71+
endif ()
72+
73+
target_link_libraries(${FFMPEG_CORE_NAME} INTERFACE
74+
"${CMAKE_BINARY_DIR}/external/ffmpeg/lib/${LIB_PREFIX}avformat.${LIB_EXT}"
75+
"${CMAKE_BINARY_DIR}/external/ffmpeg/lib/${LIB_PREFIX}avcodec.${LIB_EXT}"
76+
"${CMAKE_BINARY_DIR}/external/ffmpeg/lib/${LIB_PREFIX}swscale.${LIB_EXT}"
77+
"${CMAKE_BINARY_DIR}/external/ffmpeg/lib/${LIB_PREFIX}avutil.${LIB_EXT}"
78+
"${CMAKE_BINARY_DIR}/external/ffmpeg/lib/${LIB_PREFIX}avfilter.${LIB_EXT}"
79+
"${CMAKE_BINARY_DIR}/external/ffmpeg/lib/${LIB_PREFIX}swresample.${LIB_EXT}")

Readme.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## FFmpeg builtins
2+
3+
This repository contains the ffmpeg builtins for Vita3K and the CI to build them using vcpkg and github action.
4+
5+
The Windows version is built using clang-cl, this is done so that inline assembly optimisations (which are not supported by MSVC) can be enabled.

0 commit comments

Comments
 (0)