libavcodec视频解码不起作用
libavcodec video decoding not working
我正在尝试解码用H264编码的视频。我正在将AVPacket的数据及其大小发送到解码器代码。在那里,我正在尝试解码框架并将其显示在 GUI 上。问题是当我解码帧时,它返回的帧字节数与数据包的大小相同,这意味着它没有解压缩数据。谁能说出问题是什么。我的编码程序工作正常。
这是用于编码的代码
static struct SwsContext *img_convert_ctx;
pkt.data = NULL;
pkt.size = 0;
avpicture_fill((AVPicture *)srcFrame, frame,AV_PIX_FMT_BGR24, 640, 480);
if(img_convert_ctx == NULL) {
int w = 640;
int h = 480;
img_convert_ctx = sws_getContext(w, h,
AV_PIX_FMT_BGR24, c->width, c->height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
if(img_convert_ctx == NULL) {
fprintf(stderr, "Cannot initialize the conversion context!n");
}
}
sws_scale(img_convert_ctx, srcFrame->data, srcFrame->linesize, 0,480,picture->data, picture->linesize);
fflush(stdout);
picture->pts=counter;
ret = avcodec_encode_video2(c, &pkt, picture, &got_output);
if (ret < 0) {
fprintf(stderr, "Error encoding framen");
}
if (got_output) {
vdec.decode_frame(pkt.data ,pkt.size);
av_free_packet(&pkt);
}
解码器代码...
int len ,got_frame;
avpkt.size = data_length;
avpkt.data = frame_buffer;
if(!frame_buffer){
return "frame buffer emptyn";
}
len = avcodec_decode_video2(avctx ,frame ,&got_frame ,&avpkt);
if( len < 0){
return "error while decodingn";
}
if( got_frame ){
static struct SwsContext *img_convert_ctx;
if(img_convert_ctx == NULL) {
img_convert_ctx = sws_getContext(w, h,
PIX_FMT_YUV420P, avctx->width,
avctx->height, PIX_FMT_BGR24,
SWS_BICUBIC, NULL, NULL, NULL);
if(img_convert_ctx == NULL) {
return "Cannot initialize the conversion context!n";
}
}
j=sws_scale(img_convert_ctx,
frame->data , frame->linesize ,
0, h ,picture->data,
picture->linesize );
if(j==0){
exit(1);
}
我正在将所有其他代码(如AVCodecContext和编解码器)初始化为其他方法。
请帮助我找到解决方案。
avcodec_decode_video2
函数应返回处理的字节数,而不是结果图片的字节数。您只需要检查got_frame
的值即可了解何时解码完整帧。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- 为什么视频捕获在成员函数中不起作用?
- 为什么我的从base64解码的函数不起作用?
- FFmpeg + OpenAL - 播放视频中的流声音不起作用
- 视频抓取不起作用 OpenCV
- 编解码器在 gcc 中不起作用
- 的视频播放器不起作用
- 如何在OpenCV中设置相机的视频格式?CAP_PROP_FOURCC不起作用
- libavcodec视频解码不起作用