我在iphone下使用ffmpeg解实时流,但是解出来的东西 图形丢失太严重了

avcodec_decode_video2接收实时流使用问题

我在iphone下使用ffmpeg解实时流,但是解出来的东西  图形丢失太严重了。
代码如下:
av_register_all();
pCodecCtx = avcodec_alloc_context();
codecid = avcodec_find_decoder(CODEC_ID_H264);
pFrame=avcodec_alloc_frame();
avcodec_open(pCodecCtx,codecid);
pCodecCtx->width = 352;
pCodecCtx->height = 288;
pCodecCtx->pix_fmt = PIX_FMT_YUV420P;
self.outputWidth = 704;
self.outputHeight = 532;
AVPacket packet;
av_init_packet(&packet);
char *cTest=malloc(10240);
memset(cTest, 0, 10240);
int temp=0;
int nImageSize;
while (bYes)
{
        unsigned char cData[4096];
        int ref = recv([xteozzdAppDelegate Apple].appSocket.playerSocketID , cData, 4096, 0);
        if(ref==-1)
       {
                break;
        }
        NSLog(@"ref:%d",ref);
        char *cBefore = cTest;
        memcpy(cBefore+temp, &cData, ref);
        packet.size = ref+temp;
        NSLog(@"packet.size:%d",packet.size);
        packet.data = (unsigned char*)cTest;
        int got_picture_ptr=0;
        nImageSize = avcodec_decode_video2(pCodecCtx,pFrame,&got_picture_ptr,&packet);
        NSLog(@"nImageSize:%d--got_picture_ptr:%d",nImageSize,got_picture_ptr);
        if(nImageSize>0)
        {
                if (!pFrame->data[0])
                {
                        continue;
                }
                temp = packet.size - nImageSize;
                NSLog(@"temp:%d---packet.size:%d",temp,packet.size);
                packet.size -= nImageSize;
                cTest += temp;   
                [self performSelectorOnMainThreadselector(UpdateImageView) withObject:nil waitUntilDone:YES];
        }
        else
        {
                temp = packet.size;
        }
}
avcodec_decode_video2这个参数传入的AVPacket 的size 是多少  方法的返回值就是多少
这是我哪个地方设置错误了吗?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值