如何强制 QT5 MediaPlayer 显示字幕? [英] How to force QT5 MediaPlayer to show Subtitles?

查看:107
本文介绍了如何强制 QT5 MediaPlayer 显示字幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估从 Qt 4.8 到 Qt 5.2 的迁移,最重要的一点是多媒体后端.在 Qt 5.2 中,有一些 Qt 4.8 中的 Phonon 后端没有提供的重要功能.但至少老版本显示了字幕(与视频文件在同一目录下的SRT文件).

I am evaluating a migration from Qt 4.8 towards Qt 5.2 and the most important point is the multimedia backend. In Qt 5.2 there are some important features the Phonon backend in Qt 4.8 does not provide. But at least the elder version showed subtitles (SRT file in the same directory as the video file).

文档和试错都没有给我任何结果.

Neither the documentation nor the trial-and-error provided me any results.

那么,有谁知道如何强制 Qt 5 显示这些字幕?或者它甚至不支持(将是一种耻辱)

So, does anyone know how to FORCE Qt 5 to show these subtitles? Or isnt it even supported (would be a shame)

感谢任何帮助..

附注:我需要完全相反:禁用在 QMediaPlayer 中显示字幕文件

PS: I need exactly the opposite: Disable showing subtitle file in QMediaPlayer

推荐答案

您必须在 playbin2 上设置标志 GST_PLAY_FLAG_TEXT.(它通常默认开启.如果需要,则在 QGstreamerPlayerSession 的 ctor 中更改它).

You have to set the flag GST_PLAY_FLAG_TEXT on playbin2. (It is usually on by default. If need be then change it in the ctor of QGstreamerPlayerSession).

如果您的字幕文件是外部文件,那么您必须在 playbin2 上设置suburi"属性.suburi 属性的值是字幕文件的路径.此更改应在方法 QGstreamerPlayerSession::loadFromUri 中完成.

And if your subtitle file is external then you will have to set the "suburi" property on playbin2. The value of the suburi property is the path to the subtitle file. This change should be done in the method QGstreamerPlayerSession::loadFromUri.

在 Qt5.2 中,这些更改必须在文件 qgstreamerplayersession.cpp 中完成.您将在 qtmultimedia/src/plugins/gstreamer/mediaplayer 中找到该文件.对于较旧的 4.x 版本,文件位置可能不同.

In Qt5.2 these changes have to be done in the file qgstreamerplayersession.cpp.You will find the file at qtmultimedia/src/plugins/gstreamer/mediaplayer. The file location may be different for the older 4.x versions.

我观察到的另一件事是插件代码设置了标志 GST_PLAY_FLAG_NATIVE_VIDEO.如果设置了此标志,则不会显示字幕.您必须阻止插件代码设置此标志.您可以注释掉设置此标志的代码,或者您必须将环境变量 QT_GSTREAMER_PLAYBIN_FLAGS 设置为 0x00000017(即 GST_PLAY_FLAG_VIDEO|GST_PLAY_FLAG_AUDIO|GST_PLAY_FLAG_TEXT).将其设置为任何值将跳过 GST_PLAY_FLAG_NATIVE_VIDEO 标志.

The other thing I observed is that the plugin code sets the flag GST_PLAY_FLAG_NATIVE_VIDEO. The subtitles do not show up if this flag is set. You will have to prevent the plugin code from setting this flag. Either you can comment out the code that sets this flag or you will have to set the environment variable QT_GSTREAMER_PLAYBIN_FLAGS to 0x00000017 ( which is GST_PLAY_FLAG_VIDEO|GST_PLAY_FLAG_AUDIO|GST_PLAY_FLAG_TEXT). Setting it to any value will skip the GST_PLAY_FLAG_NATIVE_VIDEO flag.

进行这些更改后,构建插件并使用它.

After you make these changes, build the plugin and use it.

这篇关于如何强制 QT5 MediaPlayer 显示字幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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