Analyze the cause of the problem
We often encounter "a file is not defined" error when developing:
As shown in the figure above, when I was learning ffmpeg development, I followed the video step by step. The teacher's video was very smooth, but the code I operated by myself could not be compiled anyway. The error is as shown above.
Let me talk about the installation steps of my ffmpeg;
1. Open http://ffmpeg.org/download.html
2. Directly copy the address of the cloned git code on the official website download home page, and then compile and install it
All command line operations are no problem.
When using C language to develop ffmpeg to manipulate files, there is a problem.
The original code is as follows:
zh@zh-lpc:~/project/ffmpeg$ cat ff.c
#include <stdio.h>
#include <libavutil/log.h>
//#include <libavformat/avio.h>
#include <libavformat/avformat.h>
int main()
{
char *fileName="./test.txt";
int ret;
ret=avpriv_io_delete(fileName);
if(ret < 0)
{
av_log(NULL,AV_LOG_ERROR,"Fail to delete file %s \n",fileName);
return -1;
}
return 0;
}
zh@zh-lpc:~/project/ffmpeg$
Encountered when compiling:
Just look in the ffmpeg installation directory to see if there is a file containing this function:
As a result, neither
zh@zh-lpc:~/project/ffmpeg$ grep -nr "avpriv_io_delete" /usr/local/ffmpeg
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$ cat /usr/local/ffmpeg/include/libavformat/avformat.h |grep "avpriv_io_delete"
zh@zh-lpc:~/project/ffmpeg$
Seeing that the netizen said that the "avpriv_io_delete" function is in the avio.h file, I searched it, and the result is still no:
zh@zh-lpc:~/project/ffmpeg$ cat /usr/local/ffmpeg/include/libavformat/avio.h |grep "avpriv_io_delete"
zh@zh-lpc:~/project/ffmpeg$
很无奈,就猜想是自己编译的代码肯定存在问题的。
想着ffmpeg这么正规,肯定有很详细的api文档,或者其他文档说明。
Just searched the official website.
Sure enough, I saw the API Documentation column.
You can view the api of the version you want to view.
I checked version 4.1:
http://ffmpeg.org/doxygen/4.1/index.html
I looked it up in the avformat.h file, and it was not there:
Just opened the avio.h file:
searched, and sure enough related functions exist:
Solution
Since this function exists in version 4.1, I just need to re-download the code of version 4.1, and then recompile and install it.
这样还是挺麻烦的,因为是git,可以利用切换分支来解决版本的问题。
If you want to switch branches, you first need to find out what the id of version 4.1 is.
Open the Download interface in the official website again, and then enter the Browse interface in git
Address:
https://git.ffmpeg.org/gitweb/ffmpeg.git
Directly select a version of 4.1.x to enter the commit
Here you can see the commit id of the commit:
commit 4521700f295f35da4768f88b570e0836a858ce7b
tree 53e22f7d49cc946c635373d32abfa556961067ed
parent 2f54cd9548e2a8fe0ecba9a345b66f0798dd243e
Then enter your own ffmpeg storage directory and use the following command to switch branches:
git switch -c 2f54cd9548e2a8fe0ecba9a345b66f0798dd243e
After the switch, you can use git log to check whether the switch is successful, and where it is currently:
Then just recompile and install.
You can refer to what was written before:
https://truedei.blog.csdn.net/article/details/120188699
verify
It can be seen that there is now
zh@zh-lpc:~/project$ cat /usr/local/ffmpeg/include/libavformat/avformat.h |grep "avpriv_io_delete"
zh@zh-lpc:~/project$
zh@zh-lpc:~/project$
zh@zh-lpc:~/project$ cat /usr/local/ffmpeg/include/libavformat/avio.h |grep "avpriv_io_delete"
int avpriv_io_delete(const char *url);
zh@zh-lpc:~/project$
Recompiling and executing also succeeded:
zh@zh-lpc:~/project/ffmpeg$ gcc -g ff.c -o ff -I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavformat -lavutil
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$ ls
ff ff.c ffmpeg_file.c hello helloword.c
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$ touch test.txt
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$ ls
ff ff.c ffmpeg_file.c hello helloword.c test.txt
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$ ./ff
zh@zh-lpc:~/project/ffmpeg$
zh@zh-lpc:~/project/ffmpeg$ ls
ff ff.c ffmpeg_file.c hello helloword.c
zh@zh-lpc:~/project/ffmpeg$
After testing it, it is possible to write "libavformat/avio.h" and "libavformat/avformat.h" in the header file:
Because the avio.h header file is included in avformat.h.
#include <stdio.h>
#include <libavutil/log.h>
//#include <libavformat/avio.h>
#include <libavformat/avformat.h>
int main()
{
char *fileName="./test.txt";
int ret;
ret=avpriv_io_delete(fileName);
if(ret < 0)
{
av_log(NULL,AV_LOG_ERROR,"Fail to delete file %s \n",fileName);
return -1;
}
return 0;
}
~