问题
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