Skip to content

Commit db79ec8

Browse files
committed
Merge in option to build ffmpeg and x265 from main
Now I don't have to maintain two branches all the time
1 parent fc9495c commit db79ec8

File tree

5 files changed

+98
-23
lines changed

5 files changed

+98
-23
lines changed

build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
ENABLE_FFPLAY=FALSE
55
ENABLE_TOPAZ=FALSE
66
ENABLE_AVISYNTHPLUS=FALSE
7+
BUILD_FROM_MAIN=FALSE
8+
79

810
# set true for dependant features, export those needed in ffmpeg build script
911

@@ -23,6 +25,7 @@ then
2325
echo
2426
echo If you have logged out of your Topaz account you can log in using
2527
echo out/bin/login topaz_account_email_address topaz_account_password
28+
echo
2629

2730
fi
2831

@@ -36,6 +39,17 @@ then
3639
export ENABLE_AVISYNTHPLUS=TRUE
3740
echo "Enabling AviSynthPlus will meaan this binary is not longer staticly built."
3841
echo "To use AviSynthPlus you will need to run from the tool/lib directory or a directory with a link to the tool/lib/libavisynth.dylib file"
42+
echo
43+
fi
44+
45+
if [[ "${BUILD_FROM_MAIN}" == "TRUE" ]]
46+
then
47+
export BUILD_FROM_MAIN=TRUE
48+
echo "Enabling Build from main."
49+
echo "This will build ffmpeg and x265 from their respective source repositories."
50+
echo "This may break things, or have unexpected effects, but x265 will be a little more performant"
51+
echo "and no longer require that huge patch as the code has been incorporated and further enhancements made."
52+
echo
3953
fi
4054

4155
# get rid of macports - libiconv

build/build-aom.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ download_code () {
2828
cd "$2/${SOFTWARE}"
2929
checkStatus $? "change directory failed"
3030
# download source
31-
git clone --depth=1 https://aomedia.googlesource.com/aom
31+
git clone https://aomedia.googlesource.com/aom
32+
3233
checkStatus $? "download of ${SOFTWARE} failed"
3334

3435
}

build/build-ffmpeg.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# load functions
1010
. $1/functions.sh
11-
11+
set -x
1212
SOFTWARE=ffmpeg
1313

1414
make_directories() {
@@ -28,20 +28,32 @@ download_code () {
2828
cd "$2/${SOFTWARE}"
2929
checkStatus $? "change directory failed"
3030
# download source
31-
curl -O https://ffmpeg.org/releases/ffmpeg-$6.tar.bz2
32-
checkStatus $? "download of ${SOFTWARE} failed"
3331

34-
# unpack ffmpeg
35-
bunzip2 ffmpeg-$6.tar.bz2
36-
tar -xf ffmpeg-$6.tar
37-
cd "ffmpeg-$6/"
38-
checkStatus $? "change directory failed"
32+
33+
if [[ "${BUILD_FROM_MAIN}" == "TRUE" ]]
34+
then
35+
git clone https://git.ffmpeg.org/ffmpeg.git
36+
cd ffmpeg
37+
checkStatus $? "change directory failed"
38+
export FFMPEG_DIR="ffmpeg"
39+
40+
else
41+
curl -O https://ffmpeg.org/releases/ffmpeg-$6.tar.bz2
42+
checkStatus $? "download of ${SOFTWARE} failed"
43+
44+
# unpack ffmpeg
45+
bunzip2 ffmpeg-$6.tar.bz2
46+
tar -xf ffmpeg-$6.tar
47+
cd "ffmpeg-$6/"
48+
checkStatus $? "change directory failed"
49+
export FFMPEG_DIR="ffmpeg-$6"
50+
fi
3951

4052
}
4153

4254
configure_build () {
4355

44-
cd "$2/${SOFTWARE}/ffmpeg-$6/"
56+
cd "$2/${SOFTWARE}/${FFMPEG_DIR}/"
4557
checkStatus $? "change directory failed"
4658

4759
# prepare build
@@ -67,15 +79,16 @@ configure_build () {
6779
--enable-libaom --enable-libopenh264 --enable-libx264 --enable-libx265 --enable-libvpx \
6880
--enable-libmp3lame --enable-libopus --enable-neon --enable-runtime-cpudetect \
6981
--enable-audiotoolbox --enable-videotoolbox --enable-libvorbis --enable-libsvtav1 \
70-
--enable-libass --enable-lto --enable-nonfree --enable-libfdk-aac --enable-opencl ${FFMPEG_EXTRAS}
82+
--enable-libass --enable-nonfree --enable-libfdk-aac --enable-opencl ${FFMPEG_EXTRAS}
83+
# --enable-libass --enable-lto --enable-nonfree --enable-libfdk-aac --enable-opencl ${FFMPEG_EXTRAS}
7184

7285
checkStatus $? "configuration of ${SOFTWARE} failed"
7386

7487
}
7588

7689
make_clean() {
7790

78-
cd "$2/${SOFTWARE}/ffmpeg-$6/"
91+
cd "$2/${SOFTWARE}/${FFMPEG_DIR}/"
7992
checkStatus $? "change directory failed"
8093
make clean
8194
checkStatus $? "make clean for $SOFTWARE failed"
@@ -85,7 +98,7 @@ make_clean() {
8598

8699
make_compile () {
87100

88-
cd "$2/${SOFTWARE}/ffmpeg-$6/"
101+
cd "$2/${SOFTWARE}/${FFMPEG_DIR}/"
89102
checkStatus $? "change directory failed"
90103

91104
# build

build/build-x265.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
# $4 = CPUs
66
# $5 = x265 version
77

8-
set -x
8+
set -x
99
# load functions
1010
. $1/functions.sh
1111

12+
if [[ "${BUILD_FROM_MAIN}" == "TRUE" ]]
13+
then
14+
BRANCH=""
15+
PATCH="git apply $1/x265_arm64_threading.patch"
16+
else
17+
BRANCH="--branch stable"
18+
PATCH="patch -p1 -i $1/apple_arm64_x265.patch"
19+
fi
1220

1321
make_directories() {
1422

@@ -39,7 +47,7 @@ download_code() {
3947

4048
# Build fails when using git shallow clone
4149
# https://bitbucket.org/multicoreware/x265_git/issues/572/pc-file-is-not-generated
42-
git clone https://bitbucket.org/multicoreware/x265_git.git --branch stable
50+
git clone https://bitbucket.org/multicoreware/x265_git.git ${BRANCH}
4351
checkStatus $? "download of x265 failed"
4452

4553
# TODO: checksum validation (if available)
@@ -58,12 +66,15 @@ configure_build () {
5866

5967

6068
#patch for arm64 / neon recognition
61-
patch -p1 < $1/apple_arm64_x265.patch
69+
#patch -p1 < $1/apple_arm64_x265.patch
70+
${PATCH}
71+
6272

6373
cd ../12bit
6474

6575
# prepare build
6676

77+
FF
6778
cmake -DCMAKE_INSTALL_PREFIX:PATH=$3 -DENABLE_SHARED=NO -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_CLI=OFF -DMAIN12=ON ../$GIT_DIR/source
6879
checkStatus $? "configuration of 12bit x265 failed"
6980

@@ -78,7 +89,7 @@ configure_build () {
7889

7990
# prepare build
8091

81-
cmake -DCMAKE_INSTALL_PREFIX:PATH=$3 -DENABLE_SHARED=NO -DEXTRA_LIB="x265_main10.a;x265_main12.a" -DEXTRA_LINK_FLAGS=-L. -DLINKED_10BIT=ON -DLINKED_12BIT=ON -DENABLE_CLI=NO ../$GIT_DIR/source
92+
cmake -DCMAKE_INSTALL_PREFIX:PATH=$3 -DENABLE_SHARED=NO -DEXTRA_LIB="x265_main10.a;x265_main12.a" -DEXTRA_LINK_FLAGS=-L. -DLINKED_10BIT=ON -DLINKED_12BIT=ON -DENABLE_CLI=OFF ../$GIT_DIR/source
8293
checkStatus $? "configuration of 8bit x265 failed"
8394

8495
}
@@ -125,14 +136,15 @@ make_compile () {
125136
cd "$2/x265/8bit"
126137
checkStatus $? "change directory failed"
127138

139+
#soft symlink the libraies
140+
ln -sf ../10bit/libx265.a libx265_main10.a
141+
ln -sf ../12bit/libx265.a libx265_main12.a
142+
128143
# build
129144
make -j $4
130145
checkStatus $? "build of x265 failed"
131146

132147
#merge the libaries together
133-
ln -sf ../10bit/libx265.a libx265_main10.a
134-
ln -sf ../12bit/libx265.a libx265_main12.a
135-
136148
mv libx265.a libx265_main.a
137149
libtool -static -o libx265.a libx265_main.a libx265_main10.a libx265_main12.a 2>/dev/null
138150
checkStatus $? "merge of x265 objects failed"
@@ -141,9 +153,6 @@ make_compile () {
141153
make install
142154
checkStatus $? "installation of x265 failed"
143155

144-
# post-installation
145-
# modify pkg-config file for usage with ffmpeg (it seems that the flag for threads is missing)
146-
sed -i.original -e 's/lx265/lx265 -lpthread/g' $3/lib/pkgconfig/x265.pc
147156

148157
}
149158

@@ -174,3 +183,4 @@ build_main () {
174183

175184

176185
build_main $@
186+

build/x265_arm64_threading.patch

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
diff --git a/source/common/threadpool.cpp b/source/common/threadpool.cpp
2+
index 91e82a24e..e21ae9cd6 100644
3+
--- a/source/common/threadpool.cpp
4+
+++ b/source/common/threadpool.cpp
5+
@@ -115,12 +115,6 @@ void WorkerThread::threadMain()
6+
{
7+
THREAD_NAME("Worker", m_id);
8+
9+
-#if _WIN32
10+
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
11+
-#else
12+
- __attribute__((unused)) int val = nice(10);
13+
-#endif
14+
-
15+
m_pool.setCurrentThreadAffinity();
16+
17+
sleepbitmap_t idBit = (sleepbitmap_t)1 << m_id;
18+
@@ -667,9 +661,17 @@ void ThreadPool::getFrameThreadsCount(x265_param* p, int cpuCount)
19+
else if (cpuCount >= 32)
20+
p->frameNumThreads = (p->sourceHeight > 2000) ? 6 : 5;
21+
else if (cpuCount >= 16)
22+
- p->frameNumThreads = 4;
23+
+#if MACOS && X265_ARCH_ARM64
24+
+ p->frameNumThreads = 16;
25+
+#else
26+
+ p->frameNumThreads = 4;
27+
+#endif
28+
else if (cpuCount >= 8)
29+
- p->frameNumThreads = 3;
30+
+#if MACOS && X265_ARCH_ARM64
31+
+ p->frameNumThreads = 8;
32+
+#else
33+
+ p->frameNumThreads = 3;
34+
+#endif
35+
else if (cpuCount >= 4)
36+
p->frameNumThreads = 2;
37+
else

0 commit comments

Comments
 (0)