start code 关键字,标志一帧的结束和开始
SPS/PPS 视频的关键格式数据 在codec->extradata,放在每个关键帧开头
一个packet可能存放很多帧,也可能只有一帧
#include<iostream>
using namespace std;
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
};
#ifndef AV_WB32
# define AV_WB32(p, val) do { \
uint32_t d = (val); \
((uint8_t*)(p))[3] = (d); \
((uint8_t*)(p))[2] = (d)>>8; \
((uint8_t*)(p))[1] = (d)>>16; \
((uint8_t*)(p))[0] = (d)>>24; \
} while(0)
#endif
#ifndef AV_RB16
# define AV_RB16(x) \
((((const uint8_t*)(x))[0] << 8) | \
((const uint8_t*)(x))[1])
#endif
static int alloc_and_copy(AVPacket* out,
const uint8_t* sps_pps, uint32_t sps_pps_size,
const uint8_t* in, uint32_t in_size)///加特征值
{
uint32_t offset = out->size;
uint8_t nal_header_size = offset ? 3 : 4;//sps/pps特征码00 00 00 01四字节 其他的特征码00 00 01
int err;
err = av_grow_packet(out, sps_pps_size + in_size + nal_header_size);//扩容
if (err < 0)
return err;
if (sps_pps)
memcpy(out->data + offset, sps_pps, sps_