简体   繁体   中英

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 . 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. Is this the right/best way to get meta informations about a video file in Qt?

Given the fact that QtMultimedia in general is pretty much broken, you should listen to QMediaObject::metaDataChanged (inherited by QMediaPlayer ).

However, I warn you that this is broken on Windows and most likely macOS too. I've reported several QTBUG and they just don't care.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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