gmbeard / shadow-cast

GPU accelerated screen and audio recording for Linux
GNU General Public License v2.0
39 stars 0 forks source link

Unable to build on Arch Linux #17

Closed guihkx closed 1 year ago

guihkx commented 1 year ago

Hi! I'm getting some errors while trying to build on Arch Linux...

The first error I got was this one:

$ cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=/usr/bin/clang++
-- The CXX compiler identification is Clang 16.0.6
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Pipewire_INCLUDE_DIR: /usr/include/pipewire-0.3
-- Pipewire_LIBRARY: /usr/lib/libpipewire-0.3.so
-- SPA_INCLUDE_DIR: /usr/include/spa-0.2
-- Components: avcodec;avdevice;avfilter;avformat;avresample;avutil;swresample;swscale
-- FFMpeg_avcodec: FOUND
-- FFMpeg_avdevice: FOUND
-- FFMpeg_avfilter: FOUND
-- FFMpeg_avformat: FOUND
CMake Error at cmake/FindFFMpeg.cmake:95 (message):
  FFMpeg: Not all required components could be found
Call Stack (most recent call first):
  CMakeLists.txt:31 (find_package)

-- Configuring incomplete, errors occurred!

Which I was able to "fix" by removing every reference to avresample, since that library has been deprecated on Arch Linux for a very long time:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4a504e..c7b3dbc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,6 @@ find_package(
         avdevice
         avfilter
         avformat
-        avresample
         avutil
         swresample
         swscale
diff --git a/cmake/FindFFMpeg.cmake b/cmake/FindFFMpeg.cmake
index 0facb15..89914bb 100644
--- a/cmake/FindFFMpeg.cmake
+++ b/cmake/FindFFMpeg.cmake
@@ -85,7 +85,6 @@ try_find_ffmpeg_targets(
         avdevice
         avfilter
         avformat
-        avresample
         avutil
         swresample
         swscale
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7085a3a..945c0be 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -65,7 +65,6 @@ target_link_libraries(shadow-cast-obj
     FFMpeg::avdevice
     FFMpeg::avfilter
     FFMpeg::avformat
-    FFMpeg::avresample
     FFMpeg::avutil
     FFMpeg::swresample
     FFMpeg::swscale

But now I got a different error, hopefully unrelated to the removal of avresample:

$ cmake --build build
[  2%] Building CXX object src/CMakeFiles/shadow-cast-obj.dir/av/buffer.cpp.o
Checking /tmp/shadow-cast/src/av/buffer.cpp ...
Checking /tmp/shadow-cast/src/av/buffer.cpp: NDEBUG=1...
Active checkers: 59/565
[  4%] Building CXX object src/CMakeFiles/shadow-cast-obj.dir/av/buffer_pool.cpp.o
Checking /tmp/shadow-cast/src/av/buffer_pool.cpp ...
Checking /tmp/shadow-cast/src/av/buffer_pool.cpp: NDEBUG=1...
Active checkers: 59/565
[  7%] Building CXX object src/CMakeFiles/shadow-cast-obj.dir/av/codec.cpp.o
Checking /tmp/shadow-cast/src/av/codec.cpp ...
Checking /tmp/shadow-cast/src/av/codec.cpp: NDEBUG=1...
Active checkers: 59/565
/tmp/shadow-cast/src/av/codec.cpp:24:30: error: no matching constructor for initialization of 'sc::BorrowedPtr<AVCodec>' (aka 'BorrowedPtr<AVCodec>')
    sc::BorrowedPtr<AVCodec> video_encoder { avcodec_find_encoder_by_name(
                             ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/shadow-cast/src/./utils/borrowed_ptr.hpp:10:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const AVCodec *' to 'const BorrowedPtr<AVCodec>' for 1st argument
struct BorrowedPtr
       ^
/tmp/shadow-cast/src/./utils/borrowed_ptr.hpp:10:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const AVCodec *' to 'BorrowedPtr<AVCodec>' for 1st argument
/tmp/shadow-cast/src/./utils/borrowed_ptr.hpp:21:5: note: candidate template ignored: constraints not satisfied [with U = const AVCodec]
    BorrowedPtr(U* p)
    ^
/tmp/shadow-cast/src/./utils/borrowed_ptr.hpp:22:14: note: because 'std::is_convertible_v<const AVCodec *, pointer>' evaluated to false
    requires(std::is_convertible_v<U*, pointer>)
             ^
/tmp/shadow-cast/src/./utils/borrowed_ptr.hpp:28:5: note: candidate template ignored: could not match 'BorrowedPtr<U>' against 'const AVCodec *'
    BorrowedPtr(BorrowedPtr<U> const& other)
    ^
/tmp/shadow-cast/src/./utils/borrowed_ptr.hpp:18:5: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    BorrowedPtr() = default;
    ^
1 error generated.
make[2]: *** [src/CMakeFiles/shadow-cast-obj.dir/build.make:104: src/CMakeFiles/shadow-cast-obj.dir/av/codec.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: src/CMakeFiles/shadow-cast-obj.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Any help is appreciated.

Thank you!

gmbeard commented 1 year ago

Hey @guihkx. Thanks for the report.

Looks like both issues are related to ffmpeg version. My distro still has an open PR to move from ffmpeg v4.4 to v6, so I've had to develop against an older version.

I should be able to remove the avresample requirement. I don't believe it's used anyway.

But now I got a different error

Looks like the signature of the avcodec_find_encoder_by_name function has changed slightly in ffmpeg 6.

Would you be willing to try out some patches if I post them here?

guihkx commented 1 year ago

Would you be willing to try out some patches if I post them here?

Absolutely!

gmbeard commented 1 year ago

Thank you! I'll struggle to test this myself without building ffmpeg6 from scratch.

Patches incoming shortly...

gmbeard commented 1 year ago

@guihkx Try this patch...

diff --git a/src/av/codec.cpp b/src/av/codec.cpp
index be935e9..fddc14f 100644
--- a/src/av/codec.cpp
+++ b/src/av/codec.cpp
@@ -21,7 +21,7 @@ auto create_video_encoder(std::string const& encoder_name,
                           std::uint32_t fps,
                           AVPixelFormat pixel_format) -> sc::CodecContextPtr
 {
-    sc::BorrowedPtr<AVCodec> video_encoder { avcodec_find_encoder_by_name(
+    sc::BorrowedPtr<AVCodec const> video_encoder { avcodec_find_encoder_by_name(
         encoder_name.c_str()) };
     if (!video_encoder) {
         throw CodecError { "Failed to find required video codec" };
diff --git a/src/main.cpp b/src/main.cpp
index 3135ed2..8e80cee 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -85,7 +85,7 @@ auto run_wayland(sc::Parameters const& params, sc::wayland::DisplayPtr display)
     }

     sc::FormatContextPtr format_context { fc_tmp };
-    sc::BorrowedPtr<AVCodec> encoder { avcodec_find_encoder_by_name(
+    sc::BorrowedPtr<AVCodec const> encoder { avcodec_find_encoder_by_name(
         params.audio_encoder.c_str()) };
     if (!encoder) {
         throw sc::CodecError { "Failed to find required audio codec" };
@@ -282,7 +282,7 @@ auto run(sc::Parameters const& params) -> void
     }

     sc::FormatContextPtr format_context { fc_tmp };
-    sc::BorrowedPtr<AVCodec> encoder { avcodec_find_encoder_by_name(
+    sc::BorrowedPtr<AVCodec const> encoder { avcodec_find_encoder_by_name(
         params.audio_encoder.c_str()) };
     if (!encoder) {
         throw sc::CodecError { "Failed to find required audio codec" };
guihkx commented 1 year ago

That seems to have fixed the previous error, nice. Here's a new one though:

In file included from /tmp/shadow-cast/src/av/sample_format.cpp:1:
/tmp/shadow-cast/src/av/sample_format.hpp:190:31: error: no type named 'uint32_t' in namespace 'std'; did you mean simply 'uint32_t'?
auto is_sample_rate_supported(std::uint32_t requested,
                              ^~~~~~~~~~~~~
                              uint32_t
/usr/include/bits/stdint-uintn.h:26:20: note: 'uint32_t' declared here
typedef __uint32_t uint32_t;
                   ^
/tmp/shadow-cast/src/av/sample_format.cpp:36:31: error: no type named 'uint32_t' in namespace 'std'; did you mean simply 'uint32_t'?
auto is_sample_rate_supported(std::uint32_t requested,
                              ^~~~~~~~~~~~~
                              uint32_t
/usr/include/bits/stdint-uintn.h:26:20: note: 'uint32_t' declared here
typedef __uint32_t uint32_t;
                   ^
2 errors generated.
make[2]: *** [src/CMakeFiles/shadow-cast-obj.dir/build.make:174: src/CMakeFiles/shadow-cast-obj.dir/av/sample_format.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: src/CMakeFiles/shadow-cast-obj.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
gmbeard commented 1 year ago

That seems to be a clang/gcc inconsistency. I've just successfully built with clang 15 using this patch...

diff --git a/src/av/sample_format.hpp b/src/av/sample_format.hpp
index 79d9710..9a42ec1 100644
--- a/src/av/sample_format.hpp
+++ b/src/av/sample_format.hpp
@@ -3,6 +3,7 @@

 #include "av/fwd.hpp"
 #include "utils/borrowed_ptr.hpp"
+#include <cinttypes>
 #include <spa/param/audio/format-utils.h>
 #include <span>
 #include <stdexcept>
diff --git a/src/services/video_service.hpp b/src/services/video_service.hpp
index 3840969..57c04cf 100644
--- a/src/services/video_service.hpp
+++ b/src/services/video_service.hpp
@@ -31,7 +31,7 @@ protected:
     auto on_init(ReadinessRegister) -> void override;

 private:
-    NvCuda nvcuda_;
+    [[maybe_unused]] NvCuda nvcuda_;
     NvFBC nvfbc_;
     BorrowedPtr<std::remove_pointer_t<CUcontext>> nvcuda_ctx_;
     NVFBC_SESSION_HANDLE nvfbc_session_;
guihkx commented 1 year ago

That worked, thanks! Now I'm getting a few other errors related to ffmpeg 6... :sweat_smile:

/tmp/shadow-cast/src/handlers/audio_chunk_writer.cpp:39:12: error: 'channels' is deprecated [-Werror,-Wdeprecated-declarations]
    frame->channels = interleaved ? 2 : chunk.channel_buffers().size();
           ^
/usr/include/libavutil/frame.h:730:5: note: 'channels' has been explicitly marked deprecated here
    attribute_deprecated
    ^
/usr/include/libavutil/attributes.h:100:49: note: expanded from macro 'attribute_deprecated'
#    define attribute_deprecated __attribute__((deprecated))
                                                ^
/tmp/shadow-cast/src/handlers/audio_chunk_writer.cpp:41:12: error: 'channel_layout' is deprecated [-Werror,-Wdeprecated-declarations]
    frame->channel_layout = AV_CH_LAYOUT_STEREO;
           ^
/usr/include/libavutil/frame.h:574:5: note: 'channel_layout' has been explicitly marked deprecated here
    attribute_deprecated
    ^
/usr/include/libavutil/attributes.h:100:49: note: expanded from macro 'attribute_deprecated'
#    define attribute_deprecated __attribute__((deprecated))
                                                ^
2 errors generated.
make[2]: *** [src/CMakeFiles/shadow-cast-obj.dir/build.make:230: src/CMakeFiles/shadow-cast-obj.dir/handlers/audio_chunk_writer.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: src/CMakeFiles/shadow-cast-obj.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
gmbeard commented 1 year ago

Not holding my breath with this one, but give it a try...

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c7b3dbc..799dc3e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,8 @@ find_package(
 find_package(X11 REQUIRED)
 find_package(DRM REQUIRED)

+include(FFMpegVersion)
+
 option(
     SHADOW_CAST_ENABLE_TESTS
     "Enable tests for ${PROJECT_NAME}"
diff --git a/cmake/FFMpegVersion.cmake b/cmake/FFMpegVersion.cmake
new file mode 100644
index 0000000..34d7eee
--- /dev/null
+++ b/cmake/FFMpegVersion.cmake
@@ -0,0 +1,19 @@
+set(
+   ffmpeg_6_check_src
+   "extern \"C\" {
+#include <libavutil/avutil.h>
+#include <libavutil/frame.h>
+}
+
+int main(int, char**) {
+   AVFrame* frame;
+   av_channel_layout_default(&frame->ch_layout, 2);
+}")
+
+try_compile(
+   SC_FFMPEG_6
+   SOURCE_FROM_VAR ffmpeg_6_check.cpp ffmpeg_6_check_src
+   OUTPUT_VARIABLE ffmpeg_6_result
+)
+
+message(STATUS ${ffmpeg_6_result})
diff --git a/src/config.hpp.in b/src/config.hpp.in
index d4d0d7a..bff09c0 100644
--- a/src/config.hpp.in
+++ b/src/config.hpp.in
@@ -1,6 +1,8 @@
 #ifndef SHADOW_CAST_CONFIG_HPP_INCLUDED
 #define SHADOW_CAST_CONFIG_HPP_INCLUDED

+#cmakedefine FFMPEG_6
+
 namespace sc
 {
 enum struct ByteOrder
diff --git a/src/handlers/audio_chunk_writer.cpp b/src/handlers/audio_chunk_writer.cpp
index 04fb0f5..9ad7b4f 100644
--- a/src/handlers/audio_chunk_writer.cpp
+++ b/src/handlers/audio_chunk_writer.cpp
@@ -1,6 +1,7 @@
 #include "handlers/audio_chunk_writer.hpp"
 #include "av/frame.hpp"
 #include "av/sample_format.hpp"
+#include "config.hpp"
 #include "error.hpp"
 #include <algorithm>
 #include <cassert>
@@ -36,9 +37,13 @@ auto ChunkWriter::operator()(MediaChunk const& chunk) -> void
     frame->nb_samples = chunk.sample_count;
     frame->format = codec_context_->sample_fmt;
     frame->sample_rate = codec_context_->sample_rate;
+#ifdef SC_FFMPEG_6
+    AVChannelLayout default_ch_layout = AV_CHANNEL_LAYOUT_STEREO;
+    av_channel_layout_copy(&frame->ch_layout, &default_ch_layout);
+#else
     frame->channels = interleaved ? 2 : chunk.channel_buffers().size();
-
     frame->channel_layout = AV_CH_LAYOUT_STEREO;
+#endif
     frame->pts = total_samples_written_;
     total_samples_written_ += frame->nb_samples;
guihkx commented 1 year ago

I deleted the build directory and now it fails before compiling:

$ cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=/usr/bin/clang++
-- The CXX compiler identification is Clang 16.0.6
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Pipewire_INCLUDE_DIR: /usr/include/pipewire-0.3
-- Pipewire_LIBRARY: /usr/lib/libpipewire-0.3.so
-- SPA_INCLUDE_DIR: /usr/include/spa-0.2
-- Components: avcodec;avdevice;avfilter;avformat;avutil;swresample;swscale
-- FFMpeg_avcodec: FOUND
-- FFMpeg_avdevice: FOUND
-- FFMpeg_avfilter: FOUND
-- FFMpeg_avformat: FOUND
-- FFMpeg_avutil: FOUND
-- FFMpeg_swresample: FOUND
-- FFMpeg_swscale: FOUND
-- Found X11: /usr/include   
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found DRM: /usr/lib/libdrm.so  
-- DRM_INCLUDE_DIRS: /usr/include/libdrm;/usr/include
-- DRM_LIBRARY: /usr/include
-- Change Dir: '/tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-futG1P'

Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_846a4/fast
/usr/bin/make  -f CMakeFiles/cmTC_846a4.dir/build.make CMakeFiles/cmTC_846a4.dir/build
make[1]: Entering directory '/tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-futG1P'
Building CXX object CMakeFiles/cmTC_846a4.dir/ffmpeg_6_check.cpp.o
/usr/bin/clang++   -std=gnu++20 -MD -MT CMakeFiles/cmTC_846a4.dir/ffmpeg_6_check.cpp.o -MF CMakeFiles/cmTC_846a4.dir/ffmpeg_6_check.cpp.o.d -o CMakeFiles/cmTC_846a4.dir/ffmpeg_6_check.cpp.o -c /tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-futG1P/ffmpeg_6_check.cpp
In file included from /tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-futG1P/ffmpeg_6_check.cpp:2:
In file included from /usr/include/libavutil/avutil.h:301:
/usr/include/libavutil/common.h:30:2: error: missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
#error missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
 ^
1 error generated.
make[1]: *** [CMakeFiles/cmTC_846a4.dir/build.make:79: CMakeFiles/cmTC_846a4.dir/ffmpeg_6_check.cpp.o] Error 1
make[1]: Leaving directory '/tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-futG1P'
make: *** [Makefile:127: cmTC_846a4/fast] Error 2

-- Configuring done (2.4s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/shadow-cast/build
gmbeard commented 1 year ago

Another...

diff --git a/cmake/FFMpegVersion.cmake b/cmake/FFMpegVersion.cmake
index 34d7eee..66c5009 100644
--- a/cmake/FFMpegVersion.cmake
+++ b/cmake/FFMpegVersion.cmake
@@ -1,8 +1,11 @@
 set(
    ffmpeg_6_check_src
    "extern \"C\" {
-#include <libavutil/avutil.h>
+#include <libavcodec/avcodec.h>
+#include <libavutil/channel_layout.h>
+#include <libavutil/common.h>
 #include <libavutil/frame.h>
+#include <libavutil/samplefmt.h>
 }

 int main(int, char**) {
guihkx commented 1 year ago

Not yet:

Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_1967f/fast
/usr/bin/make  -f CMakeFiles/cmTC_1967f.dir/build.make CMakeFiles/cmTC_1967f.dir/build
make[1]: Entering directory '/tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-p1j2hg'
Building CXX object CMakeFiles/cmTC_1967f.dir/ffmpeg_6_check.cpp.o
/usr/bin/clang++   -std=gnu++20 -MD -MT CMakeFiles/cmTC_1967f.dir/ffmpeg_6_check.cpp.o -MF CMakeFiles/cmTC_1967f.dir/ffmpeg_6_check.cpp.o.d -o CMakeFiles/cmTC_1967f.dir/ffmpeg_6_check.cpp.o -c /tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-p1j2hg/ffmpeg_6_check.cpp
Linking CXX executable cmTC_1967f
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1967f.dir/link.txt --verbose=1
/usr/bin/clang++ CMakeFiles/cmTC_1967f.dir/ffmpeg_6_check.cpp.o -o cmTC_1967f 
/usr/bin/ld: CMakeFiles/cmTC_1967f.dir/ffmpeg_6_check.cpp.o: in function `main':
ffmpeg_6_check.cpp:(.text+0x20): undefined reference to `av_channel_layout_default'
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_1967f.dir/build.make:100: cmTC_1967f] Error 1
make[1]: Leaving directory '/tmp/shadow-cast/build/CMakeFiles/CMakeScratch/TryCompile-p1j2hg'
make: *** [Makefile:127: cmTC_1967f/fast] Error 2
gmbeard commented 1 year ago

And another...

diff --git a/cmake/FFMpegVersion.cmake b/cmake/FFMpegVersion.cmake
index 66c5009..8578c58 100644
--- a/cmake/FFMpegVersion.cmake
+++ b/cmake/FFMpegVersion.cmake
@@ -17,6 +17,14 @@ try_compile(
    SC_FFMPEG_6
    SOURCE_FROM_VAR ffmpeg_6_check.cpp ffmpeg_6_check_src
    OUTPUT_VARIABLE ffmpeg_6_result
+   LINK_LIBRARIES
+       FFMpeg::avcodec
+       FFMpeg::avdevice
+       FFMpeg::avfilter
+       FFMpeg::avformat
+       FFMpeg::avutil
+       FFMpeg::swresample
+       FFMpeg::swscale
 )

 message(STATUS ${ffmpeg_6_result})
guihkx commented 1 year ago

Now CMake passes, but building fails:

/tmp/shadow-cast/src/handlers/audio_chunk_writer.cpp:44:12: error: 'channels' is deprecated [-Werror,-Wdeprecated-declarations]
    frame->channels = interleaved ? 2 : chunk.channel_buffers().size();
           ^
/usr/include/libavutil/frame.h:730:5: note: 'channels' has been explicitly marked deprecated here
    attribute_deprecated
    ^
/usr/include/libavutil/attributes.h:100:49: note: expanded from macro 'attribute_deprecated'
#    define attribute_deprecated __attribute__((deprecated))
                                                ^
/tmp/shadow-cast/src/handlers/audio_chunk_writer.cpp:45:12: error: 'channel_layout' is deprecated [-Werror,-Wdeprecated-declarations]
    frame->channel_layout = AV_CH_LAYOUT_STEREO;
           ^
/usr/include/libavutil/frame.h:574:5: note: 'channel_layout' has been explicitly marked deprecated here
    attribute_deprecated
    ^
/usr/include/libavutil/attributes.h:100:49: note: expanded from macro 'attribute_deprecated'
#    define attribute_deprecated __attribute__((deprecated))
                                                ^
2 errors generated.
make[2]: *** [src/CMakeFiles/shadow-cast-obj.dir/build.make:230: src/CMakeFiles/shadow-cast-obj.dir/handlers/audio_chunk_writer.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: src/CMakeFiles/shadow-cast-obj.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
gmbeard commented 1 year ago

Agh, nuts!

Ok, I'm going to have to take this offline and try to build against ffmpeg6 myself. I'm not even sure that some of the patches would actually work TBH, even if it managed to build - the audio channel layout patch I did looks a bit sus to me.

I've created a new branch for this work (including all the patches above), so I'll keep this issue updated.

Thank you for you help. Really appreciate you spending your time to help with this, @guihkx

guihkx commented 1 year ago

No worries! :)

Just ping me if you want me to test it again later...

Good luck!

gmbeard commented 1 year ago

@guihkx I've obviously not had time to test it myself, but I've just pushed a commit to my ffmpeg6-compatibility branch that I think might sort it. When you have some time, It'd be great if you could pull down that branch and see if it solves your build issues

EDIT: Probably worth blowing away any changes you have locally, too

guihkx commented 1 year ago

I think we're really close! After I added these changes:

diff --git a/src/handlers/audio_chunk_writer.cpp b/src/handlers/audio_chunk_writer.cpp
index 5cd4bcc..db952d2 100644
--- a/src/handlers/audio_chunk_writer.cpp
+++ b/src/handlers/audio_chunk_writer.cpp
@@ -41,7 +41,7 @@ auto ChunkWriter::operator()(MediaChunk const& chunk) -> void
     frame->channels = interleaved ? 2 : chunk.channel_buffers().size();
     frame->channel_layout = AV_CH_LAYOUT_STEREO;
 #else
-    av_channel_layout_copy(&fram->ch_layout, &codec_context->ch_layout);
+    av_channel_layout_copy(&frame->ch_layout, &codec_context_->ch_layout);
 #endif
     frame->pts = total_samples_written_;
     total_samples_written_ += frame->nb_samples;
diff --git a/src/platform/wayland.hpp b/src/platform/wayland.hpp
index 1bc3242..44c6188 100644
--- a/src/platform/wayland.hpp
+++ b/src/platform/wayland.hpp
@@ -2,6 +2,7 @@
 #define SHADOW_CAST_PLATFORM_WAYLAND_HPP_INCLUDED

 #include "./egl.hpp"
+#include <cinttypes>
 #include <memory>
 #include <type_traits>
 #include <wayland-client.h>

Compilation got to 92%, but it ultimately failed with this error:

/tmp/shadow-cast/src/main.cpp:345:37: error: no matching function for call to 'av_buffer_pool_init'
    sc::BufferPoolPtr buffer_pool { av_buffer_pool_init(
                                    ^~~~~~~~~~~~~~~~~~~
/usr/include/libavutil/buffer.h:266:15: note: candidate function not viable: no known conversion from '(lambda at /tmp/shadow-cast/src/main.cpp:346:12)' to 'AVBufferRef *(*)(size_t)' (aka 'AVBufferRef *(*)(unsigned long)') for 2nd argument
AVBufferPool *av_buffer_pool_init(size_t size, AVBufferRef* (*alloc)(size_t size));
              ^
gmbeard commented 1 year ago

@guihkx I've just added another small commit to that branch. :pray:

guihkx commented 1 year ago

It builds!!! :tada: (I still needed the patch from my previous comment, though)

But there's this thing I forgot to mention... :sweat_smile:

I have a really old NVIDIA GPU (GTX 660, Kepler architecture, 470xx drivers), so when I run shadow-cast foo.mp4, I get the following output:

[hevc_nvenc @ 0x55cf6999fb00] ignoring invalid SAR: 0/0
[hevc_nvenc @ 0x55cf6999fb00] Codec not supported
[hevc_nvenc @ 0x55cf6999fb00] Provided device doesn't support required NVENC features
ERROR: Failed to open video codec: Function not implemented

One obvious thing to note is that this card does not support H265 encoding (or decoding), only H264.

I completely understand if you don't want to add support for such an old card, especially since official NVIDIA support for this card will also be ending very soon.

In any case, this is a whole separate issue...

Thank you for your work!

guihkx commented 1 year ago

Oh, I didn't know I could specify a different codec... Strangely, it doesn't seem to work? :thinking:

$ shadow-cast -V h264_nvenc test.mp4
ERROR: Invalid option value: h264_nvenc
gmbeard commented 1 year ago

Oh, man. I have mixed emotions right now!

It looks like Maxwell GPU is required for NVENC at the absolute minimum.

I want to hopefully support other vendors' GPUs (AMD, Intel). In doing so, this may allow Kepler NVIDIA GPUs (although they'd still have to support VAAPI, which I'm not sure they do).

ERROR: Invalid option value: h264_nvenc

You've found a bug there. Hmm, that should be covered by the tests. Alas, I still don't think it'll help you - h264_nvenc still requires GPU support.

I so very grateful for your time and help with this. Thank you.

gmbeard commented 1 year ago

One last thing... would you mind sharing some system info?...

This would be useful info for compiling some compatibility info

guihkx commented 1 year ago

It looks like Maxwell GPU is required for NVENC at the absolute minimum.

Technically, Kepler does support NVENC just fine - but if I understand correctly, only up to version 11 of NVIDIA's Video Codec SDK. We're currently at version 12.

But like I said, I'd completely understand not wanting to support it.

I want to hopefully support other vendors' GPUs (AMD, Intel). In doing so, this may allow Kepler NVIDIA GPUs (although they'd still have to support VAAPI, which I'm not sure they do).

That's awesome to hear! Unfortunately, I think NVIDIA drivers only implements VDPAU, not VAAPI. :(

Alas, I still don't think it'll help you - h264_nvenc still requires GPU support.

I added a temporary workaround just to see if h264_nvenc would work, but it didn't and I have no idea of how far I am from getting it to work:

[h264_nvenc @ 0x55d7d1d06a80] ignoring invalid SAR: 0/0
[h264_nvenc @ 0x55d7d1d06a80] YUV444P not supported
[h264_nvenc @ 0x55d7d1d06a80] Provided device doesn't support required NVENC features
ERROR: Failed to open video codec: Function not implemented

One last thing... would you mind sharing some system info?...

Sure: