@@ -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 ) {
0 commit comments