Stretch video player with vlc-qt?

5.7k Views Asked by At

I want to make qt application that contains video play function.
Already, I can play video using VLC-QT Library, and its Examples
Some reason, I want stretch preview.

I found change aspect ratio, but that is only support with enum

/*
enum Ratio {
    Original,
    Ignore, !< QML aspect ratio only
    R_16_9,
    R_16_10,
    R_185_100,
    R_221_100,
    R_235_100,
    R_239_100,
    R_4_3,
    R_5_4,
    R_5_3,
    R_1_1
}
*/
Vlc::Ratio r = Vlc::Ratio::R_1_1;

ui->video->setDefaultAspectRatio(r);
ui->video->setAspectRatio(r);
ui->video->setCurrentCropRatio(r);
ui->video->setDefaultCropRatio(r);
ui->video->setCropRatio(r);

ui->video->enableDefaultSettings();

Current:

Preview I want:
Want

How I can configure stretch mode?

1

There are 1 best solutions below

0
On

I also encountered the same problem, and after my attempts, the following solution is feasible

void VlcVideo::setAspectRatio(const QSize& size)
{
    if (_vlcMediaPlayer && libvlc_media_player_has_vout(_vlcMediaPlayer)) {
        auto size_str = QString("%1:%2").arg(QString::number(size.width()), QString::number(size.height()));
        libvlc_video_set_aspect_ratio(_vlcMediaPlayer, size_str.toUtf8().data());
        VlcError::showErrmsg();
    }
}

You can keep the same aspect ratio as QWidget in QWidget::resizeEvent(QResizeEvent* event);