Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt6 QML Multimedia: How to crop video played from MediaPlayer to VideoOutput

Qt6 QML Multimedia: How to crop video played from MediaPlayer to VideoOutput

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
multimediavideooutputmediaplayervideo rtspvideo streaming
3 Posts 2 Posters 992 Views
  • 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.
  • R Offline
    R Offline
    rklemm
    wrote on 27 Jul 2022, 14:19 last edited by rklemm
    #1

    I am streaming to a Qt app from an RTSP server that sends horizontally tiled 1080p video (so the incoming video has a raw size of 3840x1080). I want to be able to crop to either the left or right half of the video from QML. Currently, I have this code - it works, but it feels like I am overcomplicating it:

     MediaPlayer {
            id: mediaplayer
            // Sends 3840x1080 video which is a tiled 1080p stream
            source: "rtsp://xxxxx"
            videoOutput: videoOut
    }
    
    // Hide a 3840x1080 VideoOutput behind a Shader widget that crops it
    StackLayout {
            anchors.fill: parent
            currentIndex: 1
    
            VideoOutput {
                    id: videoOut
            }
    
            ShaderEffectSource {
                    id: cropVideo
                    property bool viewLeft: true
                    sourceItem: videoOut
                    hideSource: true
                    live: true
    
                    Layout.maximumHeight: 1080
                    Layout.maximumWidth: 1920
                    Layout.preferredHeight: 1080
                    Layout.preferredWidth: 1920
    
                    sourceRect: viewLeft ? Qt.rect(0, 0, 1920, 1080) 
                                        : Qt.rect(1920, 0, 1920, 1080)
            }
    }
    

    It feels like there should be a way to crop the video directly from either the MediaPlayer or VideoOutput widgets.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 28 Jul 2022, 10:32 last edited by
      #2

      VideoOutput has a sourceRect property.

      R 1 Reply Last reply 28 Jul 2022, 14:45
      0
      • G GrecKo
        28 Jul 2022, 10:32

        VideoOutput has a sourceRect property.

        R Offline
        R Offline
        rklemm
        wrote on 28 Jul 2022, 14:45 last edited by rklemm
        #3

        @GrecKo It does, but it seems to be a read-only reflection of the viewport set for the video frame objects that are coming through the videoSink. When I attempt to assign to it, I get the QML error: Invalid property assignment: "sourceRect" is a read-only property. The docs do not appear to reflect the fact that sourceRect is read-only. I am using Qt 6.3.

        Looking at the source for VideoOutput (https://github.com/qt/qtmultimedia/blob/37c2d097eb5dd8671cc752dc920da11d66105905/src/multimediaquick/qquickvideooutput_p.h#L41), we can see that the Q_PROPERTY for sourceRect is read-only in both the 6.3 and dev branches.

        I have had the thought of attempting to manually set the viewport of the QVideoFrameFormat of the frames coming through the VideoOutput's videoSink, but I haven't created a working solution for that strategy yet.

        1 Reply Last reply
        0

        3/3

        28 Jul 2022, 14:45

        • Login

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