My organisation is using Qt 6.4.3 and using the Qt Multimedia(Widgets) module. Currently, I am unable to play any non-local files (http/https/rtsp/...) using the FFmpeg backend.
I have verified that the FFmpeg plugin loads with environment variable QT_DEBUG_PLUGINS=1
.
Here is the system environment:
Qt Version : 6.4.3
Operating System: Windows 10
Build tool : Visual Studio 2022 (MSBuild)
QT_MEDIA_BACKEND: "ffmpeg"
I've seen a lot of examples of issues similar to mine, but with no satisfactory solution:
Qt Forums:
- https://forum.qt.io/topic/145002/issues-with-using-qt-multimedia-with-ffmpeg-in-qt-6-5-audio-streaming-on-macos/7
- https://forum.qt.io/topic/135819/showing-video-from-a-rtsp-ip-camera
- https://forum.qt.io/topic/115988/qmedia-player-not-working
Stack Overflow:
- QMediaPlayer resource error
- Cant load music file with QMediaPlayer
- https://stackoverflow.com/search?q=QMediaPlayer+resource+error
Here is a minimum reproducible example:
// qt headers [omitted]
int main(int argc, char* argv[]) {
// Set environment variables (also in Windows Environment Variables)
qputenv("QT_MEDIA_BACKEND", "ffmpeg");
QApplication a(argc, argv);
std::array<QUrl, 2> testUrls = {{
// Local file works:
QUrl::fromUserInput(R"(C:\<Replace With Your Own Local MP4 file>)"),
// Remote URL fails in Qt, but loads in ffplay and vlc:
QUrl::fromUserInput("http://vjs.zencdn.net/v/oceans.mp4"),
}};
QComboBox *urlSelection = new QComboBox();
for (QUrl testUrl : testUrls)
{
urlSelection->addItem(testUrl.toString(), testUrl);
}
QPushButton *playButton = new QPushButton();
playButton->setText("PLAY");
QVideoWidget *videoWidget = new QVideoWidget();
videoWidget->setFixedSize(QSize(854, 480));
QAudioOutput *audioOutput = new QAudioOutput();
QMediaPlayer *mediaPlayer = new QMediaPlayer();
QObject::connect(playButton, &QPushButton::clicked, [=](bool) {
QUrl url = urlSelection->currentData().toUrl();
mediaPlayer->setSource(url);
mediaPlayer->setVideoOutput(videoWidget);
mediaPlayer->setAudioOutput(audioOutput);
mediaPlayer->play();
});
QWidget *widget = new QWidget();
widget->setLayout(new QVBoxLayout());
widget->layout()->addWidget(videoWidget);
widget->layout()->addWidget(urlSelection);
widget->layout()->addWidget(playButton);
QMainWindow *mainWindow = new QMainWindow();
mainWindow->setCentralWidget(widget);
mainWindow->show();
return a.exec();
}
The debug console produces the following log when accessing the remote url specified:
[ DEBUG: Player Status ] QMediaPlayer::LoadingMedia
[ DEBUG: Player Error ] QMediaPlayer::ResourceError "Could not open file"
[ DEBUG: Player Playback ] QMediaPlayer::PlayingState
[ DEBUG: Player Status ] QMediaPlayer::BufferedMedia
[ DEBUG: Player Status ] QMediaPlayer::LoadedMedia
From QTBUG-110708 and QTBUG-11910, it appears that this bug is specific to prior versions of Qt (6.5.0 and earlier).
It was fixed in Qt 6.5.1; the problem vanishes after upgrading to it, meaning it's possible to play videos from the provided URL while using FFmpeg.
For more: