Ubuntu 14.04編譯opencv_videoio.dir/src/cap_gstreamer.cpp報錯
阿新 • • 發佈:2018-12-17
今天在研究AR_ToolKit,它需要搭建OpenCV的環境。於是下載了OpenCV的原始碼進行編譯(下載方法就是直接git克隆git clone https://github.com/opencv/opencv)。
編譯opencv的過程中,一開始都一帆風順,不過後來遇到了以下問題:
[ 49%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_gstreamer.cpp.o In file included from /usr/include/gstreamer-0.10/gst/pbutils/encoding-profile.h:29:0, from /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp:69: /usr/include/gstreamer-0.10/gst/pbutils/gstdiscoverer.h:35:9: error: ‘GstMiniObjectClass’ does not name a type typedef GstMiniObjectClass GstDiscovererStreamInfoClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/gstdiscoverer.h:83:9: error: ‘GstMiniObjectClass’ does not name a type typedef GstMiniObjectClass GstDiscovererContainerInfoClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/gstdiscoverer.h:104:9: error: ‘GstMiniObjectClass’ does not name a type typedef GstMiniObjectClass GstDiscovererAudioInfoClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/gstdiscoverer.h:129:9: error: ‘GstMiniObjectClass’ does not name a type typedef GstMiniObjectClass GstDiscovererVideoInfoClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/gstdiscoverer.h:159:9: error: ‘GstMiniObjectClass’ does not name a type typedef GstMiniObjectClass GstDiscovererSubtitleInfoClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/gstdiscoverer.h:202:9: error: ‘GstMiniObjectClass’ does not name a type typedef GstMiniObjectClass GstDiscovererInfoClass; ^ In file included from /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp:69:0: /usr/include/gstreamer-0.10/gst/pbutils/encoding-profile.h:47:9: error: ‘GstMiniObjectClass’ does not name a type typedef GstMiniObjectClass GstEncodingProfileClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/encoding-profile.h:66:9: error: ‘GstEncodingProfileClass’ does not name a type typedef GstEncodingProfileClass GstEncodingContainerProfileClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/encoding-profile.h:85:9: error: ‘GstEncodingProfileClass’ does not name a type typedef GstEncodingProfileClass GstEncodingVideoProfileClass; ^ /usr/include/gstreamer-0.10/gst/pbutils/encoding-profile.h:104:9: error: ‘GstEncodingProfileClass’ does not name a type typedef GstEncodingProfileClass GstEncodingAudioProfileClass; ^ /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp: In member function ‘virtual bool GStreamerCapture::grabFrame()’: /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp:268:57: error: ‘gst_app_sink_pull_sample’ was not declared in this scope sample = gst_app_sink_pull_sample(GST_APP_SINK(sink)); ^ /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp: In member function ‘virtual bool CvVideoWriter_GStreamer::open(const char*, int, double, CvSize, bool)’: /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp:1515:25: error: ‘GST_VIDEO_FORMAT_ENCODED’ was not declared in this scope input_pix_fmt = GST_VIDEO_FORMAT_ENCODED; ^ /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp: In member function ‘virtual bool CvVideoWriter_GStreamer::writeFrame(const IplImage*)’: /home/leon/open_source/opencv/modules/videoio/src/cap_gstreamer.cpp:1686:26: error: ‘GST_VIDEO_FORMAT_ENCODED’ was not declared in this scope if (input_pix_fmt == GST_VIDEO_FORMAT_ENCODED) { ^ make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_gstreamer.cpp.o] 錯誤 1 make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] 錯誤 2 make: *** [all] 錯誤 2
提取其中一句來看看:
/usr/include/gstreamer-0.10/gst/pbutils/gstdiscoverer.h:202:9: error: ‘GstMiniObjectClass’ does not name a type
typedef GstMiniObjectClass GstDiscovererInfoClass;
很明顯,與gstreamer-0.10有關。再去分析下CMakeList檔案,以gstreamer為關鍵詞查詢,發現有如下命令:
OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT ANDROID) ) OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF ) OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) )
可以看出,這就明確表示了cmakelist必須依賴於gstreamer-0.10。這裡順便介紹一下gstreamer-0.10,根據百度百科,GStreamer是用來構建流媒體應用的開源多媒體框架(framework),其目標是要簡化音/視訊應用程式的開發,目前已經能夠被用來處理像 MP3、Ogg、MPEG1、MPEG2、AVI、Quicktime 等多種格式的多媒體資料。在linux中,進行視訊處理的時候,有時候我們需要讀入各種各樣格式的視訊。在沒有相應的解碼器的時候,我們是無法正確讀入資料的,所以要正確安裝gstreamer才能實現各種格式視訊的正確讀取。
於是,乖乖的安裝吧:
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
裝完,再編譯,一切OK啦!