Skip to content

Commit 638f4f7

Browse files
authored
Merge pull request #3 from Prevter/main
small changes + setting up actions builds
2 parents 28420bc + ed8a89d commit 638f4f7

File tree

6 files changed

+60
-50
lines changed

6 files changed

+60
-50
lines changed

.github/workflows/multi-platform.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,34 @@ jobs:
1717

1818
- name: macOS
1919
os: macos-latest
20+
21+
# TODO: uncomment platforms when we own the libs for them
2022

21-
- name: Android32
22-
os: ubuntu-latest
23-
target: Android32
23+
#- name: Android32
24+
# os: ubuntu-latest
25+
# target: Android32
2426

25-
- name: Android64
26-
os: ubuntu-latest
27-
target: Android64
27+
#- name: Android64
28+
# os: ubuntu-latest
29+
# target: Android64
2830

2931
name: ${{ matrix.config.name }}
3032
runs-on: ${{ matrix.config.os }}
3133

3234
steps:
33-
- uses: actions/checkout@v4
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Own The Libs (Checkout)
39+
uses: actions/checkout@v4
40+
with:
41+
repository: EclipseMenu/ffmpeg-libs
42+
ref: ${{ matrix.config.name }}
43+
token: ${{ secrets.FFMPEG_LIBS_TOKEN }}
44+
path: ffmpeg-libs
45+
46+
- name: Own The Libs (Extract)
47+
run: 7z x ffmpeg-libs/lib/lib.7z -olib
3448

3549
- name: Build the mod
3650
uses: geode-sdk/build-geode-mod@main

CMakeLists.txt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(CMAKE_CXX_STANDARD 20)
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
55
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
67

78
if (MSVC)
89
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
@@ -17,7 +18,7 @@ add_library(${PROJECT_NAME} SHARED
1718
)
1819

1920
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Final>:Final>")
20-
21+
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
2122

2223
if (NOT DEFINED ENV{GEODE_SDK})
2324
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
@@ -46,14 +47,14 @@ if (WIN32)
4647
${CMAKE_SOURCE_DIR}/lib/aom.lib
4748
${CMAKE_SOURCE_DIR}/lib/vpx.lib
4849
${CMAKE_SOURCE_DIR}/lib/openh264.lib
49-
${CMAKE_SOURCE_DIR}/lib/ws2_32.lib
50-
${CMAKE_SOURCE_DIR}/lib/mfplat.lib
51-
${CMAKE_SOURCE_DIR}/lib/mf.lib
52-
${CMAKE_SOURCE_DIR}/lib/secur32.lib
53-
${CMAKE_SOURCE_DIR}/lib/crypt32.lib
54-
${CMAKE_SOURCE_DIR}/lib/mfuuid.lib
55-
${CMAKE_SOURCE_DIR}/lib/bcrypt.lib
56-
${CMAKE_SOURCE_DIR}/lib/strmiids.lib
50+
ws2_32.lib
51+
mfplat.lib
52+
mf.lib
53+
secur32.lib
54+
crypt32.lib
55+
mfuuid.lib
56+
bcrypt.lib
57+
strmiids.lib
5758
) # windows
5859
elseif (ANDROID)
5960
if (ANDROID_ABI STREQUAL "arm64-v8a")
@@ -94,18 +95,13 @@ else ()
9495
${CMAKE_SOURCE_DIR}/lib/libavformat.a
9596
${CMAKE_SOURCE_DIR}/lib/libavutil.a
9697
${CMAKE_SOURCE_DIR}/lib/libavfilter.a
98+
${CMAKE_SOURCE_DIR}/lib/libpostproc.a
9799
${CMAKE_SOURCE_DIR}/lib/libswresample.a
98-
${CMAKE_SOURCE_DIR}/lib/libswscale.a
100+
${CMAKE_SOURCE_DIR}/lib/libswscale.a
101+
${CMAKE_SOURCE_DIR}/lib/liblzma.a
99102
${BZIP2_LIBRARY}
100103
"-lm -lbz2 -lz -liconv -pthread -framework Security -framework VideoToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices -framework CoreAudio -framework AVFoundation -framework CoreGraphics -framework AudioToolbox -framework Metal -framework CoreImage -framework AppKit"
101104
) # macos
102-
103-
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
104-
set(STATIC_LIBS
105-
${STATIC_LIBS}
106-
${CMAKE_SOURCE_DIR}/lib/liblzma.a
107-
)
108-
endif()
109105
endif()
110106
target_link_libraries(${PROJECT_NAME} ${STATIC_LIBS})
111107

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void audioRaw() {
5959
### Windows
6060
To get the needed libraries on Windows, you can use vcpkg:
6161
```sh
62-
vcpkg install ffmpeg[core,avcodec,avformat,swscale,swresample,amf,x264,x265,nvcodec,openh264,aom,vpx]:x64-windows-static --recurse
62+
vcpkg install ffmpeg[core,avcodec,avformat,avfilter,swscale,swresample,amf,x264,x265,nvcodec,openh264,aom,vpx]:x64-windows-static --recurse
6363
```
6464
the other libraries are part of the Windows SDK
6565

mod.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"geode": "4.0.0",
33
"gd": {
4-
"win": "2.2074",
5-
"android": "2.2074",
6-
"mac": "2.2074",
7-
"ios": "2.2074"
4+
"win": "*",
5+
"android": "*",
6+
"mac": "*",
7+
"ios": "*"
88
},
99
"api": {
1010
"include": [
@@ -13,7 +13,7 @@
1313
},
1414
"id": "eclipse.ffmpeg-api",
1515
"name": "FFmpeg API",
16-
"version": "v1.0.4",
16+
"version": "v1.1.0",
1717
"developers": ["Eclipse Team", "maxnu"],
1818
"description": "Interaction with FFmpeg made easy",
1919
"tags": ["utility", "offline", "developer"],

src/audio_mixer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "audio_mixer.hpp"
22

33
#include <iostream>
4+
#include <utility>
45

56
extern "C" {
67
#include <libavcodec/avcodec.h>
@@ -87,15 +88,14 @@ std::vector<float> readAudioFile(const char *filename, int targetSampleRate, AVS
8788
std::vector<float> audioFrames;
8889

8990
float *convertBuffer[2];
90-
convertBuffer[0] = (float *)av_malloc(4096 * sizeof(float));
91-
convertBuffer[1] = (float *)av_malloc(4096 * sizeof(float));
91+
convertBuffer[0] = static_cast<float *>(av_malloc(4096 * sizeof(float)));
92+
convertBuffer[1] = static_cast<float *>(av_malloc(4096 * sizeof(float)));
9293

9394
while (av_read_frame(formatContext, &packet) >= 0) {
9495
if (packet.stream_index == audioStreamIndex && avcodec_send_packet(codecContext, &packet) == 0) {
9596
while (avcodec_receive_frame(codecContext, frame) == 0) {
96-
int ret = swr_convert(swr, (uint8_t **)convertBuffer, 4096,
97-
(const uint8_t **)frame->data,
98-
frame->nb_samples);
97+
int ret = swr_convert(swr, reinterpret_cast<uint8_t **>(convertBuffer), 4096,
98+
frame->data, frame->nb_samples);
9999
if (ret < 0) {
100100
char errbuf[AV_ERROR_MAX_STRING_SIZE];
101101
av_strerror(ret, errbuf, AV_ERROR_MAX_STRING_SIZE);
@@ -125,7 +125,7 @@ std::vector<float> readAudioFile(const char *filename, int targetSampleRate, AVS
125125

126126
namespace ffmpeg {
127127
void AudioMixer::mixVideoAudio(std::filesystem::path videoFile, std::filesystem::path audioFile, std::filesystem::path outputMp4File) {
128-
const int frameSize = 1024;
128+
constexpr int frameSize = 1024;
129129

130130
AVFormatContext* wavFormatContext = nullptr;
131131
if (avformat_open_input(&wavFormatContext, audioFile.string().c_str(), nullptr, nullptr) < 0) {
@@ -137,7 +137,7 @@ namespace ffmpeg {
137137

138138
std::vector<float> raw = readAudioFile(audioFile.string().c_str(), 44100, AV_SAMPLE_FMT_FLTP, &inputAudioParams);
139139

140-
mixVideoRaw(videoFile, raw, outputMp4File, inputAudioParams.sample_rate);
140+
mixVideoRaw(std::move(videoFile), raw, std::move(outputMp4File), inputAudioParams.sample_rate);
141141

142142
avformat_close_input(&wavFormatContext);
143143
}
@@ -182,8 +182,8 @@ namespace ffmpeg {
182182
geode::log::error("Failed to create audio stream.");
183183
return;
184184
}
185-
186-
const int channels = 2;
185+
186+
constexpr int channels = 2;
187187

188188
outputAudioStream->codecpar->codec_tag = 0;
189189
outputAudioStream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -211,7 +211,7 @@ namespace ffmpeg {
211211
audio_codec_context_encoder->sample_rate = sampleRate;
212212
audio_codec_context_encoder->ch_layout = AV_CHANNEL_LAYOUT_STEREO;
213213
audio_codec_context_encoder->sample_fmt = AV_SAMPLE_FMT_FLTP;
214-
audio_codec_context_encoder->time_base = AVRational{1, (int)sampleRate};
214+
audio_codec_context_encoder->time_base = AVRational{1, static_cast<int>(sampleRate)};
215215

216216
int ret = avcodec_open2(audio_codec_context_encoder, audioCodec, nullptr);
217217
if (ret < 0) {
@@ -289,7 +289,7 @@ namespace ffmpeg {
289289

290290
AVPacket audioPacket;
291291
av_init_packet(&audioPacket);
292-
audioPacket.data = NULL;
292+
audioPacket.data = nullptr;
293293
audioPacket.size = 0;
294294

295295
while (true) {

src/recorder.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ std::vector<std::string> Recorder::getAvailableCodecs() {
2424
while ((codec = av_codec_iterate(&iter))) {
2525
if(codec->type == AVMEDIA_TYPE_VIDEO &&
2626
(codec->id == AV_CODEC_ID_H264 || codec->id == AV_CODEC_ID_HEVC || codec->id == AV_CODEC_ID_VP8 || codec->id == AV_CODEC_ID_VP9 || codec->id == AV_CODEC_ID_AV1 || codec->id == AV_CODEC_ID_MPEG4) &&
27-
avcodec_find_encoder_by_name(codec->name) != nullptr && codec->pix_fmts && std::find(vec.begin(), vec.end(), std::string(codec->name)) == vec.end())
28-
vec.push_back(codec->name);
27+
avcodec_find_encoder_by_name(codec->name) != nullptr && codec->pix_fmts && std::ranges::find(vec, std::string(codec->name)) == vec.end())
28+
vec.emplace_back(codec->name);
2929
}
3030

3131
return vec;
@@ -76,14 +76,14 @@ bool Recorder::init(const RenderSettings& settings) {
7676
m_codecContext->bit_rate = settings.m_bitrate;
7777
m_codecContext->width = settings.m_width;
7878
m_codecContext->height = settings.m_height;
79-
m_codecContext->time_base = AVRational(1, settings.m_fps);
79+
m_codecContext->time_base = AVRational{1, settings.m_fps};
8080
m_codecContext->pix_fmt = AV_PIX_FMT_NONE;
8181
m_videoStream->time_base = m_codecContext->time_base;
8282

8383
const AVPixelFormat *pix_fmt = m_codec->pix_fmts;
8484
if (pix_fmt) {
8585
while (*pix_fmt != AV_PIX_FMT_NONE) {
86-
if(*pix_fmt == (AVPixelFormat)settings.m_pixelFormat)
86+
if(*pix_fmt == static_cast<AVPixelFormat>(settings.m_pixelFormat))
8787
m_codecContext->pix_fmt = *pix_fmt;
8888
++pix_fmt;
8989
}
@@ -96,7 +96,7 @@ bool Recorder::init(const RenderSettings& settings) {
9696
else
9797
geode::log::info("Codec {} supports pixel format.", settings.m_codec);
9898

99-
if (avcodec_open2(m_codecContext, m_codec, NULL) < 0) {
99+
if (avcodec_open2(m_codecContext, m_codec, nullptr) < 0) {
100100
geode::log::error("Could not open codec.");
101101
return false;
102102
}
@@ -114,7 +114,7 @@ bool Recorder::init(const RenderSettings& settings) {
114114
return false;
115115
}
116116

117-
if (avformat_write_header(m_formatContext, NULL) < 0) {
117+
if (avformat_write_header(m_formatContext, nullptr) < 0) {
118118
geode::log::error("Could not write header.");
119119
return false;
120120
}
@@ -243,7 +243,7 @@ bool Recorder::writeFrame(const std::vector<uint8_t>& frameData) {
243243
ret = avcodec_receive_packet(m_codecContext, m_packet);
244244
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
245245
break;
246-
else if (ret < 0)
246+
if (ret < 0)
247247
return false;
248248

249249
av_packet_rescale_ts(m_packet, m_codecContext->time_base, m_videoStream->time_base);
@@ -272,7 +272,7 @@ void Recorder::stop() {
272272

273273
m_init = false;
274274

275-
avcodec_send_frame(m_codecContext, NULL);
275+
avcodec_send_frame(m_codecContext, nullptr);
276276
while (avcodec_receive_packet(m_codecContext, m_packet) == 0) {
277277
av_packet_rescale_ts(m_packet, m_codecContext->time_base, m_videoStream->time_base);
278278
m_packet->stream_index = m_videoStream->index;
@@ -298,4 +298,4 @@ void Recorder::stop() {
298298
delete m_packet;
299299
}
300300

301-
}
301+
}

0 commit comments

Comments
 (0)