W
W
wawa2019-06-15 21:25:33
Qt
wawa, 2019-06-15 21:25:33

How to change the playing audio track and subtitles in a video in Qt/PyQt/PySide?

I'm using the latest PySide, but I have experience with Qt/C++, so the language is not important.
I do it like this:

app = QApplication()

video_widget = QVideoWidget()
video_widget.resize(800, 600)
video_widget.show()

player = QMediaPlayer()
player.setMedia(QUrl.fromLocalFile(r'video.mp4'))
player.setVideoOutput(video_widget)
player.setVolume(50)
player.play()

sys.exit(app.exec_())

video.mp4 has some embedded rus/eng audio and subtitles. How to change them, and in the case of subs, disable / enable?
I found in the docks a QMediaStreamsControl class similar to the one I need, but I can’t figure out how to get out of QMediaPlayer on it.
Did it like this:
service = player.service()
mscontrol = service.requestControl("org.qt-project.qt.mediastreamscontrol/5.0")

but mscontrol is None :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronrun, 2020-04-19
@voronrun

stackoverflow

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question