嗨,我已经有一些工作编码和h264的直接解码代码。我正在尝试调整代码以使用h265,但我在解码时出错了,因为我总是收到错误消息:
[hevc @ 0x78eca0] PPS id out of range: 0
[hevc @ 0x78eca0] Error parsing NAL unit #0.Init解码:
decoder = avcodec_find_decoder(AV_CODEC_ID_H265);
ctx = avcodec_alloc_context3(decoder);
ctx->extradata = NULL;
ctx->width = 400;
ctx->height = 256;
ctx->pix_fmt = AV_PIX_FMT_YUV420P;
avcodec_open2(ctx,decoder,NULL);编码,似乎没问题,因为我只处理小视频,我只能得到一个单独的nal:
x265_nal* nals;
unsigned int i_nals;
int ret = x265_encoder_encode(m_x265Encoder, &nals, &i_nals, m_picIn, m_picOut);
AVPacket avpkt;
av_init_packet(&avpkt);
avpkt.size = nals[0].sizeBytes;
avpkt.data = nals[0].payload;
AVFrame* frame = avcodec_alloc_frame();
int got=0;
avcodec_decode_video2(ctx,frame,&got,&avpkt);有人能帮我吗?
br迈克
发布于 2020-01-13 22:01:22
实际上我找到了一个有效的解决方案,这不是最好的代码,主要是为了测试,最终x265只是在cpu上变慢,无法跟上直播:
AVFrame* avpic = av_frame_alloc();
avpic->pts = msg.TimeStampCapture;
avpic->format = AV_PIX_FMT_YUV420P;
avpic->width = _dstFrameWidth;
avpic->height = _dstFrameHeight;
AVPicture tmppic;
avpicture_fill(&tmppic, pSrc, _rawFormat, _srcFrameWidth, _srcFrameHeight);
int err_sws = sws_scale(pSWSContext, tmppic.data, tmppic.linesize, 0, _srcFrameHeight, avpic->data, avpic->linesize);
int ret = av_image_alloc(avpic->data, avpic->linesize, avpic->width, avpic->height,AV_PIX_FMT_YUV420P,8 );
// Using scale Context to create avpic fore video2 encode
SwsContext* pSWSContext = sws_getContext(_srcFrameWidth, _srcFrameHeight, _rawFormat, _dstFrameWidth, _dstFrameHeight, AV_PIX_FMT_YUV420P, SWS_BILINEAR , 0, 0, 0);
sws_freeContext(pSWSContext);
int got_packet;
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = NULL; // packet data will be allocated by the encoder
pkt.size = 0;
ret = avcodec_encode_video2(_ectx,&pkt,avpic,&got_packet);
//count ++;
msg.pts = pkt.pts;
msg.dts = pkt.dts;
msg.count = count++;
msg.flags = pkt.flags;
nEncodedSize = pkt.size;
/// Decoder test
AVPacket avpkt;
av_init_packet(&avpkt);
avpkt.data = pkt.data;
avpkt.size = pkt.size;
avpkt.pts = pkt.pts;
avpkt.dts = pkt.dts;
avpkt.flags = pkt.flags;
avpkt.stream_index = pkt.stream_index;
AVFrame* frame = av_frame_alloc();
int got_picture = 0;
avcodec_decode_video2(m_cc,frame,&got_picture,&avpkt)
av_frame_free(&avpic);
av_packet_unref(&pkt);https://stackoverflow.com/questions/55188838
复制相似问题