Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Capturing screenshot with Phonon::VideoWidget::snapshot()
Forum Updated to NodeBB v4.3 + New Features

Capturing screenshot with Phonon::VideoWidget::snapshot()

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 10.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patap
    wrote on last edited by
    #1

    Hi all,

    Thanks for reading the post. I am working on a mini video player that provide basic media viewing functions (playback, volumn control) so the Phonon::VideoPlayer fits the purpose perfectly. With minimum code (thanks Qt!), I got the video playback working. I am developing with Qt 4.7.0 on Mac OS X 10.6.5.

    I also see there is a function VideoWidget::snapshot() to do the cool screen capture of the video, so I tried - didn't work for me - the QImage returned is always null. I tried with AVI, MOV, and MP4 video files - all didn't work for the snapshot.

    Then I changed my code to use QPixmap::grabWidget() and passed the VideoWidget or VideoPlayer in - this time it returns a valid QPixmap - but it is always a plain back image! I also tried to pass the dialog that contains the VideoPlayer into gradWidget(), and I can see all other widgets been captured correctly except the video content.

    May be capturing video screenshot is different in Phonon? Any suggestions that I could get this to work? Thanks so much!

    Some code fragments:

    @
    class Dialog : public QDialog
    {
    Q_OBJECT
    // Not showing other members except this...
    Phonon::VideoPlayer *m_videoPlayer;
    };

    void Dialog::saveSnapshot()
    {
    // For some reason the snapshot doesn't work with Phonon widgets...
    // Could be bugs inside Qt, may have to investigate further
    const QPixmap& snapshot = QPixmap::grabWidget(m_videoPlayer);
    qDebug() << "snapshot captured?" << !snapshot.isNull();

    QString format = "png";
    QString initialPath = QDir::currentPath() + tr("/snapshot.") + format;
    
    QString fileName =
            QFileDialog::getSaveFileName(this, tr("Save As"),
                                         initialPath,
                                         tr("%1 Image (*.%2)")
                                            .arg(format.toUpper())
                                            .arg(format));
    
    qDebug() << "Saving snapshot to" << fileName;
    
    if (!fileName.isEmpty()) {
        bool saved = snapshot.save(fileName);
        qDebug() << "Snapshot saved?" << saved;
    }
    

    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      [quote]
      I also see there is a function VideoWidget::snapshot() to do the cool screen capture of the video, so I tried – didn’t work for me – the QImage returned is always null. I tried with AVI, MOV, and MP4 video files – all didn’t work for the snapshot.
      [/quote]

      That's likely to be a Phonon bug. Have you tried the phonon from KDE's svn? (Which, by the way, you should be using anyway, since Phonon in Qt is 1. old 2. very bugged...)

      [quote]
      Then I changed my code to use QPixmap::grabWidget() and passed the VideoWidget or VideoPlayer in – this time it returns a valid QPixmap – but it is always a plain back image! I also tried to pass the dialog that contains the VideoPlayer into gradWidget(), and I can see all other widgets been captured correctly except the video content.[/quote]

      That probably caused by the video being shown in a overlay, which grabWidget() won't capture.

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • P Offline
        P Offline
        patap
        wrote on last edited by
        #3

        Thanks peppe, I suspect that it is a bug in Phonon too, although I didn't know that it is buggy with Qt...

        I noticed that Qt 4.7.1 is released but I couldn't find anything related to this bug in the release note. Anyway I may give it a try first...

        If it still doesn't work, any suggestions to get the snapshot of the video? Thanks in advance.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          As I said: grab KDE's one from its SVN and try using that one :-)

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • P Offline
            P Offline
            patap
            wrote on last edited by
            #5

            no luck for me with the KDE's one :-(

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #6

              Can you make a testcase and eventually submit a bug report? You may also want to ask for help on "phonon @ freenode":irc://irc.freenode.net/#phonon .

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              1 Reply Last reply
              0
              • P Offline
                P Offline
                patap
                wrote on last edited by
                #7

                Finally I got it working by changing this line:

                @
                const QPixmap& snapshot = QPixmap::grabWidget(m_videoPlayer->videoWidget());
                @

                to

                @
                const QPixmap& snapshot = QPixmap::grabWindow(m_videoPlayer->videoWidget()->winId());
                @

                As from the documentation, the QPixmap::grabWindow() function grabs pixels from the screen, not from the window, i.e. if there is another window partially or entirely over the one you grab, you get pixels from the overlying window, too. The mouse cursor is generally not grabbed.

                The window system identifier (WId) can be retrieved using the QWidget::winId() function. The rationale for using a window identifier and not a QWidget, is to enable grabbing of windows that are not part of the application, window system frames, and so on.

                Anyway I think it is definitely a bug in Phonon, so I will submit a test report soon. Thanks again for your time! :)

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  singhzubin
                  wrote on last edited by
                  #8

                  Hi Patap,

                  I am trying to do something very similar to you - it seems that my video does not stay on the screen in my N8 (symbian^3) emulator but my audio plays in the background. I also am having a 'black' screen appear when I try to grabWidget but if I try your approach above I get a 'pink' image. But this is probably because my video does not play back properly in the first place.

                  Anyways here is the code:
                  @
                  videoExample::videoExample(QWidget *parent) :
                  QDialog(parent),
                  ui(new Ui::videoExample)

                  {
                  ui->setupUi(this);

                  Phonon::MediaObject *m_MediaObject = new Phonon::MediaObject(this);
                  m_MediaObject->clearQueue ();
                  m_MediaObject->enqueue(Phonon::MediaSource("test.mp4")); // or setCurrentSource

                  Phonon::VideoWidget *m_videoWidget = new Phonon::VideoWidget(this);
                  m_videoWidget->resize(QApplication::desktop()->size());
                  m_videoWidget->setWindowFlags( Qt::Popup );
                  Phonon::createPath(m_MediaObject, m_videoWidget);

                  Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
                  Phonon::createPath(m_MediaObject, audioOutput);
                  m_MediaObject->play();

                  // if you want to grab the entire window
                  QPixmap image = QPixmap::grabWindow(m_videoWidget->winId());

                  //if you want to grab only the video widget data
                  //QPixmap image= QPixmap::grabWidget(m_videoWidget);

                  qDebug()<<"The Qpixmap image size is" << image.size();
                  if (image.size().isEmpty())
                  {
                  qDebug()<<"The Qpixmap image does not contain any data";
                  }

                  ui->label->setPixmap(image);
                  image.save("--printScreen5.bmp", "BMP");

                  }

                  videoExample::~videoExample()

                  {

                  delete ui;
                  

                  }@

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    riverszhang
                    wrote on last edited by
                    #9

                    Hi, singhzubin
                    do you fix the bug? I meet the same problem as your. Wish you can help me out.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved