Qt:读取视频尺寸而不创建视频播放器

发布于 2024-11-02 03:54:02 字数 125 浏览 4 评论 0原文

我需要读取给定视频文件的尺寸(其宽度和高度),而不构建视频播放器,例如 Phonon,例如我的问题是我应该使用哪个类来访问此数据。我已经尝试过使用 QPixmap 和 QMovie,但它们都不支持 *.mov。

谢谢你!

I need to read the dimensions of a given video file (its width and height), without constructing a video player, like Phonon, e.g. My question is which class I should use to get access to this data. I have already tried using QPixmap and QMovie, but niether of them supports *.mov.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我最亲爱的 2024-11-09 03:54:02

Pavlo,你可以试试这个:

QMediaContent media("myMovie.mov");
QSize resolution = media.canonicalResource().resolution();

代码使用 QMediaResource来自 Qt Mobility 项目的类。我还没有尝试过,我想你至少需要一个正确的后端(能够读取 MOV 格式的插件)。我仅根据 API 概述给出这个答案。

希望这有帮助。

Pavlo, you can try this:

QMediaContent media("myMovie.mov");
QSize resolution = media.canonicalResource().resolution();

The code uses QMediaResource class from Qt Mobility project. I haven't tried it yet and I suppose you need at least a correct backend (plugin that is capable of reading MOV format). I'm giving this answer only from API overview.

Hope this helps.

丑疤怪 2024-11-09 03:54:02

我终于解决了我的问题,我想我会与其他人分享我的解决方案。
在类构造函数中,我初始化以下两个变量:

media = new Phonon::MediaObject(this);
videoWidget = new Phonon::VideoWidget;

我将 media 信号连接到类中的插槽:

connect(media,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
        this,SLOT(videoState(Phonon::State,Phonon::State)));

我让用户选择一个视频文件:

QString filename = QFileDialog::getOpenFileName(this,tr("Choose video file"),QDir().homePath(),tr("Video files (*.mov *.mpg *.avi)"));

并将该文件应用于 media 对象:

media->setCurrentSource(filename);
Phonon::createPath(media,videoWidget);

由于 media 对象已连接到插槽,因此可以在其帮助下监视 media 中的每个变化。

void VideoModuleDialog::videoState(Phonon::State newState, Phonon::State oldState)
{
    if(newState == Phonon::PlayingState || newState == Phonon::StoppedState)
    {
        width->setText(QString().number(videoWidget->sizeHint().width()));
        height->setText(QString().number(videoWidget->sizeHint().height()));
    }
    if(newState == Phonon::ErrorState)
    {
        QMessageBox::critical(this,tr("Video file error!"),
                              tr("Video file error: ") + media->errorString(),QMessageBox::Ok);
    }
}

然而,我必须承认,这段代码在我看来相当慢。声子库仅在我的程序中使用在一个地方,就是在这里,在一个对话框窗口中,用户可以选择要嵌入的视频剪辑,我希望从文件中读取视频尺寸。这个对话框窗口打开需要一些时间,所以我想,这个解决方案对于我的问题来说有点太苛刻了。但是,我无法找到其他解决方案。如果对这篇文章的主题有不同的意见,我很高兴听到他们的意见。

I finally solved my problem and I thought I'd share my solution with everybody else.
In the class constructor I initialize the following two variables:

media = new Phonon::MediaObject(this);
videoWidget = new Phonon::VideoWidget;

I connect a signal of media to a slot in my class:

connect(media,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
        this,SLOT(videoState(Phonon::State,Phonon::State)));

I let the user choose a video file:

QString filename = QFileDialog::getOpenFileName(this,tr("Choose video file"),QDir().homePath(),tr("Video files (*.mov *.mpg *.avi)"));

And apply this file to the media object:

media->setCurrentSource(filename);
Phonon::createPath(media,videoWidget);

Because media object is already connected to a slot, every change in media can be monitored with its help.

void VideoModuleDialog::videoState(Phonon::State newState, Phonon::State oldState)
{
    if(newState == Phonon::PlayingState || newState == Phonon::StoppedState)
    {
        width->setText(QString().number(videoWidget->sizeHint().width()));
        height->setText(QString().number(videoWidget->sizeHint().height()));
    }
    if(newState == Phonon::ErrorState)
    {
        QMessageBox::critical(this,tr("Video file error!"),
                              tr("Video file error: ") + media->errorString(),QMessageBox::Ok);
    }
}

I must admit, however, that this code seems to me to be quite slow. Phonon library is used in my program only in one place, and this is here, in a dialog window where user can choose a video clip to embed, and i want the video dimensions to be read from file. It takes some time until this dialog window opens, so I guess, this solution is a bit too harsh for my problem. However, I was not able to find another solution. If there are different opinions as to the subject of this post, I'd be glad to hear them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文