【问题标题】:Take snapshot of video in Qt Multimedia在 Qt Multimedia 中拍摄视频快照
【发布时间】:2015-10-15 15:35:11
【问题描述】:

是否可以拍摄Qt Multimedia 中的视频快照?怎么样?

【问题讨论】:

    标签: qt video snapshot qmediaplayer qtmultimedia


    【解决方案1】:

    这取决于平台,但您可能会做的是使用QMediaPlayer,通过setVideoOutput 设置子类视频表面,并从QVideoFrame 中获取帧数据在present 方法中传递。然后,您必须处理帧格式并在 CPU 内存中不存在的情况下进行映射。

    但是,根据您的需要,我会使用 ffmpeg/libav 从特定位置获取帧。

    【讨论】:

      【解决方案2】:

      试试这个(这里的文档:http://doc.qt.io/qt-5/qml-qtquick-item.html#grabToImage-method

      import QtQuick 2.5
      import QtQuick.Window 2.2
      import QtQuick.Controls 1.4
      import QtQuick.Layouts 1.1
      import QtMultimedia 5.0
      
      Window {
          id: mainWindow
          visible: true
          width: 480
          height: 800
      
          MediaPlayer {    
              id: player
              source: "file:///location/of/some/video.mp4"
              autoPlay: false            
          }
      
          ColumnLayout {
              anchors.fill: parent
              VideoOutput {
                  id: output
                  source: player
                  Layout.fillHeight: true
                  Layout.fillWidth: true                
              }
      
              Row {
                  id: buttonsRow
                  height: 100
                  spacing: 20
                  anchors.horizontalCenter: parent.horizontalCenter
                  Layout.margins: 10                
      
                  Button {
                      id: playPauseButton
                      text: player.playbackState === MediaPlayer.PlayingState ? "Pause" : "Play"
                      onClicked: {
                          var playing = player.playbackState === MediaPlayer.PlayingState;
                          playing ? player.pause() : player.play();
                      }
                  }                
                  Button {
                      text: "Snapshot"
                      onClicked: {
                          output.grabToImage(function(image) {
                              console.log("Called...", arguments)
                              image.saveToFile("screen.png"); // save happens here
                          });
                      }
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2014-12-03
        • 1970-01-01
        • 1970-01-01
        • 2017-10-05
        • 1970-01-01
        • 1970-01-01
        • 2013-11-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多