简体   繁体   English

QMediaPlayer给我有关视频的错误信息

[英]QMediaPlayer gives me wrong informations about video

I'm trying to implement a server terminal application which inspects video files. 我正在尝试实现一个检查视频文件的服务器终端应用程序。 I need to get informations like audio/video codec, resolution, bitrate, length, etc. 我需要获取音频/视频编解码器,分辨率,比特率,长度等信息。

I found most of the needed information in QMediaResource . 我在QMediaResource中找到了大多数所需的信息。 After reading multiple examples, I came to this: 阅读多个示例后,我得出以下结论:

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

    QMediaPlayer media;
    media.setMedia(QUrl::fromLocalFile("/home/danbru1211/Videos/S01E01.mp4"));

    QObject::connect(&media, &QMediaPlayer::mediaStatusChanged,
                     [&media](QMediaPlayer::MediaStatus status){
        qDebug() << status;

        auto resource = media.media().canonicalResource();
        qDebug() << "language" << resource.language();
        qDebug() << "audioCodec" << resource.audioCodec();
        qDebug() << "videoCodec" << resource.videoCodec();
        qDebug() << "dataSize" << resource.dataSize();
        qDebug() << "audioBitRate" << resource.audioBitRate();
        qDebug() << "sampleRate" << resource.sampleRate();
        qDebug() << "channelCount" << resource.channelCount();
        qDebug() << "videoBitRate" << resource.videoBitRate();
        qDebug() << "resolution" << resource.resolution();
    });

    return a.exec();
}

But sadly this does not output the right meta data: 但是遗憾的是,这不会输出正确的元数据:

QMediaPlayer::LoadedMedia
language ""
audioCodec ""
videoCodec ""
dataSize 0
audioBitRate 0
sampleRate 0
channelCount 0
videoBitRate 0
resolution QSize(-1, -1)

I am sure the path of the video exists and is readable. 我确定视频的路径存在并且可读。 Why do I get all 0 values and not the correct ones. 为什么我得到所有0值而不是正确的值。 Is this the right/best way to get meta informations about a video file in Qt? 这是在Qt中获取有关视频文件的元信息的正确/最佳方法吗?

Given the fact that QtMultimedia in general is pretty much broken, you should listen to QMediaObject::metaDataChanged (inherited by QMediaPlayer ). 考虑到QtMultimedia一般都已损坏,您应该收听QMediaObject :: metaDataChanged (由QMediaPlayer继承)。

However, I warn you that this is broken on Windows and most likely macOS too. 但是,我警告您,这在Windows上以及很可能在macOS上也已损坏。 I've reported several QTBUG and they just don't care. 我已经报告了几个QTBUG ,它们只是不在乎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM