Skip to content

Commit

Permalink
Adding FFmpeg recompile option
Browse files Browse the repository at this point in the history
Helpful for GitHub workflows but also for compiling debug and release in
a row
  • Loading branch information
voylin committed Aug 8, 2024
1 parent 1b32186 commit f823801
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 42 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/build_gdextension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
path: bin/linux_video_only/template_debug/*
- name: Build Linux Release
run: scons -Q -j4 target=template_release platform=linux arch=x86_64 use_system=yes
# TODO: Need to probably clean out the debug executable before uploading release artifacts
- name: Uploading GDExtension artifact
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -69,8 +68,7 @@ jobs:
name: gdextension-linux-full-build
path: bin/linux_video_only_full/template_debug/*
- name: Build Linux full Release
run: scons -Q -j4 target=template_release platform=linux arch=x86_64 use_system=no enable_gpl=yes
# TODO: Need to probably clean out the debug executable before uploading release artifacts
run: scons -Q -j4 target=template_release platform=linux arch=x86_64 use_system=no enable_gpl=yes recompile_ffmpeg=no
- name: Uploading GDExtension artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -91,16 +89,15 @@ jobs:
run: pip install scons
- name: Install Yasm
run: sudo apt-get update && sudo apt-get install -y yasm
- name: Build Linux Debug
- name: Build Windows Debug
run: scons -Q -j4 target=template_debug platform=linux arch=x86_64 use_system=no enable_gpl=yes
- name: Uploading GDExtension artifact
uses: actions/upload-artifact@v4
with:
name: gdextension-windows-build
path: bin/windows/template_debug/*
- name: Build Linux Release
run: scons -Q -j4 target=template_release platform=linux arch=x86_64 use_system=no enable_gpl=yes
# TODO: Need to probably clean out the debug executable before uploading release artifacts
- name: Build Windows Release
run: scons -Q -j4 target=template_release platform=linux arch=x86_64 use_system=no enable_gpl=yes recompile_ffmpeg=no
- name: Uploading GDExtension artifact
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions COMPILE_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ Using the command line is pretty straightforward. Use `scons` with any of the st

`include_renderer=` with `yes`, the rendering class will get included. If you don't need rendering capabilities, you could use set this to `no`. Default is `no`.

### Recompile FFmpeg

`recompile_ffmpeg=` is set to yes by default, but when making consequential builds, you probably don't need this to happen so for the second run of the same OS you could set this to `no`. This is helpful when building the template_debug and template_release directly after each other.

64 changes: 32 additions & 32 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,48 @@ if 'linux' in platform:
'ffmpeg/bin/include/libswscale',
'ffmpeg/bin/include/libswresample'])
env.Append(LIBPATH=['ffmpeg/bin/lib'])

if ARGUMENTS.get('recompile_ffmpeg', 'yes') == 'yes':
os.chdir('ffmpeg')
os.system('make distclean')
time.sleep(5)
# These may be needed when running into trouble compiling
# --extra-cflags="-fPIC" --extra-ldflags="-fpic" --target-os=linux')
os.system(f'./configure --prefix={folder_bin} {ffmpeg_build_args} --target-os=linux')
time.sleep(5)

os.system(f'make -j {num_jobs}')
os.system(f'make -j {num_jobs} install')
os.chdir('..')

os.makedirs(f'{folder_bin}/{platform}/{target}', exist_ok=True)
os.system(f'cp ffmpeg/bin/lib/*.so* {folder_bin}/{platform}/{target}')
elif 'windows' in platform:
# Building FFmpeg
if ARGUMENTS.get('recompile_ffmpeg', 'yes') == 'yes':
extra_args = ''
if os_platform.system().lower() == 'linux':
extra_args = '--cross-prefix=x86_64-w64-mingw32- --target-os=mingw32 --enable-cross-compile'

# TEST: Testing if adding this makes it so copying files is no longer needed
extra_args += ' --extra-ldflags="-static"'
# Copying necessary files
# os.system(f'cp /usr/x86_64-w64-mingw32/bin/libwinpthread-1.dll {folder_bin}/{platform}/')
# os.system(f'cp /usr/x86_64-w64-mingw32/bin/libstdc++-6.dll {folder_bin}/{platform}/')
else:
extra_args = ' --target-os=windows'

os.chdir('ffmpeg')
os.environ['PATH'] = '/opt/bin:' + os.environ['PATH']

os.system('make distclean')
time.sleep(5)
# These may be needed when running into trouble compiling
# --extra-cflags="-fPIC" --extra-ldflags="-fpic" --target-os=linux')
os.system(f'./configure --prefix={folder_bin} {ffmpeg_build_args} --target-os=linux')
os.system(f'./configure --prefix={folder_bin} {ffmpeg_build_args} {extra_args}')
time.sleep(5)

os.system(f'make -j {num_jobs}')
os.system(f'make -j {num_jobs} install')
os.chdir('..')

os.makedirs(f'{folder_bin}/{platform}/{target}', exist_ok=True)
os.system(f'cp ffmpeg/bin/lib/*.so* {folder_bin}/{platform}/{target}')
elif 'windows' in platform:
# Building FFmpeg
extra_args = ''
if os_platform.system().lower() == 'linux':
os.environ['PATH'] = '/opt/bin/' + os.environ['PATH']
extra_args = '--cross-prefix=x86_64-w64-mingw32- --target-os=mingw32 --enable-cross-compile'

# TEST: Testing if adding this makes it so copying files is no longer needed
extra_args += ' --extra-ldflags="-static"'
# Copying necessary files
# os.system(f'cp /usr/x86_64-w64-mingw32/bin/libwinpthread-1.dll {folder_bin}/{platform}/')
# os.system(f'cp /usr/x86_64-w64-mingw32/bin/libstdc++-6.dll {folder_bin}/{platform}/')
else:
extra_args = ' --target-os=windows'

os.chdir('ffmpeg')
os.environ['PATH'] = '/opt/bin:' + os.environ['PATH']

os.system('make distclean')
time.sleep(5)
os.system(f'./configure --prefix={folder_bin} {ffmpeg_build_args} {extra_args}')
time.sleep(5)
os.system(f'make -j {num_jobs}')
os.system(f'make -j {num_jobs} install')
os.chdir('..')

if os_platform.system().lower() == 'windows':
env.Append(LIBS=[
'avcodec.lib',
Expand Down
11 changes: 10 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@
case '2': target = 'release'

extra_args = ''
use_system = False
if platform == 'linux':
print('Use system FFmpeg:')
print('1. Yes; (default)')
print('2. No.')
match input('> '):
case '2': extra_args = 'use_system=no'
case _: extra_args = 'use_system=yes'
case _:
extra_args = 'use_system=yes'
use_system = True

print('Enable GPL:')
print('1. no; (default)')
Expand All @@ -71,6 +74,12 @@
match input('> '):
case '2.': ' include_renderer=yes'

if use_system:
print('Recompile FFmpeg:')
print('1. Yes; (default)')
print('2. No.')
match input('> '):
case '2.': ' recompile_ffmpeg=no'
user_input = input('Number of threads/cores for compiling> ')
if user_input.isdigit():
jobs = int(user_input)
Expand Down
4 changes: 2 additions & 2 deletions compile_builds.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

scons -j10 target=template_debug platform=linux arch=x86_64 use_system=yes
scons -j10 target=template_debug platform=linux arch=x86_64 use_system=no enable_gpl=yes
scons -j10 target=template_debug platform=windows arch=x86_64 use_system=no enable_gpl=yes
scons -j10 target=template_debug platform=linux arch=x86_64 use_system=no enable_gpl=yes recompile_ffmpeg=yes
scons -j10 target=template_debug platform=windows arch=x86_64 use_system=no enable_gpl=yes recompile_ffmpeg=yes

0 comments on commit f823801

Please sign in to comment.