gaussian-splatting icon indicating copy to clipboard operation
gaussian-splatting copied to clipboard

SIBR viewer install fails (Ubuntu 22.04)

Open dialectrics opened this issue 11 months ago • 7 comments

Building the SIBR viewer was successful, but cmake fails when installing the target seemingly due to use of deprecated FFMPEG functions. Curious if anyone else building SIBR from source on linux has succeeded and if so what was the formula for success. I've tried a couple versions of FFMPEG and libavcodec but they turn up same results. For the record, I'm able to train successfully and used the forked nerfstudio viewer to visualize the result with zero issues. Any input appreciated, maybe the answer is right under my nose and I just can't see it. Here's the command line output when I follow the SIBR install instructions:

(nerfstudio) mrpibb@mrpibb:~/gaussian-splatting/SIBR_viewers$ cmake -Bbuild . -DCMAKE_BUILD_TYPE=Release 
-- Git found: /usr/bin/git
-- SIBR version :
 BRANCH HEAD
 COMMIT_HASH 14199886ae3f42358092c16ada909c1e0b1cba20
 TAG 
 VERSION 0.9.6-141-g1419988
-- Install path set to /home/mrpibb/gaussian-splatting/SIBR_viewers/install.
Note you can provide default program options for Visual Studio target properties by either setting a value for the cmake cached variable 'SIBR_PROGRAMARGS' or by setting a new environment variable 'SIBR_PROGRAMARGS'
-- 
****************** Handling core dependencies ******************
Activating EGL support for headless GLFW/GLEW
There is no provided GLEW library for your compiler, relying on find_package to find it
-- FindGLEW: did not find GLEW CMake config file. Searching for libraries.
-- FindGLEW: GLEW_USE_STATIC_LIBS is undefined. Treated as FALSE.
-- FindGLEW: GLEW_INCLUDE_DIR: /usr/include
-- FindGLEW: GLEW_INCLUDE_DIRS: /usr/include
-- FindGLEW: CMAKE_FIND_LIBRARY_SUFFIXES for SHARED: .so;.a
-- FindGLEW: CMAKE_FIND_LIBRARY_SUFFIXES for STATIC: .so
-- FindGLEW: GLEW_SHARED_LIBRARY_RELEASE: /usr/lib/x86_64-linux-gnu/libGLEW.so
-- FindGLEW: GLEW_STATIC_LIBRARY_RELEASE: /usr/lib/x86_64-linux-gnu/libGLEW.a
-- FindGLEW: GLEW_SHARED_LIBRARY_DEBUG: GLEW_SHARED_LIBRARY_DEBUG-NOTFOUND
-- FindGLEW: GLEW_STATIC_LIBRARY_DEBUG: GLEW_STATIC_LIBRARY_DEBUG-NOTFOUND
-- FindGLEW: GLEW_SHARED_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLEW.so
-- FindGLEW: GLEW_STATIC_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLEW.a
-- FindGLEW: GLEW_LIBRARIES: /usr/lib/x86_64-linux-gnu/libGLEW.so
-- FindGLEW: GLEW_VERSION_MAJOR: 2
-- FindGLEW: GLEW_VERSION_MINOR: 2
-- FindGLEW: GLEW_VERSION_MICRO: 0
-- FindGLEW: GLEW_VERSION: 2.2.0
-- FindGLEW: Creating GLEW::glew imported target.
-- FindGLEW: Creating GLEW::GLEW imported target.
There is no provided ASSIMP library for your compiler, relying on find_package to find it
NO ASSIMP DIR ASSIMP_DIR
SETTING ASSIMP DIR ASSIMP_DIR
ASSIMP DIR ASSIMP_DIR
There is no provided OpenCV library for your compiler, relying on find_package to find it
-- Library imgui already available, skipping.
-- Library nativefiledialog already available, skipping.
-- Library mrf already available, skipping.
-- Library nanoflann already available, skipping.
-- Library picojson already available, skipping.
-- Library rapidxml already available, skipping.
-- Library xatlas already available, skipping.
-- ****************************************************************
-- Adding dataset_tools project
-- BUILD_IBR_DATASET_TOOLS is OFF
-- Adding ulr project
-- BUILD_IBR_ULR is OFF
-- Adding basic project
-- BUILD_IBR_BASIC is ON
-- Adding gaussianviewer project
-- BUILD_IBR_GAUSSIANVIEWER is ON
-- Library CudaRasterizer already available, skipping.
-- Adding remote project
-- BUILD_IBR_REMOTE is ON
-- Configuring done (0.2s)
-- Generating done (0.1s)
-- Build files have been written to: /home/mrpibb/gaussian-splatting/SIBR_viewers/build

(nerfstudio) mrpibb@mrpibb:~/gaussian-splatting/SIBR_viewers$ cmake --build build -j24 --target install
[  0%] Built target sibr_graphics_resources
[  2%] Built target mrf
[  2%] Built target SIBR_texturedMesh_app_resources
[  6%] Built target imgui
[  8%] Built target xatlas
[ 11%] Built target nativefiledialog
[ 11%] Built target sibr_gaussian_shaders
[ 13%] Built target CudaRasterizer
[ 23%] Built target sibr_system
[ 23%] Built target sibr_renderer_shaders
[ 23%] Built target sibr_view_shaders
[ 23%] Built target PREBUILD
[ 35%] Built target sibr_graphics
[ 37%] Building CXX object src/core/video/CMakeFiles/sibr_video.dir/FFmpegVideoEncoder.cpp.o
[ 42%] Built target sibr_assets
[ 48%] Built target sibr_raycaster
[ 52%] Built target sibr_imgproc
[ 58%] Built target sibr_scene
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp: In constructor ‘sibr::FFVideoEncoder::FFVideoEncoder(const string&, double, const Vector2i&, bool)’:
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp:46:4: error: ‘av_register_all’ was not declared in this scope
   46 |    av_register_all();
      |    ^~~~~~~~~~~~~~~
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp: In member function ‘void sibr::FFVideoEncoder::close()’:
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp:82:28: error: ‘struct AVStream’ has no member named ‘codec’
   82 |    avcodec_close(video_st->codec);
      |                            ^~~~~
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp: In member function ‘void sibr::FFVideoEncoder::init(const Vector2i&)’:
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp:111:24: warning: invalid conversion from ‘const AVOutputFormat*’ to ‘AVOutputFormat*’ [-fpermissive]
  111 |   fmt = av_guess_format(NULL, out_file, NULL);
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
      |                        |
      |                        const AVOutputFormat*
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp:126:32: warning: invalid conversion from ‘const AVCodec*’ to ‘AVCodec*’ [-fpermissive]
  126 |   pCodec = avcodec_find_encoder(pFormatCtx->oformat->video_codec);
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                |
      |                                const AVCodec*
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp:139:25: error: ‘struct AVStream’ has no member named ‘codec’
  139 |   pCodecCtx = video_st->codec;
      |                         ^~~~~
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp: In member function ‘bool sibr::FFVideoEncoder::encode(AVFrame*)’:
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp:234:13: error: ‘avcodec_encode_video2’ was not declared in this scope; did you mean ‘avcodec_encode_subtitle’?
  234 |   int ret = avcodec_encode_video2(pCodecCtx, pkt, frameYUV, &got_picture);
      |             ^~~~~~~~~~~~~~~~~~~~~
      |             avcodec_encode_subtitle
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp: In member function ‘void sibr::FFVideoEncoder::init(const Vector2i&)’:
/home/mrpibb/gaussian-splatting/SIBR_viewers/src/core/video/FFmpegVideoEncoder.cpp:169:24: warning: ignoring return value of ‘int avformat_write_header(AVFormatContext*, AVDictionary**)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  169 |   avformat_write_header(pFormatCtx, NULL);
      |   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
gmake[2]: *** [src/core/video/CMakeFiles/sibr_video.dir/build.make:76: src/core/video/CMakeFiles/sibr_video.dir/FFmpegVideoEncoder.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1239: src/core/video/CMakeFiles/sibr_video.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

dialectrics avatar Aug 30 '23 22:08 dialectrics

same problem, I used ubuntu 22, cuda 11.8 gcc 9.0 and tried several older version of ffmpeg. and basic these four errors:

‘av_register_all’ was not declared in this scope error: ‘struct AVStream’ has no member named ‘codec’ error: ‘avcodec_encode_video2’ was not declared in this scope; did you mean ‘avcodec_encode_subtitle’?

qgli avatar Sep 06 '23 00:09 qgli

Also same problem, Ubuntu 22, cuda 11.8. The problem seems to be in the FFmpeg C++ file, which is based off of a 7 year old extremely outdated file (found link in the header file)

Ednaordinary avatar Sep 13 '23 05:09 Ednaordinary

I solved the problem, but since I cannot access the original Gitlab of the SIBR viewer, I can only publish my solution here. I'd appreciate if anyone could contact the author team of the SIBR viewer.
FFmpegVideoEncoder.zip

The solution is to replace the FFmpegVideoEncoder.cpp file under SIBR_viewers/src/core/video folder and compile again.

I hope the author notices this problem ASAP.

qgli avatar Sep 19 '23 02:09 qgli

This fix seemed to work for me

Ednaordinary avatar Sep 27 '23 03:09 Ednaordinary

Here is @qgli's changes as a patch file (in case it helps others quickly get up and running in Ubuntu 22.04:

diff --git a/src/core/video/FFmpegVideoEncoder.cpp b/src/core/video/FFmpegVideoEncoder.cpp
index d908531..0fbba4f 100644
--- a/src/core/video/FFmpegVideoEncoder.cpp
+++ b/src/core/video/FFmpegVideoEncoder.cpp
@@ -43,7 +43,7 @@ namespace sibr {
 			SIBR_LOG << "[FFMPEG] Registering all." << std::endl;
 			// Ignore next line warning.
 #pragma warning(suppress : 4996)
-			av_register_all();
+			//av_register_all();
 			ffmpegInitDone = true;
 		}
 		
@@ -74,18 +74,18 @@ namespace sibr {
 	void FFVideoEncoder::close()
 	{
 #ifndef HEADLESS
-		if (av_write_trailer(pFormatCtx) < 0) {
-			SIBR_WRG << "[FFMPEG] Can not av_write_trailer " << std::endl;
-		}
-
-		if (video_st) {
-			avcodec_close(video_st->codec);
-			av_free(frameYUV);
-		}
-		avio_close(pFormatCtx->pb);
-		avformat_free_context(pFormatCtx);
-
-		needFree = false;
+    if (av_write_trailer(pFormatCtx) < 0) {
+        SIBR_WRG << "[FFMPEG] Can not av_write_trailer " << std::endl;
+    }
+
+    if (video_st) {
+        avcodec_free_context(&pCodecCtx); // 释放AVCodecContext
+        av_free(frameYUV);
+    }
+    avio_close(pFormatCtx->pb);
+    avformat_free_context(pFormatCtx);
+
+    needFree = false;
 #endif
 	}
 
@@ -97,95 +97,96 @@ namespace sibr {
 
 	}
 
-	void FFVideoEncoder::init(const sibr::Vector2i & size)
-	{
+void FFVideoEncoder::init(const sibr::Vector2i & size)
+{
 #ifndef HEADLESS
-		w = size[0];
-		h = size[1];
-
-		auto out_file = filepath.c_str();
-
-
-		pFormatCtx = avformat_alloc_context();
-
-		fmt = av_guess_format(NULL, out_file, NULL);
-		pFormatCtx->oformat = fmt;
-
-		const bool isH264 = pFormatCtx->oformat->video_codec == AV_CODEC_ID_H264;
-		if(isH264){
-			SIBR_LOG << "[FFMPEG] Found H264 codec." << std::endl;
-		} else {
-			SIBR_LOG << "[FFMPEG] Found codec with ID " << pFormatCtx->oformat->video_codec << " (not H264)." << std::endl;
-		}
-		
-		if (avio_open(&pFormatCtx->pb, out_file, AVIO_FLAG_READ_WRITE) < 0) {
-			SIBR_WRG << "[FFMPEG] Could not open file " << filepath << std::endl;
-			return;
-		}
-
-		pCodec = avcodec_find_encoder(pFormatCtx->oformat->video_codec);
-		if (!pCodec) {
-			SIBR_WRG << "[FFMPEG] Could not find codec." << std::endl;
-			return;
-		}
-
-		video_st = avformat_new_stream(pFormatCtx, pCodec);
-
-		if (video_st == NULL) {
-			SIBR_WRG << "[FFMPEG] Could not create stream." << std::endl;
-			return;
-		}
-
-		pCodecCtx = video_st->codec;
-		pCodecCtx->codec_id = fmt->video_codec;
-		pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
-		pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
-		pCodecCtx->width = w;
-		pCodecCtx->height = h;
-		pCodecCtx->gop_size = 10;
-		pCodecCtx->time_base.num = 1;
-		pCodecCtx->time_base.den = (int)std::round(fps);
-
-		// Required for the header to be well-formed and compatible with Powerpoint/MediaPlayer/...
-		if (pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER) {
-			pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
-		}
-
-		//H.264 specific options.
-		AVDictionary *param = 0;
-		if (pCodecCtx->codec_id == AV_CODEC_ID_H264) {
-			av_dict_set(&param, "preset", "slow", 0);
-			av_dict_set(&param, "tune", "zerolatency", 0);
-		}
-
-		av_dump_format(pFormatCtx, 0, out_file, 1);
-
-		int res = avcodec_open2(pCodecCtx, pCodec, &param);
-		if(res < 0){
-			SIBR_WRG << "[FFMPEG] Failed to open encoder, error: " << res << std::endl;
-			return;
-		}
-		// Write the file header.
-		avformat_write_header(pFormatCtx, NULL);
-
-		// Prepare the scratch frame.
-		frameYUV = av_frame_alloc();
-		frameYUV->format = (int)pCodecCtx->pix_fmt;
-		frameYUV->width = w;
-		frameYUV->height = h;
-		frameYUV->linesize[0] = w;
-		frameYUV->linesize[1] = w / 2;
-		frameYUV->linesize[2] = w / 2;
-
-		yuSize[0] = frameYUV->linesize[0] * h;
-		yuSize[1] = frameYUV->linesize[1] * h / 2;
-
-		pkt = av_packet_alloc();
-
-		initWasFine = true;
-		needFree = true;
+    w = size[0];
+    h = size[1];
+
+    auto out_file = filepath.c_str();
+
+    pFormatCtx = avformat_alloc_context();
+    fmt = av_guess_format(NULL, out_file, NULL);
+    pFormatCtx->oformat = fmt;
+
+    if (avio_open(&pFormatCtx->pb, out_file, AVIO_FLAG_READ_WRITE) < 0) {
+        SIBR_WRG << "[FFMPEG] Could not open file " << filepath << std::endl;
+        return;
+    }
+
+    pCodec = avcodec_find_encoder(pFormatCtx->oformat->video_codec);
+    if (!pCodec) {
+        SIBR_WRG << "[FFMPEG] Could not find codec." << std::endl;
+        return;
+    }
+
+    video_st = avformat_new_stream(pFormatCtx, pCodec);
+    if (video_st == NULL) {
+        SIBR_WRG << "[FFMPEG] Could not create stream." << std::endl;
+        return;
+    }
+
+    // This is the major change.
+    pCodecCtx = avcodec_alloc_context3(pCodec);
+    if (!pCodecCtx) {
+        SIBR_WRG << "[FFMPEG] Could not allocate codec context." << std::endl;
+        return;
+    }
+
+    pCodecCtx->codec_id = fmt->video_codec;
+    pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
+    pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
+    pCodecCtx->width = w;
+    pCodecCtx->height = h;
+    pCodecCtx->gop_size = 10;
+    pCodecCtx->time_base.num = 1;
+    pCodecCtx->time_base.den = (int)std::round(fps);
+
+    // Required for the header to be well-formed and compatible with Powerpoint/MediaPlayer/...
+    if (pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER) {
+        pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
+    }
+
+    //H.264 specific options.
+    AVDictionary *param = 0;
+    if (pCodecCtx->codec_id == AV_CODEC_ID_H264) {
+        av_dict_set(&param, "preset", "slow", 0);
+        av_dict_set(&param, "tune", "zerolatency", 0);
+    }
+
+    av_dump_format(pFormatCtx, 0, out_file, 1);
+
+    int res = avcodec_open2(pCodecCtx, pCodec, &param);
+    if(res < 0){
+        SIBR_WRG << "[FFMPEG] Failed to open encoder, error: " << res << std::endl;
+        return;
+    }
+    // Associating the codec context with the stream.
+    video_st->codecpar = avcodec_parameters_alloc();
+	avcodec_parameters_from_context(video_st->codecpar, pCodecCtx);
+
+
+    // Write the file header.
+    avformat_write_header(pFormatCtx, NULL);
+
+    // Prepare the scratch frame.
+    frameYUV = av_frame_alloc();
+    frameYUV->format = (int)pCodecCtx->pix_fmt;
+    frameYUV->width = w;
+    frameYUV->height = h;
+    frameYUV->linesize[0] = w;
+    frameYUV->linesize[1] = w / 2;
+    frameYUV->linesize[2] = w / 2;
+
+    yuSize[0] = frameYUV->linesize[0] * h;
+    yuSize[1] = frameYUV->linesize[1] * h / 2;
+
+    pkt = av_packet_alloc();
+
+    initWasFine = true;
+    needFree = true;
 #endif
-	}
+}
 
 
 	bool FFVideoEncoder::operator<<(cv::Mat frame)
@@ -227,23 +228,32 @@ namespace sibr {
 	}
 
 #ifndef HEADLESS
-	bool FFVideoEncoder::encode(AVFrame * frame)
-	{
-		int got_picture = 0;
-
-		int ret = avcodec_encode_video2(pCodecCtx, pkt, frameYUV, &got_picture);
-		if (ret < 0) {
-			SIBR_WRG << "[FFMPEG] Failed to encode frame." << std::endl;
-			return false;
-		}
-		if (got_picture == 1) {
-			pkt->stream_index = video_st->index;
-			ret = av_write_frame(pFormatCtx, pkt);
-			av_packet_unref(pkt);
-		}
-
-		return true;
-	}
+bool FFVideoEncoder::encode(AVFrame * frame)
+{
+    int ret;
+
+    // Send the frame for encoding
+    ret = avcodec_send_frame(pCodecCtx, frameYUV);
+    if (ret < 0) {
+        SIBR_WRG << "[FFMPEG] Failed to send frame for encoding." << std::endl;
+        return false;
+    }
+
+    // Receive the encoded packet
+    ret = avcodec_receive_packet(pCodecCtx, pkt);
+    if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
+        SIBR_WRG << "[FFMPEG] Failed to receive encoded packet." << std::endl;
+        return false;
+    }
+    if (ret >= 0) {
+        pkt->stream_index = video_st->index;
+        ret = av_write_frame(pFormatCtx, pkt);
+        av_packet_unref(pkt);
+    }
+
+    return true;
+}
 #endif
 
+
 }

jasonsperske avatar Sep 30 '23 04:09 jasonsperske

Hello, I have same error but I am using ubuntu 18.04 and it's on school server so I can not do anything about that. I tried to compile after replacing the file but the issue persists, Could anyone please help I have never worked with these kind of files so I am really stuck. Thanks.

maryamkqamar avatar Mar 22 '24 03:03 maryamkqamar

I'm also experiencing this problem, how did you fix it? I downloaded the latest source code.

a4152684 avatar Apr 02 '24 06:04 a4152684