Hi FFmpeg developers,

I am a FreeRDP developer and I am currently working on using FFmpeg to decode video. The code I attached below is a simplified version of my real code. It basically just decode the video frame and store the image into my own buffer, which will be later sent to XVideo:

        /* Decode data into frame */
        AVPacket pkt;
        av_init_packet(&pkt);
        pkt.data = data;
        pkt.size = data_size;
        len = avcodec_decode_video2(context, frame, &decoded, &pkt);

        /* Copy the decoded frame to decoded_data */
        decoded_size = avpicture_get_size(context->pix_fmt,
                context->width, context->height);
        decoded_data = malloc(decoded_size);
        f = avcodec_alloc_frame();
        avpicture_fill((AVPicture *) f, decoded_data,
                context->pix_fmt,
                context->width, context->height);
        av_picture_copy((AVPicture *) f, (AVPicture *) frame,
                context->pix_fmt,
                context->width, context->height);
        av_free(f);

So far I only work with YUV420P. The above codes works fine if the decoded frame->linesize[0]==width; however in some cases frame->linesize[0] will be aligned to larger size than width, then color will be messed up in the target YUV data buffer (Y channel is ok but U and V is not).

To be more specific, the problematic test video is 852x480, the output frame has linesize 896/448/448, and the target frame has 852/426/426. I tried to read the av_picture_copy source code and dump the buffers, and seems everythig is alright: every first 426 bytes of the source lines are just copied to the target. But the color of the image does not look right.

Am I missing something here?

Vic

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to