简体   繁体   English

ffmepg解码的帧存储在哪里?

[英]Where the decoded frame by ffmepg stored?

I try to decode video and convert frame to rgb32 or gb565le format. 我尝试解码视频并将帧转换为rgb32或gb565le格式。

Then pass this frame from C to Android buffer by JNI. 然后通过JNI将此帧从C传递到Android缓冲区。

So far, I know to how pass buffer from C to Android as well as how to decode video and get decoded frame. 到目前为止,我知道如何将缓冲区从C传递到Android,以及如何解码视频并获取解码的帧。

My question is how to convert decoded frame to rgb32 (or rgb565le) and where is it stored? 我的问题是如何将解码的帧转换为rgb32(或rgb565le),并将其存储在哪里?

The following is my code, I'm not sure is correct or not. 以下是我的代码,我不确定是否正确。

-Jargo -贾戈


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);
}

The decoded frame goes into pict . 解码的帧进入pict ( pFrame is a raw frame.) pFrame是原始帧。)

100x100 is probably no good you have to calculate pict size based on pFrame size. 您必须根据pFrame大小计算pict大小,否则100x100可能不好。 I guess it should be pFrame->width*pFrame->height*32; 我猜应该是pFrame->width*pFrame->height*32;

You have to allocate pict yourself. 您必须自己分配pict

See this tutorial http://dranger.com/ffmpeg/ 参见本教程http://dranger.com/ffmpeg/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM