Convert an H.264 bitstream from length prefixed mode to start code prefixed mode (as defined in the Annex B of the ITU-T H.264 specification).
This is required by some streaming formats, typically the MPEG-2 transport stream format (muxer mpegts).
annex-b系:传统派
annex-b格式 bitstream === 起始码前缀模式
利用startcode,分割nalu
pps sps存储在es中
流媒体直播使用格式, 比如常用格式有ts
avcc系:现代派
avc- c格式 container ==== 长度前缀模式
使用长度分割nalu
pps sps存储在container中
介质存储使用格式, 比如 flv mp4 mkv
针对avpacket使用,而不是其他数据结构
- h264使用的过滤器:h264_mp4toannexb
- h265使用的过滤器:hevc_mp4toannexb
static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out);
static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out);
转换为annexb :
ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
filter = av_bsf_get_by_name("h264_mp4toannexb");
if (!filter) {
av_log(avf, AV_LOG_ERROR, "h264_mp4toannexb bitstream filter "
"required for H.264 streams\n");
return AVERROR_BSF_NOT_FOUND;
}
ret = av_bsf_alloc(filter, &bsf);
if (ret < 0)
return ret;
cs->bsf = bsf;
ret = avcodec_parameters_copy(bsf->par_in, st->codecpar);
if (ret < 0)
return ret;
ret = av_bsf_init(bsf);
if (ret < 0)
return ret;