ffmpeg解码h265码流
时间: 2023-08-26 12:07:05 浏览: 42
ffmpeg是一个用于处理多媒体文件的开源程序库,可以在多个平台上使用。要解码H.265码流,需要使用ffmpeg的libavcodec库。以下是基本的代码示例:
```
#include <libavutil/frame.h>
#include <libavcodec/avcodec.h>
int main() {
avcodec_register_all();
AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_HEVC);
AVCodecContext* codec_ctx = avcodec_alloc_context3(codec);
avcodec_open2(codec_ctx, codec, NULL);
AVPacket pkt;
av_init_packet(&pkt);
// 读取H.265码流到pkt中
AVFrame* frame = av_frame_alloc();
int ret = avcodec_send_packet(codec_ctx, &pkt);
while (ret >= 0) {
ret = avcodec_receive_frame(codec_ctx, frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
break;
} else if (ret < 0) {
fprintf(stderr, "Error while decoding : %d\n", ret);
exit(1);
} else {
// 对解码后的frame进行处理
}
}
av_packet_unref(&pkt);
av_frame_free(&frame);
avcodec_free_context(&codec_ctx);
return 0;
}
```