Skip to content

Commit

Permalink
Merge pull request #3 from Prevter/main
Browse files Browse the repository at this point in the history
small changes + setting up actions builds
  • Loading branch information
maxnut authored Nov 19, 2024
2 parents 28420bc + ed8a89d commit 638f4f7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 50 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,34 @@ jobs:

- name: macOS
os: macos-latest

# TODO: uncomment platforms when we own the libs for them

- name: Android32
os: ubuntu-latest
target: Android32
#- name: Android32
# os: ubuntu-latest
# target: Android32

- name: Android64
os: ubuntu-latest
target: Android64
#- name: Android64
# os: ubuntu-latest
# target: Android64

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

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Own The Libs (Checkout)
uses: actions/checkout@v4
with:
repository: EclipseMenu/ffmpeg-libs
ref: ${{ matrix.config.name }}
token: ${{ secrets.FFMPEG_LIBS_TOKEN }}
path: ffmpeg-libs

- name: Own The Libs (Extract)
run: 7z x ffmpeg-libs/lib/lib.7z -olib

- name: Build the mod
uses: geode-sdk/build-geode-mod@main
Expand Down
30 changes: 13 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)

if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
Expand All @@ -17,7 +18,7 @@ add_library(${PROJECT_NAME} SHARED
)

set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Final>:Final>")

set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)

if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
Expand Down Expand Up @@ -46,14 +47,14 @@ if (WIN32)
${CMAKE_SOURCE_DIR}/lib/aom.lib
${CMAKE_SOURCE_DIR}/lib/vpx.lib
${CMAKE_SOURCE_DIR}/lib/openh264.lib
${CMAKE_SOURCE_DIR}/lib/ws2_32.lib
${CMAKE_SOURCE_DIR}/lib/mfplat.lib
${CMAKE_SOURCE_DIR}/lib/mf.lib
${CMAKE_SOURCE_DIR}/lib/secur32.lib
${CMAKE_SOURCE_DIR}/lib/crypt32.lib
${CMAKE_SOURCE_DIR}/lib/mfuuid.lib
${CMAKE_SOURCE_DIR}/lib/bcrypt.lib
${CMAKE_SOURCE_DIR}/lib/strmiids.lib
ws2_32.lib
mfplat.lib
mf.lib
secur32.lib
crypt32.lib
mfuuid.lib
bcrypt.lib
strmiids.lib
) # windows
elseif (ANDROID)
if (ANDROID_ABI STREQUAL "arm64-v8a")
Expand Down Expand Up @@ -94,18 +95,13 @@ else ()
${CMAKE_SOURCE_DIR}/lib/libavformat.a
${CMAKE_SOURCE_DIR}/lib/libavutil.a
${CMAKE_SOURCE_DIR}/lib/libavfilter.a
${CMAKE_SOURCE_DIR}/lib/libpostproc.a
${CMAKE_SOURCE_DIR}/lib/libswresample.a
${CMAKE_SOURCE_DIR}/lib/libswscale.a
${CMAKE_SOURCE_DIR}/lib/libswscale.a
${CMAKE_SOURCE_DIR}/lib/liblzma.a
${BZIP2_LIBRARY}
"-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"
) # macos

if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(STATIC_LIBS
${STATIC_LIBS}
${CMAKE_SOURCE_DIR}/lib/liblzma.a
)
endif()
endif()
target_link_libraries(${PROJECT_NAME} ${STATIC_LIBS})

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void audioRaw() {
### Windows
To get the needed libraries on Windows, you can use vcpkg:
```sh
vcpkg install ffmpeg[core,avcodec,avformat,swscale,swresample,amf,x264,x265,nvcodec,openh264,aom,vpx]:x64-windows-static --recurse
vcpkg install ffmpeg[core,avcodec,avformat,avfilter,swscale,swresample,amf,x264,x265,nvcodec,openh264,aom,vpx]:x64-windows-static --recurse
```
the other libraries are part of the Windows SDK

Expand Down
10 changes: 5 additions & 5 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"geode": "4.0.0",
"gd": {
"win": "2.2074",
"android": "2.2074",
"mac": "2.2074",
"ios": "2.2074"
"win": "*",
"android": "*",
"mac": "*",
"ios": "*"
},
"api": {
"include": [
Expand All @@ -13,7 +13,7 @@
},
"id": "eclipse.ffmpeg-api",
"name": "FFmpeg API",
"version": "v1.0.4",
"version": "v1.1.0",
"developers": ["Eclipse Team", "maxnu"],
"description": "Interaction with FFmpeg made easy",
"tags": ["utility", "offline", "developer"],
Expand Down
22 changes: 11 additions & 11 deletions src/audio_mixer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "audio_mixer.hpp"

#include <iostream>
#include <utility>

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

float *convertBuffer[2];
convertBuffer[0] = (float *)av_malloc(4096 * sizeof(float));
convertBuffer[1] = (float *)av_malloc(4096 * sizeof(float));
convertBuffer[0] = static_cast<float *>(av_malloc(4096 * sizeof(float)));
convertBuffer[1] = static_cast<float *>(av_malloc(4096 * sizeof(float)));

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

namespace ffmpeg {
void AudioMixer::mixVideoAudio(std::filesystem::path videoFile, std::filesystem::path audioFile, std::filesystem::path outputMp4File) {
const int frameSize = 1024;
constexpr int frameSize = 1024;

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

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

mixVideoRaw(videoFile, raw, outputMp4File, inputAudioParams.sample_rate);
mixVideoRaw(std::move(videoFile), raw, std::move(outputMp4File), inputAudioParams.sample_rate);

avformat_close_input(&wavFormatContext);
}
Expand Down Expand Up @@ -182,8 +182,8 @@ namespace ffmpeg {
geode::log::error("Failed to create audio stream.");
return;
}
const int channels = 2;

constexpr int channels = 2;

outputAudioStream->codecpar->codec_tag = 0;
outputAudioStream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
Expand Down Expand Up @@ -211,7 +211,7 @@ namespace ffmpeg {
audio_codec_context_encoder->sample_rate = sampleRate;
audio_codec_context_encoder->ch_layout = AV_CHANNEL_LAYOUT_STEREO;
audio_codec_context_encoder->sample_fmt = AV_SAMPLE_FMT_FLTP;
audio_codec_context_encoder->time_base = AVRational{1, (int)sampleRate};
audio_codec_context_encoder->time_base = AVRational{1, static_cast<int>(sampleRate)};

int ret = avcodec_open2(audio_codec_context_encoder, audioCodec, nullptr);
if (ret < 0) {
Expand Down Expand Up @@ -289,7 +289,7 @@ namespace ffmpeg {

AVPacket audioPacket;
av_init_packet(&audioPacket);
audioPacket.data = NULL;
audioPacket.data = nullptr;
audioPacket.size = 0;

while (true) {
Expand Down
18 changes: 9 additions & 9 deletions src/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ std::vector<std::string> Recorder::getAvailableCodecs() {
while ((codec = av_codec_iterate(&iter))) {
if(codec->type == AVMEDIA_TYPE_VIDEO &&
(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) &&
avcodec_find_encoder_by_name(codec->name) != nullptr && codec->pix_fmts && std::find(vec.begin(), vec.end(), std::string(codec->name)) == vec.end())
vec.push_back(codec->name);
avcodec_find_encoder_by_name(codec->name) != nullptr && codec->pix_fmts && std::ranges::find(vec, std::string(codec->name)) == vec.end())
vec.emplace_back(codec->name);
}

return vec;
Expand Down Expand Up @@ -76,14 +76,14 @@ bool Recorder::init(const RenderSettings& settings) {
m_codecContext->bit_rate = settings.m_bitrate;
m_codecContext->width = settings.m_width;
m_codecContext->height = settings.m_height;
m_codecContext->time_base = AVRational(1, settings.m_fps);
m_codecContext->time_base = AVRational{1, settings.m_fps};
m_codecContext->pix_fmt = AV_PIX_FMT_NONE;
m_videoStream->time_base = m_codecContext->time_base;

const AVPixelFormat *pix_fmt = m_codec->pix_fmts;
if (pix_fmt) {
while (*pix_fmt != AV_PIX_FMT_NONE) {
if(*pix_fmt == (AVPixelFormat)settings.m_pixelFormat)
if(*pix_fmt == static_cast<AVPixelFormat>(settings.m_pixelFormat))
m_codecContext->pix_fmt = *pix_fmt;
++pix_fmt;
}
Expand All @@ -96,7 +96,7 @@ bool Recorder::init(const RenderSettings& settings) {
else
geode::log::info("Codec {} supports pixel format.", settings.m_codec);

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

if (avformat_write_header(m_formatContext, NULL) < 0) {
if (avformat_write_header(m_formatContext, nullptr) < 0) {
geode::log::error("Could not write header.");
return false;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ bool Recorder::writeFrame(const std::vector<uint8_t>& frameData) {
ret = avcodec_receive_packet(m_codecContext, m_packet);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
break;
else if (ret < 0)
if (ret < 0)
return false;

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

m_init = false;

avcodec_send_frame(m_codecContext, NULL);
avcodec_send_frame(m_codecContext, nullptr);
while (avcodec_receive_packet(m_codecContext, m_packet) == 0) {
av_packet_rescale_ts(m_packet, m_codecContext->time_base, m_videoStream->time_base);
m_packet->stream_index = m_videoStream->index;
Expand All @@ -298,4 +298,4 @@ void Recorder::stop() {
delete m_packet;
}

}
}

0 comments on commit 638f4f7

Please sign in to comment.