小工具知识网

当前位置: 首页 > 行业知识 > [ffmpeg] 解码

行业知识

[ffmpeg] 解码

2026-10-21 00:39:43 来源:互联网转载
#include#include #include using namespace std;extern "C"{#include #include }#pragma comment(lib, "avcodec.lib")#pragma comment(lib, "avutil.lib")int main(int argc, char* argv[]){// 分割 h264 存入 AVPacketstring filename = "test.h264";ifstream ifs(filename, ios::binary);if (!ifs) return -1;unsigned char inbuf[4096] = { 0 };AVCodecID codec_id = AV_CODEC_ID_H264;// 1. 找解码器auto codec = avcodec_find_decoder(codec_id);// 2. 创建上下文auto c = avcodec_alloc_context3(codec);// 3. 打开上下文avcodec_open2(c, NULL, NULL);// 分割上下文auto parser = av_parser_init(codec_id);auto pkt = av_packet_alloc();auto frame = av_frame_alloc();while (!ifs.eof()){ifs.read((char*)inbuf, sizeof(inbuf));int data_size = ifs.gcount(); // 读取的字节数if (data_size  0){// 通过 0001 截取输出到 AVPacket 返回帧大小int ret = av_parser_parse2(parser, c,&pkt->data, &pkt->size, // 输出data, data_size, // 输入AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);data += ret;data_size -= ret; // 已处理if (pkt->size){//cout size break;}// 获取多帧解码数据while (ret = 0){// 每次会调用 av_frame_unrefret = avcodec_receive_frame(c, frame);if (ret 

上一篇:远程主机文件

下一篇:轻松上手EA下载教程,一步步教你如何轻松下载EA软件