gpt4 book ai didi

c - fatal error :libavcodec/avcodec.h No such file or directory

转载 作者:行者123 更新时间:2023-11-30 16:32:56 24 4
gpt4 key购买 nike

我尝试在我的ubuntu1604平台上调试ffmpeg,但它总是说找不到头文件,但实际上我确实在编译代码中包含了头文件。

错误信息如下: error message

这是我的测试代码:

 #include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"

int main(int argc, char * argv[]){
av_register_all();
AVFormatContext *pFormatCtx = NULL;

// Open video file
if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) !=0 )
return -1; // Couldn't open file

// Retrieve stream information
if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
return -1; // Couldn't find stream information

// Dump information about file onto standard error
av_dump_format(pFormatCtx, 0, argv[1], 0);

int i;
AVCodecContext *pCodecCtxOrig = NULL;
AVCodecContext *pCodecCtx = NULL;

// Find the first video stream
int videoStream = -1;
for(i=0; i<pFormatCtx->nb_streams; i++)
if (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
videoStream = 1;
break;
}

if (videoStream == -1)
return -1; // Didn't find a video stream

// Get a pointer to the codec context for the video stream
pCodecCtx = pFormatCtx->streams[videoStream]->codec;

AVCodec *pCodec = NULL;
// Find the decoder for the video stream
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec==NULL){
fprintf(stderr, "Unsupported codec!\n");
return -1; // Codec not found
}

// Copy context
pCodecCtx = avcodec_alloc_context3(pCodec);
if (avcodec_copy_context(pCodecCtx, pCodecCtxOrig) !=0 ){
fprintf(stderr, "Couldn't copy codec context");
return -1; // Error copying codec context
}

// Open codec
if (avcodec_open2(pCodecCtx, pCodec, NULL)<0)
return -1; // Could not open codec

AVFrame *pFrame = NULL;
// Allocate video fream
pFrame = av_frame_alloc();

// Allocate an AVFrame structure
AVFrame *pFrameRGB = NULL;
pFrameRGB = av_frame_alloc();
if(pFrameRGB == NULL)
return -1;
}

以下是我的 Makefile

C++     = gcc
INCLUDE_DIR = ./include
LIB_DIR = ./lib
BIN_DIR = ./build/bin
TARGET = $(BIN_DIR)/mk-screen-caps

INC_PATH += -I./ -I$(INCLUDE_DIR)
LIBS += -lstdc++ -lm -lgcc_s -lgcc -lc
LIBS += $(LIB_DIR)/libavcodec.a $(LIB_DIR)/libavdevice.a
$(LIB_DIR)/libavfilter.a
LIBS += $(LIB_DIR)/libavformat.a $(LIB_DIR)/libavutil.a
$(LIB_DIR)/libfdk-aac.a
LIBS += $(LIB_DIR)/libmp3lame.a $(LIB_DIR)/libopus.a
$(LIB_DIR)/libpostproc.a
LIBS += $(LIB_DIR)/libswresample.a $(LIB_DIR)/libswscale.a
$(LIB_DIR)/libx264.a
LIBS += $(LIB_DIR)/libx265.a $(LIB_DIR)/libyasm.a

C++_FLAGS += -pipe -g -Wall -o0

C_FILES += $(wildcard ./*.c);
CPP_FILES += $(wildcard ./*.cpp)
HEAD_FILES += $(wildcard $(INCLUDE_DIR)/*.h)

C_OBJS=$(C_FILES:.c=.o)
CPP_OBJS=$(CPP_FILES:.cpp=.O)

all: $(TARGET)
$(TARGET): $(CPP_OBJS)
$(C++) $(C++_FLAGS) -o $@ $(CPP_FILES) $(LIBS)

%.o: %.c $(HEAD_FILES)
$(C++) -c $(C_FILES) $(INC_PATH) $< -o $@
%.O: %.cpp $(HEAD_FILES)
$(C++) -c $(CPP_FLAGS) $(INC_PATH) $< -o $@

clean:
rm -f $(TARGET) $(C_OBJS) $(CPP_OBJS)

以下是我的目录信息:

mk-screen-caps(父目录)

--构建

--bin

--包括

--(需要包含文件和目录)

--lib

--(需要的库)

最佳答案

根据发布的错误消息,您的 INC_PATH Make 变量未使用。因此,gcc 找不到 avcodec.h

也许您已经更改了 Makefile,因为如果我运行上面发布的文件,它实际上使用了模式规则 %.O: %.cpp $(HEAD_FILES)

尝试运行make --debug。对我来说,这会导致:

$ make --debug
GNU Make 4.1
Built for aarch64-unknown-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
File 'all' does not exist.
File 'build/bin/mk-screen-caps' does not exist.
File 'test.O' does not exist.
Must remake target 'test.O'.
gcc -c -I./ -I./include test.cpp -o test.O
test.cpp:2:33: fatal error: libavcodec/avcodec.h: No such file or directory
compilation terminated.
Makefile:31: recipe for target 'test.O' failed
make: *** [test.O] Error 1

它也失败了,因为我在任何目录.include中都没有libavcodec/avcodec.h。但可以看出,include目录列表实际上是在gcc的调用中使用的。

关于c - fatal error :libavcodec/avcodec.h No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49923107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com