0

我尝试解码视频并将帧转换为 rgb32 或 gb565le 格式。

然后通过 JNI 将此帧从 C 传递到 Android 缓冲区。

到目前为止,我知道如何将缓冲区从 C 传递到 Android,以及如何解码视频和获取解码帧。

我的问题是如何将解码帧转换为 rgb32(或 rgb565le),它存储在哪里?

以下是我的代码,我不确定是否正确。

-贾戈


img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, 100, 100, PIX_FMT_RGB32, SWS_BICUBIC, NULL, NULL, NULL);
if(!img_convert_ctx) return -6;

while(av_read_frame(pFormatCtx, &packet) >= 0) {
   // Is this a packet from the video stream?
   if(packet.stream_index == videoStream) {
       avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);

       // Did we get a video frame?
       if(frameFinished) {
            AVPicture pict;

            if(avpicture_alloc(&pict, PIX_FMT_RGB32, 100, 100) >= 0) {
                sws_scale(img_convert_ctx, (const uint8_t * const *)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pict.data, pict.linesize);
            }
       } // End of if( frameFinished )
   } // End of if( packet.stream_index == videoStream )

   // Free the packet that was allocated by av_read_frame
   av_free_packet(&packet);
}
4

1 回答 1

0

解码帧进入pict. (pFrame是一个原始帧。)

100x100可能不好,您必须pict根据 pFrame 大小计算大小。我想应该是pFrame->width*pFrame->height*32;

你必须pict自己分配。

请参阅本教程http://dranger.com/ffmpeg/

于 2013-08-26T05:58:44.403 回答