因为是直接从裸流写出,需要对
p_outContex->flags |= CODEC_FLAG_GLOBAL_HEADER;
p_outContex->extradata_size = sps.size(); //缺少将导致win player无法播放
p_outContex->extradata = (unsigned char*)av_malloc(sps.size());
memcpy(p_outContex->extradata, &sps[0], sps.size());
p_outContex->width = w;
p_outContex->height = h;
p_outContex->codec_id= AV_CODEC_ID_H264;
p_outContex->codec_type = AVMEDIA_TYPE_VIDEO;
p_outContex->pix_fmt = AV_PIX_FMT_YUV420P;
out_stream->codecpar->bit_rate = 400000;
out_stream->time_base.den = 90000;
out_stream->time_base.num = 1;
这几项完整赋值
在写入pack时对
p_pkt.data = (BYTE*)pData;
p_pkt.size = size;
if (keyframe)
{
p_pkt.flags = AV_PKT_FLAG_KEY;//缺少将导致无封面,无分块(stco 空节),无法拖动
}
p_pkt.duration = p_st;//持续时间
p_pkt.pts = m_vTime;//显示时间
p_pkt.dts = p_pkt.pts;//解码时间
p_pkt.pos = -1;
p_pkt.stream_index = m_videoindex_out;
完整赋值