Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7.3, 6.8.0
-
None
Description
It's seems that QMediaPlayer can't be used in working thread specifically with "darwin" multimedia backend.
Imagine that you need to generate video previews for a bulk of video files using QtConcurrent::map() more or less effectively using a thread pool and you already have a function like:
QImage generateVideoPreview(const QUrl &videoUrl) { qDebug() << "Generating video preview for " << videoUrl; QImage preview; QEventLoop loop; QVideoSink sink; QObject::connect(&sink, &QVideoSink::videoFrameChanged, &loop, [&] (const QVideoFrame& frame) { if (!frame.isValid()) { qDebug() << "invalid frame!"; return; } preview = frame.toImage(); loop.quit(); }); QMediaPlayer player; QObject::connect(&player, &QMediaPlayer::errorOccurred, &loop, [&](QMediaPlayer::Error error, const QString& errorString) { qDebug() << "Error " << error << ": " << errorString; loop.quit(); }); player.setVideoOutput(&sink); player.setSource(videoUrl); player.play(); QTimer::singleShot(2000, &loop, [&] { qDebug() << "Timeout!"; loop.quit(); }); loop.exec(); return preview; }
So, the next code works fine with "windows" (on Windows) or "ffmpeg" (on macOS) multimedia backends
QList<QString> videoFiles = ...; auto res = QtConcurrent::map(videoFiles, &generateVideoPreview); ...
but it refuses to work with "darwin" multimedia backend on macOS.
See attached example. It has no practical meaning, I just slightly modified code from QTBUG-122608 to demonstrate the problem.
Just launch it and open any video file. Instead of video preview you'll see nothing after 2 secs timeout. Removing QtConcurrent::run() usage in the code makes it work.