본문 바로가기
SWE/스트리밍

qt-gstreamer 예제 player 실행해보기 | 설치 및 환경설정

by S나라라2 2022. 7. 18.
반응형

 

 

Qt-GStreamer 예제 Player 실행해보기

 

 

Qt GUI에 Gstreamer를 이용해서 비디오 스트리밍을 해보려고 한다. 

 

 

찾을수록 GStreamer와 Qt를 선택한 것을 후회했다.... 

왜냐하면 아래 공홈에서 말하듯이, QtGStreamer C++ 바인딩은 굉장히 오래됐고 관리되지 않고 있다.

마지막 release가 2014년이다.(qt-gstreamer-1.2.0)

 

 


그래도 일단 해보자!!

 

qt-gstreamer 예제 프로그램 player를 실행하기 위해 아래와 같은 과정을 거친다.

1. qt-gstreamer 설치

2. Dependency 확인

   2-1. cmake 버전확인

   2-2. gstreamer 버전 확인

   2-3. Qt 버전 확인

      Ubuntu20.04.1에 Qt4 설치

   2-4. Boost library 설치 확인

      Ubuntu20.04.1에 boost library 설치

3. 빌드 에러 잡기위해 코드 수정

4. player 빌드 및 실행

 


 

1. qt-gstreamer 설치

https://gstreamer.freedesktop.org/src/qt-gstreamer/

 qt-gstreamer-1.2.0.tar.xz를 설치했다. 압축을 해제한다.

 

2. Dependency 확인

2-1. cmake 버전확인

-> cmake 2.8.9 이상이어야 한다.

$ cmake --version

cmake version 3.16.3

 

2-2. gstreamer 버전 확인

-> gstreamer 1.0.0 이상, gstreamer--plugins-base 1.0.0 이상이어야 한다.

$ dpkg -l | grep gstreamer

ii  gir1.2-gstreamer-1.0:amd64                 1.16.2-2                            amd64        GObject introspection data for the GStreamer library

ii  gstreamer1.0-alsa:amd64                    1.16.2-4ubuntu0.1                   amd64        GStreamer plugin for ALSA

ii  gstreamer1.0-clutter-3.0:amd64             3.0.27-1                            amd64        Clutter PLugin for GStreamer 1.0

ii  gstreamer1.0-doc                           1.16.2-2                            all          GStreamer core documentation and manuals

ii  gstreamer1.0-gl:amd64                      1.16.2-4ubuntu0.1                   amd64        GStreamer plugins for GL

ii  gstreamer1.0-gtk3:amd64                    1.16.2-1ubuntu2.1                   amd64        GStreamer plugin for GTK+3

ii  gstreamer1.0-libav:amd64                   1.16.2-2                            amd64        ffmpeg plugin for GStreamer

ii  gstreamer1.0-packagekit                    1.1.13-2ubuntu1.1                   amd64        GStreamer plugin to install codecs using PackageKit

ii  gstreamer1.0-plugins-bad:amd64             1.16.2-2.1ubuntu1                   amd64        GStreamer plugins from the "bad" set

ii  gstreamer1.0-plugins-base:amd64            1.16.2-4ubuntu0.1                   amd64        GStreamer plugins from the "base" set

ii  gstreamer1.0-plugins-base-apps             1.16.2-4ubuntu0.1                   amd64        GStreamer helper programs from the "base" set

ii  gstreamer1.0-plugins-good:amd64            1.16.2-1ubuntu2.1                   amd64        GStreamer plugins from the "good" set

ii  gstreamer1.0-plugins-ugly:amd64            1.16.2-2build1                      amd64        GStreamer plugins from the "ugly" set

ii  gstreamer1.0-pulseaudio:amd64              1.16.2-1ubuntu2.1                   amd64        GStreamer plugin for PulseAudio

ii  gstreamer1.0-qt5:amd64                     1.16.2-1ubuntu2.1                   amd64        GStreamer plugin for Qt5

ii  gstreamer1.0-tools                         1.16.2-2                            amd64        Tools for use with GStreamer

ii  gstreamer1.0-x:amd64                       1.16.2-4ubuntu0.1                   amd64        GStreamer plugins for X11 and Pango

ii  libgstreamer-gl1.0-0:amd64                 1.16.2-4ubuntu0.1                   amd64        GStreamer GL libraries

ii  libgstreamer-opencv1.0-0:amd64             1.16.2-2.1ubuntu1                   amd64        GStreamer OpenCV libraries

ii  libgstreamer-plugins-bad1.0-0:amd64        1.16.2-2.1ubuntu1                   amd64        GStreamer libraries from the "bad" set

ii  libgstreamer-plugins-bad1.0-dev:amd64      1.16.2-2.1ubuntu1                   amd64        GStreamer development files for libraries from the "bad" set

ii  libgstreamer-plugins-base1.0-0:amd64       1.16.2-4ubuntu0.1                   amd64        GStreamer libraries from the "base" set

ii  libgstreamer-plugins-base1.0-dev:amd64     1.16.2-4ubuntu0.1                   amd64        GStreamer development files for libraries from the "base" set

ii  libgstreamer-plugins-good1.0-0:amd64       1.16.2-1ubuntu2.1                   amd64        GStreamer development files for libraries from the "good" set

ii  libgstreamer-plugins-good1.0-dev           1.16.2-1ubuntu2.1                   amd64        GStreamer development files for libraries from the "good" set

ii  libgstreamer1.0-0:amd64                    1.16.2-2                            amd64        Core GStreamer libraries and elements

ii  libgstreamer1.0-dev:amd64                  1.16.2-2                            amd64        GStreamer core development files

 

 

2-3. Qt 버전 확인

-> Qt4를 추천한다.

Qt 5도 가능하다고 하지만 막상 Qt5.12.8로 빌드하니까 에러가 나온다.

Qt 5.6이상부터 사용되지 않는 모듈(Declarative)을 사용하고 있기 때문에 나오는 에러였다.

 

Ubuntu20.04.1에 Qt4 설치

#1. repository 추가
$sudo add-apt-repository ppa:rock-core/qt4
$sudo apt update

#2. Qt4설치
$sudo apt install qt4-dev-tools qt4-qmake libqt4-dev
$sudo apt install qtcreator

#3. Qt4를 디폴트로 설치
$sudo apt install qt4-default
$ qmake -v
QMake version 2.01a
Using Qt version 4.8.7 in /usr/lib/x86_64-linux-gnu

#4.qml 설치
$sudo apt-get install -y qt4-qmlviewer

처음에 qt4-qmlviewer를 설치하지 않았었더니 아래와 같은 빌드 로그가 나왔었다.

Found Qt4or5: TRUE  found components: Core Gui Widgets OpenGL Quick1 Test missing components: Quick2 Qml

 

 

2-4. Boost library 설치 확인

설치 확인 하는 방법 2가지

#방법1. dpkg
$ dpkg -s libboost-dev | grep 'Version'
dpkg-query: package 'libboost-dev' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files.

#방법2. /user/include에서 확인
$ cat /user/include/boost/version.hpp | grep "BOOST_LIB_VERSION"
cat: /user/include/boost/version.hpp: No such file or directory

boost library가 pc에 없는 경우 위와 같은 로그가 나온다.

 

Ubuntu20.04.1에 boost library 설치

$sudo apt-get update
$ wget -c 'https://sourceforge.net/projects/boost/files/boost/1.78.0/boost_1_78_0.tar.bz2/download'  // 1.79.0 가장 최신
$ tar -xvf download
$ cd boost_1_78_0/
$ ./bootstrap.sh 

$su root // super user 권한으로 아래 명령어 실행
#./b2 install   // 안하면 Cp permission denied 나옴


에러 : ./boost/python/detail/wrap_python.hpp:57:11: fatal error: pyconfig.h: No such file or directory
	->  $ find /usr/include -name pyconfig.h 
		Python-dev 설치 안되어있음.
	->  $sudo apt-get install python-dev // python-dev 설치

python-dev가 설치 안되어 있었어서 설치 중간에 위와 같은 에러가 나왔다. python-dev를 설치 후에 

./b2 install 을 다시 실행했다.

 

완료하면 아래 위치에 boost가 설치된 것을 확인할 수 있다.

/usr/local/include

/usr/local/lib

 

 

3. 빌드 에러 잡기위해 코드 수정

 

에러: message.cpp cannot convert ...

# 에러 내용
/home/hwayoung/workplace/qt-gstreamer-1.2.0.tar/qt-gstreamer-1.2.0/qt-gstreamer-1.2.0/src/QGst/message.cpp:161:67: error: cannot convert ‘const QGst::TagList*’ to ‘const GstTagList*’ {aka ‘const _GstTagList*’}
  161 |     GstMessage *m = gst_message_new_tag(source, gst_tag_list_copy(&taglist));
      |                                                                   ^~~~~~~~
      |                                                                   |
      |                                                                   const QGst::TagList*

수정 방법

void Caps::append(const CapsPtr & caps2)
{
    //gst_caps_append(object<GstCaps>(), gst_caps_copy(caps2)); // 기존 코드
    // 아래 추가
    const GstCaps * caps2ptr = caps2; 
    gst_caps_append(object<GstCaps>(), gst_caps_copy(caps2ptr));
}

출처 : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=941867

 

 

위의 과정을 모두 거치면 cmake 실행에서 아무 에러도 나오지 않게 된다!! 성-공-

더보기

hwayoung@hwayoung-laptop:~/workplace/qt-gstreamer-1.2.0.tar/qt-gstreamer-1.2.0/qt-gstreamer-1.2.0/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using Qt4 (min: 4.7)
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - found
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - not found
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found
-- Found Qt4: /usr/bin/qmake (found suitable version "4.8.7", minimum required is "4.7") 
-- Found Qt4or5: TRUE  found components: Core Gui Widgets OpenGL Quick1 Test missing components: Quick2 Qml
-- Found Boost: /usr/local/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.39")  
-- GCC 4.5 or later detected. Enabling C++0x support in QTGSTREAMER_FLAGS.
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'gstreamer-1.0'
--   Found gstreamer-1.0, version 1.16.2
-- Checking for module 'gstreamer-base-1.0'
--   Found gstreamer-base-1.0, version 1.16.2
-- Found GSTREAMER_BASE_LIBRARY: /usr/lib/x86_64-linux-gnu/libgstbase-1.0.so
-- Found GSTREAMER_BASE_INCLUDE_DIR: /usr/include/gstreamer-1.0
-- Found GStreamer: /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so (Required is at least version "1.0.0") 
-- Checking for module 'gstreamer-plugins-base-1.0'
--   Found gstreamer-plugins-base-1.0, version 1.16.2
-- Checking for module 'gstreamer-app-1.0'
--   Found gstreamer-app-1.0, version 1.16.2
-- Found GSTREAMER_APP_LIBRARY: /usr/lib/x86_64-linux-gnu/libgstapp-1.0.so
-- Found GSTREAMER_APP_INCLUDE_DIR: /usr/include/gstreamer-1.0
-- Checking for module 'gstreamer-audio-1.0'
--   Found gstreamer-audio-1.0, version 1.16.2
-- Found GSTREAMER_AUDIO_LIBRARY: /usr/lib/x86_64-linux-gnu/libgstaudio-1.0.so
-- Found GSTREAMER_AUDIO_INCLUDE_DIR: /usr/include/gstreamer-1.0
-- Checking for module 'gstreamer-video-1.0'
--   Found gstreamer-video-1.0, version 1.16.2
-- Found GSTREAMER_VIDEO_LIBRARY: /usr/lib/x86_64-linux-gnu/libgstvideo-1.0.so
-- Found GSTREAMER_VIDEO_INCLUDE_DIR: /usr/include/gstreamer-1.0
-- Checking for module 'gstreamer-pbutils-1.0'
--   Found gstreamer-pbutils-1.0, version 1.16.2
-- Found GSTREAMER_PBUTILS_LIBRARY: /usr/lib/x86_64-linux-gnu/libgstpbutils-1.0.so
-- Found GSTREAMER_PBUTILS_INCLUDE_DIR: /usr/include/gstreamer-1.0
-- Found GStreamerPluginsBase: TRUE (Required is at least version "1.0.0") 
-- Checking for module 'glib-2.0'
--   Found glib-2.0, version 2.64.6
-- Found GLIB2: /usr/lib/x86_64-linux-gnu/libglib-2.0.so  
-- Checking for module 'gobject-2.0'
--   Found gobject-2.0, version 2.64.6
-- Found GObject: /usr/include/glib-2.0  
-- Performing Test USE_OPENGLES
-- Performing Test USE_OPENGLES - Failed
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
  Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
  available.  Run "cmake --help-policy CMP0072" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  FindOpenGL found both a legacy GL library:

    OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so

  and GLVND libraries for OpenGL and GLX:

    OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
    OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so

  OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
  compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
  CMakeLists.txt:124 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so   
CMake Warning (dev) at examples/CMakeLists.txt:13 (get_target_property):
  Policy CMP0045 is not set: Error on non-existent target in
  get_target_property.  Run "cmake --help-policy CMP0045" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  get_target_property() called with non-existent target "examples_distcheck".
Call Stack (most recent call first):
  examples/CMakeLists.txt:22 (example_distcheck)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 

-----------------------------------------------------------------------------
-- The following external packages were located on your system.
-- This installation will have the extra features provided by these packages.
-----------------------------------------------------------------------------
   * Qt - Required for building everything
   * QtOpenGL - Required for OpenGL acceleration in qtvideosink and QtGStreamerUi
   * QtQuick1 (QtDeclarative) - Required for building QtQuick1 support
   * Boost - Required for building QtGLib
   * GStreamer - Required to build QtGStreamer
   * GStreamer base library - Used for building the qtvideosink element
   * GStreamer app library - Required to build QtGStreamerUtils
   * GStreamer audio library - Required to build QtGStreamer
   * GStreamer video library - Required to build QtGStreamer
   * GStreamer pbutils library - Used for building the Discoverer API
   * GLib - Required to build QtGLib
   * GObject - Required to build QtGLib
   * OpenGL - Required for OpenGL rendering support in qtvideosink

-----------------------------------------------------------------------------
-- The following OPTIONAL packages could NOT be located on your system.
-- Consider installing them to enable more features from this software.
-----------------------------------------------------------------------------
   * Doxygen  <http://www.doxygen.org/>
     Used to generate the API documentation

-----------------------------------------------------------------------------

-- Configuring done
CMake Warning (dev) in src/QGlib/CMakeLists.txt:
  Policy CMP0071 is not set: Let AUTOMOC and AUTOUIC process GENERATED files.
  Run "cmake --help-policy CMP0071" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  For compatibility, CMake is excluding the GENERATED source file(s):

    "/home/hwayoung/workplace/qt-gstreamer-1.2.0.tar/qt-gstreamer-1.2.0/qt-gstreamer-1.2.0/build/src/QGlib/gen.cpp"

  from processing by AUTOMOC.  If any of the files should be processed, set
  CMP0071 to NEW.  If any of the files should not be processed, explicitly
  exclude them by setting the source file property SKIP_AUTOMOC:

    set_property(SOURCE file.h PROPERTY SKIP_AUTOMOC ON)

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) in src/QGst/CMakeLists.txt:
  Policy CMP0071 is not set: Let AUTOMOC and AUTOUIC process GENERATED files.
  Run "cmake --help-policy CMP0071" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  For compatibility, CMake is excluding the GENERATED source file(s):

    "/home/hwayoung/workplace/qt-gstreamer-1.2.0.tar/qt-gstreamer-1.2.0/qt-gstreamer-1.2.0/build/src/QGst/gen.cpp"

  from processing by AUTOMOC.  If any of the files should be processed, set
  CMP0071 to NEW.  If any of the files should not be processed, explicitly
  exclude them by setting the source file property SKIP_AUTOMOC:

    set_property(SOURCE file.h PROPERTY SKIP_AUTOMOC ON)

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) in elements/gstqtvideosink/CMakeLists.txt:
  Policy CMP0071 is not set: Let AUTOMOC and AUTOUIC process GENERATED files.
  Run "cmake --help-policy CMP0071" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  For compatibility, CMake is excluding the GENERATED source file(s):

    "/home/hwayoung/workplace/qt-gstreamer-1.2.0.tar/qt-gstreamer-1.2.0/qt-gstreamer-1.2.0/build/elements/gstqtvideosink/gstqtvideosinkmarshal.c"
    "/home/hwayoung/workplace/qt-gstreamer-1.2.0.tar/qt-gstreamer-1.2.0/qt-gstreamer-1.2.0/build/elements/gstqtvideosink/gstqtvideosinkmarshal.h"

  from processing by AUTOMOC.  If any of the files should be processed, set
  CMP0071 to NEW.  If any of the files should not be processed, explicitly
  exclude them by setting the source file property SKIP_AUTOMOC:

    set_property(SOURCE file.h PROPERTY SKIP_AUTOMOC ON)

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /home/hwayoung/workplace/qt-gstreamer-1.2.0.tar/qt-gstreamer-1.2.0/qt-gstreamer-1.2.0/build

 

 

4. player 빌드 및 실행

내가 실행해보고싶은 예제인 Player 폴더에 Makefile이 제대로 생성된 것을 확인할 수 있다.

위치 : qt-gstreamer-1.2.0/build/examples/player

 

빌드하기

$make

 

실행하기

$ ./player

실행하면 아래와 같은 player 프로그램이 뜬다.

 

신텔 트레일러 영상 재생시켜보기

하단 좌측의 파일모양의 버튼을 눌러서 pc에 설치되어 있는 영상을 선택한다.

 

 

*신텔 트레일러 비디오파일 다운받는 곳: https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm

 

 

 

반응형