Skip to content

Commit

Permalink
add vflip support
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnut committed Dec 29, 2024
1 parent 46e68fc commit 6768ca0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class FFMPEG_API_DLL Recorder {
AVFilterContext* m_buffersrcCtx = nullptr;
AVFilterContext* m_buffersinkCtx = nullptr;
AVFilterContext* m_colorspaceCtx = nullptr;
AVFilterContext* m_vflipCtx = nullptr;

size_t m_frameCount = 0;
bool m_init = false;
Expand Down
1 change: 1 addition & 0 deletions include/render_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ struct RenderSettings {
PixelFormat m_pixelFormat = PixelFormat::RGB0;
std::string m_codec = "h264";
std::string m_colorspaceFilters = "";
bool m_doVerticalFlip = true;
int64_t m_bitrate = 30000000;
uint32_t m_width = 1920;
uint32_t m_height = 1080;
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "4.0.1",
"geode": "4.1.1",
"gd": {
"win": "*",
"android": "*",
Expand Down
44 changes: 32 additions & 12 deletions src/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ geode::Result<> Recorder::init(const RenderSettings& settings) {

int inputPixelFormat = (int)settings.m_pixelFormat;

if(!settings.m_colorspaceFilters.empty()) {
if(!settings.m_colorspaceFilters.empty() || settings.m_doVerticalFlip) {
m_filterGraph = avfilter_graph_alloc();
if (!m_filterGraph)
return geode::Err("Could not allocate filter graph.");

const AVFilter* buffersrc = avfilter_get_by_name("buffer");
const AVFilter* buffersink = avfilter_get_by_name("buffersink");
const AVFilter* colorspace = avfilter_get_by_name("colorspace");
const AVFilter* vflip = avfilter_get_by_name("vflip");

char args[512];
snprintf(args, sizeof(args),
Expand All @@ -150,19 +151,38 @@ geode::Result<> Recorder::init(const RenderSettings& settings) {
return geode::Err("Could not create output for filter graph: " + utils::getErrorString(ret));
}

if(ret = avfilter_graph_create_filter(&m_colorspaceCtx, colorspace, "colorspace", settings.m_colorspaceFilters.c_str(), nullptr, m_filterGraph); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not create colorspace for filter graph: " + utils::getErrorString(ret));
if(!settings.m_colorspaceFilters.empty()) {
if(ret = avfilter_graph_create_filter(&m_colorspaceCtx, colorspace, "colorspace", settings.m_colorspaceFilters.c_str(), nullptr, m_filterGraph); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not create colorspace for filter graph: " + utils::getErrorString(ret));
}

if(ret = avfilter_link(m_buffersrcCtx, 0, m_colorspaceCtx, 0); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
}

if(ret = avfilter_link(m_colorspaceCtx, 0, m_buffersinkCtx, 0); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
}
}

if(ret = avfilter_link(m_buffersrcCtx, 0, m_colorspaceCtx, 0); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
}

if(ret = avfilter_link(m_colorspaceCtx, 0, m_buffersinkCtx, 0); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
if(settings.m_doVerticalFlip) {
if(ret = avfilter_graph_create_filter(&m_vflipCtx, vflip, "vflip", nullptr, nullptr, m_filterGraph); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not create vflip for filter graph: " + utils::getErrorString(ret));
}

if(ret = avfilter_link(m_buffersrcCtx, 0, m_vflipCtx, 0); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
}

if(ret = avfilter_link(m_vflipCtx, 0, m_buffersinkCtx, 0); ret < 0) {
avfilter_graph_free(&m_filterGraph);
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
}
}

if (ret = avfilter_graph_config(m_filterGraph, nullptr); ret < 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ std::string getErrorString(int errorCode) {
char errbuf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(errorCode, errbuf, AV_ERROR_MAX_STRING_SIZE);
std::string errStr(errbuf);
errStr += "\nDetails:\n";
for(const std::string& log : s_ffmpegLogs)
errStr += log;
// errStr += "\nDetails:\n";
// for(const std::string& log : s_ffmpegLogs)
// errStr += log;

s_ffmpegLogs.clear();
return errStr;
Expand Down

0 comments on commit 6768ca0

Please sign in to comment.