I'm develop a Qt app for displaying my IP-CAMERA stream. It has code similar to this project :
https://github.com/cleitonbueno/qt-rtsp-test/tree/widgets
QVideoWidget *_vw1 = new QVideoWidget;
QMediaPlayer *_player1 = new QMediaPlayer;
QGridLayout *layout = new QGridLayout;
layout->addWidget(_vw1,0,0,1,1);
QWidget *win = new QWidget();
win->setLayout(layout);
setCentralWidget(win);
_player1->setVideoOutput(_vw1);
const QUrl url1 = QUrl("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov");
const QNetworkRequest requestRtsp1(url1);
_player1->setMedia(requestRtsp1);
_player1->play();
When i play Bigbuckbunny video, video's packet is coming and media player plays. But When i write ip camera's rtsp address in Qurl, Media player can't play this stream.
Capture made with Wireshark shows that the rtsp packets are received. But media player is seen black screen.
I'm using linux ubuntu 16.04 Gnome 3 (86_64 GNU/Linux)
QT 5.10.0
QT creator is 4.5
I remove ip camera's username and password. But I also tried with username and password (rtsp://192.168.1.1:554/live/stream1 && rtsp://username:password#192.168.1.1:554/live/stream1).
Can you please help me. I can't understand the root cause of this problem.
Related
Hello Techie's I am working on Qt QMediaPlayer and trying to play song through my local file but i don't know where I am getting wrong I am unable to play song on Window but the same code is working fine in Mac but not on window.
For all kind helps Thanks in advance.
I had tried this
player->setMedia(QUrl::fromLocalFile("<path to file>/test.mp3"));
and this as well
player->setMedia(QMediaContent(QUrl::fromLocalFile("<path to file>/test.mp3")));
Here's my complete code snippet:
QMediaPlayer *player = new QMediaPlayer();
player->setMedia(QUrl::fromLocalFile("<path to file>/test.mp3"));
player->setVolume(100);
player->play();
qDebug() << player->errorString();
No error listed, so its difficult to identify where I am getting wrong.
Have you try some path format, i had a similar experience with QMediaPlayer and i had to use path format like this some\\path\\exemple.mp3 or like this some//path//exemple.mp3 i don't remember exactly.
Maybe check QMediaPlayer exemple and try to run the exemple to check if is codec problem or a code problem.
Actually, I try in QTCreator to save a playlist into a multitude of format.
QTCreator save and load without problems the m3u format.
It either load a .pls file I written by hand, but it can't save a similar pls format (It create an empty "playlst.pls").
I used the example showed from this manual:
http://doc.qt.io/qt-5/qmediaplaylist.html#save
The code save the playlist in pls format, the file is created, but empty.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Player setting
player = new QMediaPlayer;
connect(player, SIGNAL(positionChanged(qint64)),
this, SLOT(positionChanged(qint64)));
player->setMedia(QUrl::fromLocalFile("/home/batfly/MilkyWay.mp3"));
player->setVolume(50);
player->play();
// Configure playlist:
playlist = new QMediaPlaylist;
playlist->addMedia(QUrl("file:///home/batfly/MilkyWay.mp3"));
playlist->addMedia(QUrl("file:///home/batfly/Gurdil.mp3"));
playlist->addMedia(QUrl("file:///home/batfly/OwenWasHere.mp3"));
playlist->setCurrentIndex(1);
// Set playlist on player:
player = new QMediaPlayer;
player->setPlaylist(playlist);
// Save playlist:
playlist->save(QUrl::fromLocalFile
("/home/batfly/playlisttest.pls"),"pls");
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
player->play();
}
Where is the problem?
QTCreator can't save into pls format, or I forget something?
Thank you!
PS: I add more information about my problem:
- I'm working in Linux (Debian 9.X).
- I use QTCreator 4.2, the last version have some bugs actually, so I don't update and keel the apt install version of Debian.
Here I read:
Embedded window video
--drawable-hwnd=<integer [-2147483648 .. 2147483647]>
Window handle (HWND)
Video will be embedded in this pre-existing window. If zero, a new window will be created.
I get the window handle of my Qt5 QML application in this way:
QObject* m_rootObject = engine.rootObjects().first();
if(m_rootObject) {
QWindow *window = qobject_cast<QWindow *>(m_rootObject);
if(window) {
WId wid = window->winId();
qDebug() << wid;
}
}
and then I launch vlc:
vlc --drawable-hwnd=395302 udp://#:1235
but it still creates a new window. I'm working on Windows 7.
Perhaps I'm not understanding what the documentation says?
I had the same problem with an RTSP stream.
Setting
--drawable-hwnd=windowhandle
seems not to be sufficient.
It only worked after I also set
--no-embedded-video
My complete command line looks like
--no-embedded-video --qt-notification=0 --qt-auto-raise=0 --qt-start-minimized --no-qt-name-in-title --no-video-title-show rtsp://127.0.0.1:8554/
I need to draw an oscillogram of audio track. The audio could be stored with video too. I play audio with such code:
QMediaPlayer* player = new QMediaPlayer;
//connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
player->setMedia(QUrl::fromLocalFile("/home/mikhail/Downloads/BRAT.mkv"));
player->play();
I need to play any of audio tracks in video file and display it's oscillogram.
How can I realize it?
I've found an example in Qt examples: http://doc.qt.io/qt-5/qtcharts-audio-example.html . That's what I need but the sound streams from micro. I'm new at Qt, although an example is simple, I can't understand how to replace data from micro with data from player.
I can guess that I need to replace QAudioInput:
QAudioFormat formatAudio;
formatAudio.setSampleRate(8000);
formatAudio.setChannelCount(1);
formatAudio.setSampleSize(8);
formatAudio.setCodec("audio/pcm");
formatAudio.setByteOrder(QAudioFormat::LittleEndian);
formatAudio.setSampleType(QAudioFormat::UnSignedInt);
QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice();
m_audioInput = new QAudioInput(inputDevices,formatAudio, this);
m_device = new XYSeriesIODevice(m_series, this);
m_device->open(QIODevice::WriteOnly);
m_audioInput->start(m_device);
But I can't find how to give to QAudioInput a buffer of raw data from QMediaPlayer.
Also I have working code to get raw data with ffmpeg, but I think it could be done with QMediaPlayer and it would be easier.
Thanks for any help!
I have a program that records video from a web camera. It shows the camera view in the form. When start button clicked it should start recording video and should be stopped after pressing stop button. Program compiles fine but no video is recorded. Can anyone say what is the wrong with it?
Here is my code.
{
camera = new QCamera(this);
viewFinder = new QCameraViewfinder(this);
camera->setViewfinder(viewFinder);
recorder = new QMediaRecorder(camera,this);
QBoxLayout *layout = new QVBoxLayout;
layout->addWidget(viewFinder);
ui->widget->setLayout(layout);
QVideoEncoderSettings settings = recorder->videoSettings();
settings.setResolution(640,480);
settings.setQuality(QMultimedia::VeryHighQuality);
settings.setFrameRate(30.0);
//settings.setCodec("video/mp4");
recorder->setVideoSettings(settings);
recorder->setContainerFormat("mp4");
camera->setCaptureMode(QCamera::CaptureVideo);
camera->start();
}
void usbrecorder::on_btn_Record_clicked()
{
usbrecorder::startRecording();
}
void usbrecorder::on_btn_Stop_clicked()
{
usbrecorder::stopRecording();
}
void usbrecorder::startRecording()
{
recorder->setOutputLocation(QUrl::fromLocalFile("C:\\Users\\Stranger\\Downloads\\Video\\vidoe_001.mp4"));
recorder->record();
}
void usbrecorder::stopRecording()
{
recorder->stop();
}
This is due to limitations on Windows.
As mentioned in Qt documentation here: https://doc.qt.io/qt-5/qtmultimedia-windows.html#limitations
Video recording is currently not supported. Additionally, the DirectShow plugin does not support any low-level video functionality such as monitoring video frames being played or recorded using QVideoProbe or related classes.
You need to specify an output location:
QMediaRecorder::setOutputLocation(const QUrl& location)
e.g.
setOutputLocation(QUrl("file:///home/user/vid.mp4"));
Try to print the state, status and error message:
qDebug()<<record.state();
qDebug()<<record.status();
qDebug()<<record.error();
and see what it prints. With those messages you can have a clear picture of your problem. Maybe QMediaRecorder cannot access your camera.