Search code examples
c++qtlibvlcvlc-qt

How to play video backwards in qt using vlc-qt libvlc


I am developing a media player using vlc-qt , Actually I want a button which will play do the fast backward operation. I don't have the problem with the fast forward operation but not able to implement the fast backward operation, Is there any function there in vlc-qt which will play the video backwards. Here are the buttons code which I am using for fast forward and fast backward operation

void expPlayer::on_pushButton_2_clicked()
{
    m_player->setPlaybackRate(m_player->playbackRate()+1);
}

void expPlayer::on_pushButton_3_clicked()
{
    //It should play the video backward with more playback rate.
}

Here is my full code

#ifndef EXPPLAYER_H
#define EXPPLAYER_H

#include <QMainWindow>
#include "VLCQtCore/Instance.h"
#include "VLCQtCore/MediaPlayer.h"
#include "VLCQtCore/Media.h"
#include "VLCQtCore/Common.h"
#include "VLCQtCore/Config.h"
#include "QPushButton"
#include "QtMultimedia/QMediaPlaylist"
#include "VLCQtWidgets/WidgetVideo.h"
#include "VLCQtWidgets/WidgetSeekProgress.h"
#include "QSlider"
#include "QFileDialog"
#include "QInputDialog"
#include "QLabel"
#include "QListView"
#include "QBoxLayout"
#include "VLCQtWidgets/WidgetSeek.h"
QT_BEGIN_NAMESPACE
namespace Ui { class expPlayer; }
QT_END_NAMESPACE

class expPlayer : public QMainWindow
{
    Q_OBJECT

public:
    expPlayer(QWidget *parent = nullptr);
    ~expPlayer();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();
    
    void on_pushButton_3_clicked();
    
private:
    Ui::expPlayer *ui;

    VlcInstance *m_instance;
    VlcMedia *m_media;
    VlcMediaPlayer *m_player;
    VlcWidgetSeekProgress *m_progressBar;
};
#endif // EXPPLAYER_H

#include "expplayer.h"
#include "ui_expplayer.h"

expPlayer::expPlayer(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::expPlayer)
{
    ui->setupUi(this);
    m_instance = new VlcInstance(VlcCommon::args(), this);
    m_player = new VlcMediaPlayer(m_instance);

    m_player->setVideoWidget(ui->m_video);
    ui->m_video->setMediaPlayer(m_player);
    m_progressBar=new VlcWidgetSeekProgress(this);
    m_progressBar->setMediaPlayer(m_player);
    ui->m_video->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    ui->m_video->show();

    m_media = new VlcMedia("http://www.youtube.com/watch?v=Btv7G0BV45g",m_instance);
    m_player->open(m_media);
    qDebug()<<"m_player->video():"<<m_player->video();
    m_player->play();

    m_progressBar->resize(ui->m_video->width(),30);
    m_progressBar->move(ui->m_video->x(),ui->m_video->y()+ui->m_video->height()+20);
    m_progressBar->show();

}

expPlayer::~expPlayer()
{
    delete ui;
}


void expPlayer::on_pushButton_clicked()
{



}

void expPlayer::on_pushButton_2_clicked()
{
    m_player->setPlaybackRate(m_player->playbackRate()+1);
}

void expPlayer::on_pushButton_3_clicked()
{
    //It should play the video backward with more playback rate.
}
qt 

Solution

  • VLC does not have this capability. As a workaround, you could try VLC with ffmpeg. I never used it, but:

    1. You can use ffmpeg to reverse a video, see this and Reverse video playback through ffmpeg, e.g.
    2. You can use ffmepg with VLC, see this, e.g.

    So I guess you could accomplish what you need with this solution.

    Other related sources, which I am not certain will help you

    1. You may try combining other open source alternatives with VLC, similarly as suggested above for ffmpeg.

      1.1. You may try using AviSynth with VLC.

      1.2. You may try using Avidemux with VLC. It used to be possible to reverse a video with it (see also this), but I am not sure it is possible nowadays. I am not sure it is possible to combine VLC with Avidemux either.

      1.3. Video players that have frame by frame playback feature

      1.4. Video player with backward frame by frame stepping for Linux, including the extension Previous Frame.

      1.5. Gstreamer

    2. How can I reverse a video clip?

    3. https://forum.videolan.org/viewtopic.php?t=139871

    4. https://forum.videohelp.com/threads/345380-video-player-that-can-step-forward-backwards-and-change-play-speed

    Note: OpenShot is another open source software that can play backwards... would you dare trying to combine it with VLC?