Add tag to video

I need to write a simple video player that can display some subtitles, a link or an image (for example, on YouTube) at a specific time. I have no idea how to display anything using QVideoWidget. I could not find a useful class for this. Could you give me some advice?

I did it my own way, but after downloading any video, QLabel disappears ...

player->setVideoOutput(vw); playlistView->setMaximumWidth(200); playlistView->setMinimumWidth(300); window = new QWidget; Playerlayout = new QGridLayout; subtitleWidget = new QLabel; subtitleWidget->setMaximumWidth(1000); subtitleWidget->setMaximumHeight(100); subtitleWidget->setStyleSheet("QLabel {background-color : red; color blue;}"); subtitleWidget->setAlignment(Qt::AlignCenter | Qt::AlignBottom); subtitleWidget->setWordWrap(true); subtitleWidget->setText("example subtitle"); Playerlayout->addWidget(vw,0,0); Playerlayout->addWidget(subtitleWidget,0,0); Playerlayout->addWidget(playlistView,0,1,1,2); 
+5
source share
1 answer

If QVideoWidget does not provide what you need directly, you can always customize the overlay.

The hierarchy of the main layout element will be something like ...

 QWidget layout QVideoWidget subtitle_widget 

In this case, the layout can be either QStackedLayout , using the stacking mode QStackedLayout::StackAll or QGridLayout , while the QVideoWidget and subtitle_widget tags are the same but with the correct z-order.

Transition using QGridLayout ...

 auto *w = new QWidget; auto *l = new QGridLayout(w); auto *video_widget = new QVideoWidget; auto *subtitle_widget = new QLabel; /* * Subtitles will be shown at the bottom of the 'screen' * and centred horizontally. */ subtitle_widget->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); subtitle_widget->setWordWrap(true); /* * Place both the video and subtitle widgets in cell (0, 0). */ l->addWidget(video_widget, 0, 0); l->addWidget(subtitle_widget, 0, 0); 

Subtitles, etc. can now be displayed simply by calling subtitle_widget->setText(...) at the appropriate time.

The same method can be easily extended to overlay other types of information.

+1
source

Source: https://habr.com/ru/post/1274744/


All Articles