avcodec_decode_video 解码失败,got_picture返回0
来源:互联网 发布:sfp plus端口 编辑:程序博客网 时间:2024/05/21 18:36
//H264解码器初始化
bool H264DecodeInit(void)
{
//
int numBytes;
avcodec_init();
/* register all the codecs */
avcodec_register_all();
codecContext= NULL;
/* find the mpeg1 video decoder */
codec = avcodec_find_decoder(CODEC_ID_H264);
if (!codec) {
fprintf(stderr, "codec not found\n");
}
codecContext= avcodec_alloc_context();
codecContext->width=800;
codecContext->height=600;
codecContext->sample_fmt=SAMPLE_FMT_S16;
codecContext->pix_fmt=PIX_FMT_YUV420P;
m_pFrame= avcodec_alloc_frame();
if (m_pFrame==NULL)
{
return false;
}
m_pFrameRGB = avcodec_alloc_frame();
if(m_pFrameRGB == NULL)
{
return false;
}
if(codec->capabilities&CODEC_CAP_TRUNCATED)
codecContext->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
/* For some codecs, such as msmpeg4 and mpeg4, width and height
MUST be initialized there because this information is not
available in the bitstream. */
/* open it */
if (avcodec_open(codecContext, codec) < 0) {
fprintf(stderr, "could not open codec\n");
}
numBytes=avpicture_get_size(PIX_FMT_RGB24, 800, 600);
m_buffer=new uint8_t[numBytes];
// Assign appropriate parts of buffer to image planes in pFrameRGB
avpicture_fill((AVPicture *)m_pFrameRGB, m_buffer, PIX_FMT_RGB24, 800 ,600);
return true;
}
//H264 解码函数
void H264DecodeProcess(struct buffer_desc desc)
{
int got_picture,len;
len = avcodec_decode_video(codecContext, m_pFrame, &got_picture,
(uint8_t *)desc.buffer, desc.valid_len); //Rtp码流已经解包放在desc.buffer中,buffer的长度为desc.valid_len 调用这个函数got_picture=0;
if (len != desc.valid_len) {
printf("decode error\n");
}
img_convert((AVPicture *)m_pFrameRGB, PIX_FMT_BGR24,(AVPicture*)m_pFrame,codecContext->pix_fmt, codecContext->width,codecContext->height);
//显示图像
return;
}
如果我将Rtp码流解包后,直接丢给解码模块,实时解码,发现//Rtp码流已经解包放在desc.buffer中,buffer的长度为desc.valid_len 第一次调用avcodec_decode_video
这个函数got_picture=0;第2次调用avcodec_decode_video这个函数就可以得到正确的值,即我的每解码一帧要调用avcodec_decode_video,2次,很诧异,有路过的高手指点下。
我的码流中只有IDR帧和P帧,对Rtp包解码后,对sps和pps,idr,p帧前面都加了00 00 00 01开始标记
- avcodec_decode_video 解码失败,got_picture返回0
- avcodec_decode_video2(pCodecCtx, m_pFrame, &got_picture, &m_packet); got_picture总为0
- avcodec_decode_video解码的帧为什么后面的比前面的pts小
- UpdateLayeredWindow()失败,GetLastError()返回0
- json_decode解码失败.
- json_decode解码失败.
- mediacodec surfaceview解码失败
- CoCreateInstance失败,返回错误码0x8007007e
- json_decode解码失败的原因
- 服务器返回常见错误解码
- CreateWindow返回Handle失败
- AVIStreamGetFrameOpen返回null失败
- ajax 返回失败
- 返回代码失败
- APNs连接失败,返回错误码为0
- malloc函数申请内存失败,返回空NULL(0)
- android 启动socket 失败:socket(af_inet sock_stream 0) 返回-1
- open 总是失败 返回-1 android6.0 selinux策略问题
- SQL Server 2005“备份集中的数据库备份与现有的数据库不同”解决方法
- Sql Server查询性能优化之不可小觑的书签查找
- ARM 寄存器说明
- 日志程序
- shell 命令
- avcodec_decode_video 解码失败,got_picture返回0
- JMS学习
- Fedora 9 添加yum并进行源更新
- 线段树基本操作模板 hdu1166 hdu1754
- VIM
- 各种Ajax框架的对比介绍:
- BREW开发教程(1):BREW SDK一览
- BREW开发教程(2):BREW基础
- linux 串口应用开发