Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

raw h.264 bitstream decoding

I can get raw h.264 frames from a camera. (it does NOT contain any network headers, for example rtsp, http). They are h.264 raw data. And I push these data to a queue frame by frame. I googled many ffmpeg example which uses avformat_open_input() with either local file path or network path. And I can see the video while I save the frames to a file and using avformat_open_input().

My problem is that I want to decode the frames realtime, not after it is saved as a file. Does anyone have any idea on this?

Thanks!

like image 487
srjohnhuang Avatar asked Feb 09 '23 01:02

srjohnhuang


1 Answers

You do not need avformat, you need avcodec. avformat is for parsing containers and protocols. avcodec is for encoding and decoding elementary streams (what you already have).

AVPacket avpkt; int err, frame_decoded = 0;
AVCodec *codec = avcodec_find_decoder ( AV_CODEC_ID_H264 );
AVCodecContext *codecCtx = avcodec_alloc_context3 ( codec );
avcodec_open2 ( codecCtx, codec, NULL );
// Set avpkt data and size here
err = avcodec_decode_video2 ( codecCtx, avframe, &frame_decoded, &avpkt );
like image 62
szatmary Avatar answered Mar 04 '23 07:03

szatmary