Display USB camera on ubuntu22 with Qt
OS: Ubuntu 22.04.3
Qt Creator 4.11.1, Qt 5.14.1, GCC 5.3.1
There are 2 way to use:
(1) overlay
(2) QVideoWidget
From QT5.12.2, there is a quick call.
QMediaplayer->setMedia(QUrl("gst-pipeline: videotestsrc ! videoconvert ! xvimagesink name=\"qtvideosink\""));
Overlay and USB camera
QVideoWidget and videotestsrc
QVideoWidget and USB camera
sudo apt-get update
sudo apt-get install libqt5widgets5
sudo apt-get install libqt5multimedia5 libqt5multimediawidgets5
sudo apt-get install libqt5multimedia5-plugins
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libfontconfig1
sudo apt-get install mesa-common-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install libx11-dev libxext-dev libxtst-dev
download and install qt-opensource-linux-x64-5.14.2.run
sudo apt-get install libqt5widgets5
sudo apt-get install libqt5multimedia5 libqt5multimediawidgets5
sudo apt-get install libqt5multimedia5-plugins
sudo apt-get install libqt5gstreamer-dev
ASUS S501MER RTX5060 NVIDIA
OS: Ubuntu 22.04.3
sudo apt-get update
sudo apt-get install libc-dev -y
sudo apt-get install linux-headers-$(uname -r) -y
sudo apt-get install ubuntu-drivers-common -y
sudo apt-get install nvidia-driver-550 -y
sudo apt-get -y install \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
gstreamer1.0-tools \
gstreamer1.0-x \
gstreamer1.0-alsa \
gstreamer1.0-gl \
gstreamer1.0-gtk3 \
gstreamer1.0-qt5 \
gstreamer1.0-pulseaudio
在Ubuntu, 要讓程式開機自動啟動, 方法之一是用systemd服務.
在/lib/systemd/system加個文字檔.
若是程式是有視窗與聲音的, 還要加環境參數
User=gcat
Group=gcat
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/gcat/.Xauthority
Environment=XDG_RUNTIME_DIR=/run/user/1000
Environment=QT_QPA_PLATFORM=xcb
[Unit]
Description=autorun test09
After=multi-user.target
Wants=multi-user.target
#After=graphical.target
[Service]
#ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/test09
Restart=no
User=gcat
Group=gcat
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/gcat/.Xauthority
Environment=XDG_RUNTIME_DIR=/run/user/1000
Environment=QT_QPA_PLATFORM=xcb
[Install]
WantedBy=multi-user.target