ffmpeg解码数据保存为yuv格式

将ffmpeg解码的数据保存为yuv格式:

    Q_UNUSED(width);
    Q_UNUSED(height);
    BroadCastManager *ptr = (BroadCastManager *)receiver;
    int frame_finished;
    memset(&ptr->client_info.packet,0,sizeof(ptr->client_info.packet));
    ptr->client_info.packet.data=pData;
    ptr->client_info.packet.size=size;
 
  
    unsigned int consumed_bytes = avcodec_decode_video2(ptr->client_info.pCodecCtx,ptr->client_info.pFrame,&frame_finished,&ptr->client_info.packet);
    unsigned char *DisplayBuf;
    DisplayBuf = (unsigned char *)malloc(sizeof(unsigned char)*(3 * (ptr->client_info.width) * (ptr->client_info.height)));
    if(DisplayBuf == NULL)
    {
        qInfo() << "the displaybuf is null";
        return NULL;
    }
    if(consumed_bytes > 0)
    {
        memset(DisplayBuf,0,3 *(ptr->client_info.width) * (ptr->client_info.height));
        int p=0;
        for(int i=0; iclient_info.height; i++)
        {
            memcpy(DisplayBuf+p,ptr->client_info.pFrame->data[0] + i * ptr->client_info.pFrame->linesize[0], ptr->client_info.width);
            p += ptr->client_info.width;
        }
 
  
        for(int i=0; iclient_info.height/2; i++)
        {
            memcpy(DisplayBuf+p,ptr->client_info.pFrame->data[1] + i * ptr->client_info.pFrame->linesize[1], ptr->client_info.width/2);
            p+=ptr->client_info.width/2;
        }
 
  
        for(int i=0; iclient_info.height/2; i++)
        {
             memcpy(DisplayBuf+p,ptr->client_info.pFrame->data[2] + i * ptr->client_info.pFrame->linesize[2], ptr->client_info.width/2);
             p+=ptr->client_info.width/2;
        }
        return DisplayBuf;
     }
 
  

你可能感兴趣的:(QT)