Xpra-org / xpra

Persistent remote applications for X11; screen sharing for X11, MacOS and MSWindows.
https://xpra.org/
GNU General Public License v2.0
1.91k stars 164 forks source link

ROI for stream mode #4052

Open totaam opened 10 months ago

totaam commented 10 months ago

Make the --encoding=stream mode (#3872) more appropriate for xpra by specifying unchanged screen regions. ffmpeg added support for this here: https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/418c954e318a79f77eae1b4d6b29d40daee4284a Original x264 commit is here (from 2012!): https://mailman.videolan.org/pipermail/x264-devel/2012-April/009327.html

Seems to involve:

When scaling server-side, the module will need to scale the ROI coordinates too.


Something similar should be possible with NVENC, unfortunately the documentation is seriously lacking.

int8_t                                     *qpDeltaMap;
/**< [in]: Specifies the pointer to signed byte array containing QP delta value per MB
in raster scan order in the current picture.
This QP modifier is applied on top of the QP chosen by rate control. */
uint32_t                                    qpDeltaMapSize;
/**< [in]: Specifies the size in bytes of qpDeltaMap surface allocated by client
and pointed to by NV_ENC_PIC_PARAMS::qpDeltaMap.
Surface (array) should be picWidthInMbs * picHeightInMbs */

libvpx: https://github.com/webmproject/libvpx/blob/main/examples/set_maps.c

totaam commented 9 months ago

For AMD: AMD Enables VCN Region Of Interest "ROI" Video Encoder Support For Linux GPU Drivers

totaam commented 2 weeks ago

With the ROI stub above, and add adding some debug logging to the x264 code:

           if( h->fdec->mb_info && (h->fdec->mb_info[h->mb.i_mb_xy]&X264_MBINFO_CONSTANT) )
            {
                d = h->fdec->i_frame - h->fref[0][0]->i_frame;
                qp = h->fref[0][0]->effective_qp[h->mb.i_mb_xy];
                maxqp = h->mb.i_qp;
                printf("xy=%d, d=%d, weighted_pred=%d, qp=%d - max=%d\n", h->mb.i_mb_xy, d, h->sh.b_weighted_pred, qp, maxqp);
                if( !SLICE_MBAFF && d == 1 && !h->sh.b_weighted_pred && qp <= maxqp )
                {

Not all odd macroblocks are being skipped as I would have expected - ie:

xy=3219, d=1, weighted_pred=0, qp=255 - max=19

Useful link for x264 defaults: https://github.com/cybertk/x264/blob/cf71aa426ac07a47b41f754b1d6b5d9e8fc39f5d/files/x264/common/common.c#L45

totaam commented 1 week ago

Findings: