[Windows,Qt5,QMediaPlayer,QMediaPlaylist]:当前视频源更改时,微弱的黑屏时间 [英] [Windows, Qt5, QMediaPlayer, QMediaPlaylist]: Tiny duration black screen when the current video source changed

查看:684
本文介绍了[Windows,Qt5,QMediaPlayer,QMediaPlaylist]:当前视频源更改时,微弱的黑屏时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Qt5 :: QMediaPlayer编写视频播放器,以随机播放一些视频,其播放时间如下:

I'm writing a Video Player with Qt5::QMediaPlayer to play randomly some videos for a randomly duration as this:

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    QMediaPlaylist* playlist = new QMediaPlaylist(&a);
    playlist->addMedia(QUrl::fromLocalFile("./Resources/fractal-files/A-060405V4651.WMV"));
    playlist->addMedia(QUrl::fromLocalFile("./Resources/fractal-files/E-102604.WMV"));
    playlist->addMedia(QUrl::fromLocalFile("./Resources/fractal-files/C-102304.WMV"));

    QMediaPlayer* player = new QMediaPlayer(&a);
    player->setPlaylist(playlist);

    QVideoWidget* videoWidget = new QVideoWidget;
    player->setVideoOutput(videoWidget);

    player->play();
    videoWidget->show();

    QTimer* t = new QTimer;
    QObject::connect(t, &QTimer::timeout, [&](){
        playlist->setCurrentIndex(playlist->nextIndex());
        player->play();
        videoWidget->setWindowTitle(playlist->currentMedia().canonicalUrl().fileName());
        t->start((qrand()%5 + 5)*1000);
    });
    t->start((qrand()%5 + 5)*1000);

    QTimer* t2 = new QTimer;
    QObject::connect(t2, &QTimer::timeout, [&](){
        player->setPosition(qrand() % player->duration());
        videoWidget->setWindowTitle(playlist->currentMedia().canonicalUrl().fileName());
        t2->start((qrand()%2 + 2)*1000);
    });
    t2->start((qrand()%2 + 2)*1000);

    return a.exec();
}

有两个问题:
1.更改位置时

There are two issues:
1. When change the position

player->setPosition(qrand() % player->duration());

有一些延迟(我的客户可以接受,但比较好)
2.当视频源更改为:

there are a bit delay (my client can accept this, but smoothly is better)
2. When the video source changed with:

playlist->setCurrentIndex(playlist->nextIndex());
player->play();

有一个客户不希望的持续时间很短的黑屏.他希望效果至少与更改位置时相同:

there are a small duration black screen that the client doesn't want. He want the effect at least same as when changing the postion:

player->setPosition(qrand() % player->duration());

在Windows上使用Qt5更改视频源时,我们可以消除黑屏吗?还是我们可以与其他库/框架一起使用(在更改视频源时播放没有黑屏间隙的视频列表)? (在MacO上,切换很流畅)
非常感谢你!

Can we remove this black screen when changing the video source with Qt5 on Windows? Or we can do this with other libraries/frameworks (play a list of videos without black screen gap when change the video source)? (On MacOs, the switching is smooth)
Thank you very much!

推荐答案

这是已报告的 bug 在QtMediaPlayer中,并且仅在Windows上出现.在当前的API中,当媒体播放完时,播放器会清除视频区域以播放下一个媒体.过渡不是无缝的,并且会导致无效的帧.作为循环视频中的一种解决方法,可以将位置更改为同一媒体中的所需帧.

This is a reported bug in QtMediaPlayer and it only occurs on Windows. In current API, when a media reach the end, player clears the video area to play next media. Transition is not seamless and cause invalid frames. As a workaround in a looping video one can change the position to desired frame in same media.

如果需要更换媒体,则可以尝试使用两个mediaplayer对象,一个用于当前媒体,另一个用于下一个媒体.是时候播放下一个媒体了,将该播放器位置更改为0并将其显示在小部件上.在 bug 报告的链接中指出了这一点.这是一团糟,仍然不是一个完整的解决方案.

If you need to change the media you can try using two mediaplayer object one for current media and one for next media. When it is time to play the next media change that player position to 0 and show it on widget. That one is stated in link of bug report. It is messy and still not a complete solution.

那么,该怎么办?

  1. 您可以等待Qt修复.错误似乎是在2-3个月前报告的.

  1. You can wait for the Qt fix. Bug seems reported 2-3 months ago.

更改媒体播放器(Gstreamer具有无缝/无缝视频支持) 您当然可以在使用Qt开发的UI中嵌入媒体播放器.有示例.

Change Media Player ( Gstreamer has gapless/seamless video support ) You can surely embed a media player in your UI developped with Qt. There are examples.

移动另一个提供更好的媒体播放功能的UI库.

Move t another UI library that offers better media playing features.

我会按照2-1-3的顺序去做.尝试嵌入另一个媒体播放器,并等待几个月的时间来修复该错误.

I would go with the 2-1-3 order. Try embedding another media player and allow a couple of months for them to fix the bug.

这篇关于[Windows,Qt5,QMediaPlayer,QMediaPlaylist]:当前视频源更改时,微弱的黑屏时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆