как скопировать другой буфер кадров с помощью ffmpeg

#ffmpeg #frame

#ffmpeg #кадр

Вопрос:

У меня есть вопрос по копированию кадра с другой позицией.

Я получил 1280 640 декодированных кадров (YUV420) из h264 / mp4, и я хочу объединить 4 кадра с 2560 1280 кадровым буфером. как показано ниже.

введите описание изображения здесь

Код похож на этот, но не работает.

введите код здесь

/* pCodecCtx и pFrame для декодированной информации о кадре */ int Encoding2JPEG( AVCodecContext *pCodecCtx, AVFrame *pFrame, int FrameNo, int Quality) {

     int gotFrame;

    /* New Context for JPEG encoding */
    AVCodec *jpeg_codec = NULL;
    AVCodecContext *jpeg_ctx =NULL;
    int ret;
    AVPacket *packet;
    packet = av_packet_alloc();
    if(!packet)
    {
            printf("alloc fail!n");
            return -1;
    }

    if(frame)
            printf("received frame for encoding %3"PRId64"n", frame->pts);

    pFrame_gather = av_frame_alloc();
    if(!pFrame_gather)
    {
            printf("Could not allocate gater frame!n");
            return -1;
    }

    pFrame_gather->format = pCodecCtx->pix_fmt;
    pFrame_gather->width = pCodecCtx->width*2;
    pFrame_gather->height = pCodecCtx->height*2;

    if ( av_frame_get_buffer(pFrame_gather, 0) < 0)
            printf("Could not allocate the gather frame data!n");

    /* Buffer Clear */
    ptrdiff_t linesize[4] = { frame->linesize[0], 0, 0, 0 };
    if( av_image_fill_black ( pFrame_gather->data, linesize, pCodecCtx->pix_fmt, 
                    AVCOL_RANGE_JPEG , pFrame_gather->width, pFrame_gather->height) != 0 )
            printf("image clear error!n");

    ret = av_frame_make_writable(pFrame_gather);
    if( ret <0)
                    printf("writeable set fail!n");

     /* set position of destination */
    int top_band =0;
    int left_band=200;

     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pCodecCtx->pix_fmt);
     int y_shift;
     int x_shift;
     int max_step[4];

     if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
      return -1;

 y_shift = desc->log2_chroma_h;
 x_shift = desc->log2_chroma_w;
 av_image_fill_max_pixsteps(max_step, NULL, desc);
 
 /* Y Data */
 memcpy( pFrame_gather->data[0]   (top_band * pFrame->linesize[0])   left_band,
         frame->data[0] , pCodecCtx->width*pCodecCtx->height);
 /* U Data */
 memcpy ( pFrame_gather->data[1]   ((top_band >> y_shift) * pFrame->linesize[1])   
          (left_band >> x_shift), frame->data[1], pCodecCtx->width/2*pCodecCtx->height/2);
 /* V DAta */
 memcpy ( pFrame_gather->data[2]   ((top_band >> y_shift) * pFrame->linesize[2]) 
            (left_band >> x_shift), frame->data[2], pCodecCtx->width/2*pCodecCtx->height/2);

 /* unref variable .... */
 ....
  

}

Верхний исходный код — это что-то скручивание. Это не работает. Как скопировать память с позицией?