Skip to content

Commit 6768ca0

Browse files
committed
add vflip support
1 parent 46e68fc commit 6768ca0

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

include/recorder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class FFMPEG_API_DLL Recorder {
8989
AVFilterContext* m_buffersrcCtx = nullptr;
9090
AVFilterContext* m_buffersinkCtx = nullptr;
9191
AVFilterContext* m_colorspaceCtx = nullptr;
92+
AVFilterContext* m_vflipCtx = nullptr;
9293

9394
size_t m_frameCount = 0;
9495
bool m_init = false;

include/render_settings.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ struct RenderSettings {
313313
PixelFormat m_pixelFormat = PixelFormat::RGB0;
314314
std::string m_codec = "h264";
315315
std::string m_colorspaceFilters = "";
316+
bool m_doVerticalFlip = true;
316317
int64_t m_bitrate = 30000000;
317318
uint32_t m_width = 1920;
318319
uint32_t m_height = 1080;

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.0.1",
2+
"geode": "4.1.1",
33
"gd": {
44
"win": "*",
55
"android": "*",

src/recorder.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ geode::Result<> Recorder::init(const RenderSettings& settings) {
124124

125125
int inputPixelFormat = (int)settings.m_pixelFormat;
126126

127-
if(!settings.m_colorspaceFilters.empty()) {
127+
if(!settings.m_colorspaceFilters.empty() || settings.m_doVerticalFlip) {
128128
m_filterGraph = avfilter_graph_alloc();
129129
if (!m_filterGraph)
130130
return geode::Err("Could not allocate filter graph.");
131131

132132
const AVFilter* buffersrc = avfilter_get_by_name("buffer");
133133
const AVFilter* buffersink = avfilter_get_by_name("buffersink");
134134
const AVFilter* colorspace = avfilter_get_by_name("colorspace");
135+
const AVFilter* vflip = avfilter_get_by_name("vflip");
135136

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

153-
if(ret = avfilter_graph_create_filter(&m_colorspaceCtx, colorspace, "colorspace", settings.m_colorspaceFilters.c_str(), nullptr, m_filterGraph); ret < 0) {
154-
avfilter_graph_free(&m_filterGraph);
155-
return geode::Err("Could not create colorspace for filter graph: " + utils::getErrorString(ret));
154+
if(!settings.m_colorspaceFilters.empty()) {
155+
if(ret = avfilter_graph_create_filter(&m_colorspaceCtx, colorspace, "colorspace", settings.m_colorspaceFilters.c_str(), nullptr, m_filterGraph); ret < 0) {
156+
avfilter_graph_free(&m_filterGraph);
157+
return geode::Err("Could not create colorspace for filter graph: " + utils::getErrorString(ret));
158+
}
159+
160+
if(ret = avfilter_link(m_buffersrcCtx, 0, m_colorspaceCtx, 0); ret < 0) {
161+
avfilter_graph_free(&m_filterGraph);
162+
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
163+
}
164+
165+
if(ret = avfilter_link(m_colorspaceCtx, 0, m_buffersinkCtx, 0); ret < 0) {
166+
avfilter_graph_free(&m_filterGraph);
167+
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
168+
}
156169
}
157170

158-
if(ret = avfilter_link(m_buffersrcCtx, 0, m_colorspaceCtx, 0); ret < 0) {
159-
avfilter_graph_free(&m_filterGraph);
160-
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
161-
}
162-
163-
if(ret = avfilter_link(m_colorspaceCtx, 0, m_buffersinkCtx, 0); ret < 0) {
164-
avfilter_graph_free(&m_filterGraph);
165-
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
171+
if(settings.m_doVerticalFlip) {
172+
if(ret = avfilter_graph_create_filter(&m_vflipCtx, vflip, "vflip", nullptr, nullptr, m_filterGraph); ret < 0) {
173+
avfilter_graph_free(&m_filterGraph);
174+
return geode::Err("Could not create vflip for filter graph: " + utils::getErrorString(ret));
175+
}
176+
177+
if(ret = avfilter_link(m_buffersrcCtx, 0, m_vflipCtx, 0); ret < 0) {
178+
avfilter_graph_free(&m_filterGraph);
179+
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
180+
}
181+
182+
if(ret = avfilter_link(m_vflipCtx, 0, m_buffersinkCtx, 0); ret < 0) {
183+
avfilter_graph_free(&m_filterGraph);
184+
return geode::Err("Could not link filters: " + utils::getErrorString(ret));
185+
}
166186
}
167187

168188
if (ret = avfilter_graph_config(m_filterGraph, nullptr); ret < 0) {

src/utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ std::string getErrorString(int errorCode) {
2525
char errbuf[AV_ERROR_MAX_STRING_SIZE];
2626
av_strerror(errorCode, errbuf, AV_ERROR_MAX_STRING_SIZE);
2727
std::string errStr(errbuf);
28-
errStr += "\nDetails:\n";
29-
for(const std::string& log : s_ffmpegLogs)
30-
errStr += log;
28+
// errStr += "\nDetails:\n";
29+
// for(const std::string& log : s_ffmpegLogs)
30+
// errStr += log;
3131

3232
s_ffmpegLogs.clear();
3333
return errStr;

0 commit comments

Comments
 (0)