@@ -145,7 +145,8 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
145145 }
146146
147147 for (i = 0 ; i < c -> planes ; i ++ ) {
148- c -> slice_buffer [i ] = av_malloc (avctx -> width * (avctx -> height + 1 ) +
148+ c -> slice_stride = FFALIGN (avctx -> width , 32 );
149+ c -> slice_buffer [i ] = av_malloc (c -> slice_stride * (avctx -> height + 2 ) +
149150 FF_INPUT_BUFFER_PADDING_SIZE );
150151 if (!c -> slice_buffer [i ]) {
151152 av_log (avctx , AV_LOG_ERROR , "Cannot allocate temporary buffer 1.\n" );
@@ -196,11 +197,11 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
196197 return 0 ;
197198}
198199
199- static void mangle_rgb_planes (uint8_t * dst [4 ], uint8_t * src , int step ,
200- int stride , int width , int height )
200+ static void mangle_rgb_planes (uint8_t * dst [4 ], int dst_stride , uint8_t * src ,
201+ int step , int stride , int width , int height )
201202{
202203 int i , j ;
203- int k = width ;
204+ int k = 2 * dst_stride ;
204205 unsigned g ;
205206
206207 for (j = 0 ; j < height ; j ++ ) {
@@ -224,6 +225,7 @@ static void mangle_rgb_planes(uint8_t *dst[4], uint8_t *src, int step,
224225 k ++ ;
225226 }
226227 }
228+ k += dst_stride - width ;
227229 src += stride ;
228230 }
229231}
@@ -547,16 +549,16 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
547549
548550 /* In case of RGB, mangle the planes to Ut Video's format */
549551 if (avctx -> pix_fmt == PIX_FMT_RGBA || avctx -> pix_fmt == PIX_FMT_RGB24 )
550- mangle_rgb_planes (c -> slice_buffer , pic -> data [0 ], c -> planes ,
551- pic -> linesize [0 ], width , height );
552+ mangle_rgb_planes (c -> slice_buffer , c -> slice_stride , pic -> data [0 ],
553+ c -> planes , pic -> linesize [0 ], width , height );
552554
553555 /* Deal with the planes */
554556 switch (avctx -> pix_fmt ) {
555557 case PIX_FMT_RGB24 :
556558 case PIX_FMT_RGBA :
557559 for (i = 0 ; i < c -> planes ; i ++ ) {
558- ret = encode_plane (avctx , c -> slice_buffer [i ] + width ,
559- c -> slice_buffer [i ], width ,
560+ ret = encode_plane (avctx , c -> slice_buffer [i ] + 2 * c -> slice_stride ,
561+ c -> slice_buffer [i ], c -> slice_stride ,
560562 width , height , & pb );
561563
562564 if (ret ) {
0 commit comments