I'm trying to take a single frame snapshot from each video stored in a directory for use as thumbnails in a list of videos. I want to use the takeSnapshot
method from the VLC-Qt wrapper for libvlc; documentation can be found here: https://vlc-qt.tano.si/reference/1.1/classvlcvideo#a4f3a741285dd9030f76bb996eaa011d4
My code is as follows:
for(i = dirList.begin(); i != dirList.end(); ++i) {
QString videoPath = i->absoluteFilePath();
const QString outPath = QString("C:/Users/jidap/Desktop/testDir/thumbnails/%1.jpg").arg(j);
instance = new VlcInstance(vlc_args, this);
player = new VlcMediaPlayer(instance);
videoManager = new VlcVideo(player);
media = new VlcMedia(videoPath, true, instance);
player->open(media);
player->play();
//QThread::sleep(200);
if(!videoManager->takeSnapshot(outPath)) {
std::cout << "thumbnail cannot be created" << std::endl;
}
player->stop();
}
When I run this, the takeSnapshot
method, it returns false for each iteration in the list, triggering the error message I wrote, and not saving any snapshots to the thumbnails directory. After examining the takeSnapshot
code, it seems that either my VlcMediaPlayer is either not instantiated or has no video output or both, but I'm not sure why that's happening or how to fix it. Any help is appreciated.
I figured it out:
Basically start an invisible instance of vlc, sleep the thread for long enough for the vout to take effect, then take the snapshot. This worked on my device by sleeping the thread for 0.1 seconds, but that may be different on other machines.