Read H264 SPS & PPS NAL bytes using libavformat APIs

拟墨画扇 提交于 2019-12-08 06:48:05

问题


How to read H264 SPS & PPS NAL bytes using libavformat APIs?

I tried reading video data to 'AVPacket' structure using "av_read_frame(input_avFormatContext, &avPkt)" API, from a .mp4 video (codec is h264) file.

I dumped avPkt->data to a file. But 1st frame read is an IDR frame.

File generated using "ffmpeg -i video.mp4 video.h264" will contain SPS & PPS in the starting before start of IDR.

I want to extract raw .h264 video from .mp4 file and dump it in SPS,PPS, IDR, P1, P2... order.

I want to get this done programmatically using libavformat APIs.

Any idea on it?

Thanks.


回答1:


In mp4-container (mkv also) PPS/SPS are stored separate from frame data in global headers. To access them from libav* APIs you need to look for extradata field in AVCodecContext of AVStream which relate to needed video stream. Also extradata can have different format from standard H.264 NALs so look in MP4-container specs for format description.



来源:https://stackoverflow.com/questions/17279575/read-h264-sps-pps-nal-bytes-using-libavformat-apis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!