Skip to content

Commit bf4ffda

Browse files
committed
load ffmpeg exe from gd folder
1 parent f2471a7 commit bf4ffda

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

src/overlay_layer.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "recorder_layer.hpp"
66
#include "nodes.hpp"
77
#include "version.hpp"
8+
#include <filesystem>
89

910
bool OverlayLayer::init() {
1011
if (!initWithColor({ 0, 0, 0, 105 })) return false;
@@ -209,16 +210,22 @@ void OverlayLayer::_update_default_fps() {
209210
}
210211

211212
void OverlayLayer::FLAlert_Clicked(gd::FLAlertLayer* alert, bool btn2) {
212-
if (!btn2) {
213-
auto& rs = ReplaySystem::get();
214-
int tag = alert->getTag();
215-
if (tag == 1) {
216-
rs.toggle_recording();
213+
if (alert->getTag() == 1) {
214+
if (!btn2) {
215+
CCApplication::sharedApplication()->openURL("https://www.gyan.dev/ffmpeg/builds/");
216+
}
217+
} else {
218+
if (!btn2) {
219+
auto& rs = ReplaySystem::get();
220+
int tag = alert->getTag();
221+
if (tag == 1) {
222+
rs.toggle_recording();
223+
update_info_text();
224+
} else if (tag == 2) {
225+
_handle_load_replay();
226+
}
217227
update_info_text();
218-
} else if (tag == 2) {
219-
_handle_load_replay();
220228
}
221-
update_info_text();
222229
}
223230
}
224231

@@ -317,14 +324,28 @@ void OverlayLayer::on_toggle_showcase(CCObject* toggle_) {
317324
void OverlayLayer::on_recorder(CCObject*) {
318325
static bool has_ffmpeg = false;
319326
if (!has_ffmpeg) {
320-
// theres prob a way to do it by not spawning a process but im lazy and hate dealing with winapi
321-
auto process = subprocess::Popen("where ffmpeg");
322-
if (process.close())
323-
gd::FLAlertLayer::create(nullptr, "Error", "Ok", nullptr, "ffmpeg was not found in your path, recorder will not work without it")->show();
324-
else
327+
char buffer[MAX_PATH];
328+
GetModuleFileNameA(GetModuleHandleA(NULL), buffer, MAX_PATH);
329+
const auto path = std::filesystem::path(buffer).parent_path() / "ffmpeg.exe";
330+
if (std::filesystem::exists(path)) {
325331
has_ffmpeg = true;
326-
if (!has_ffmpeg)
327-
return;
332+
ReplaySystem::get().recorder.m_ffmpeg_path = path.string();
333+
} else {
334+
// theres prob a way to do it by not spawning a process but im lazy and hate dealing with winapi
335+
auto process = subprocess::Popen("where ffmpeg");
336+
if (process.close()) {
337+
auto popup = gd::FLAlertLayer::create(this, "Error",
338+
"Download", "Cancel",
339+
"ffmpeg was not found, recorder will not work without it. "
340+
"To install ffmpeg download it and place the ffmpeg.exe (found inside the bin folder in the zip) in the gd folder"
341+
);
342+
popup->setTag(1);
343+
popup->show();
344+
} else
345+
has_ffmpeg = true;
346+
if (!has_ffmpeg)
347+
return;
348+
}
328349
}
329350
RecorderLayer::create()->show();
330351
}

src/recorder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void Recorder::start(const std::string& path) {
3838
auto song_offset = m_song_start_offset;
3939
std::thread([&, path, song_file, fade_in, fade_out, bg_volume, sfx_volume, is_testmode, song_offset]() {
4040
std::stringstream stream;
41-
stream << "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s " << m_width << "x" << m_height << " -r " << m_fps
41+
stream << '"' << m_ffmpeg_path << '"' << " -y -f rawvideo -pix_fmt rgb24 -s " << m_width << "x" << m_height << " -r " << m_fps
4242
<< " -i - ";
4343
if (!m_codec.empty())
4444
stream << "-c:v " << m_codec << " ";
@@ -77,7 +77,7 @@ void Recorder::start(const std::string& path) {
7777
auto total_time = m_last_frame_t; // 1 frame too short?
7878
{
7979
std::stringstream stream;
80-
stream << "ffmpeg -y -ss " << song_offset << " -i \"" << song_file
80+
stream << '"' << m_ffmpeg_path << '"' << " -y -ss " << song_offset << " -i \"" << song_file
8181
<< "\" -i \"" << path << "\" -t " << total_time << " -c:v copy ";
8282
if (!m_extra_audio_args.empty())
8383
stream << m_extra_audio_args << " ";

src/recorder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Recorder {
3939
float m_song_start_offset;
4040
bool m_finished_level;
4141
bool m_include_audio = true;
42+
std::string m_ffmpeg_path = "ffmpeg";
4243

4344
void start(const std::string& path);
4445
void stop();

0 commit comments

Comments
 (0)