ffmpeg-libav-tutorial
ffmpeg-libav-tutorial copied to clipboard
Cannot compile, using ffmpeg from sources
Hello, I'm using Ubuntu 18.04, did a clean install in a virtual machine. I downloaded libvpx from sources, compiled and installed without any problems. Then I downloaded ffmpeg source (from git, from git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg), and compiled it (passing --enable-libvpx to it), make compiled without any issues, and did a make install.
When I try to make the 0_hello_world.c, make gives me the following error: (you can check the output with a better looking text at https://pastebin.com/wPKY99ue )
mkdir build
gcc -g -Wall -o build/hello_world -lavformat -lavcodec -lswscale -lavutil -lz 0_hello_world.c
&& ./build/hello_world small_bunny_1080p_60fps.mp4`
0_hello_world.c: In function βmainβ:
0_hello_world.c:35:3: warning: βav_register_allβ is deprecated [-Wdeprecated-declarations]
av_register_all();
^~~~~~~~~~~~~~~
In file included from 0_hello_world.c:15:0:
/usr/local/include/libavformat/avformat.h:2033:6: note: declared here
void av_register_all(void);
^~~~~~~~~~~~~~~
/tmp/ccbsfyh8.o: In function 'av_make_error_string':
/usr/local/include/libavutil/error.h:111: undefined reference to 'av_strerror'
/tmp/ccbsfyh8.o: In function 'main':
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:35: undefined reference to 'av_register_all'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:40: undefined reference to 'avformat_alloc_context'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:54: undefined reference to 'avformat_open_input'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:73: undefined reference to 'avformat_find_stream_info'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:103: undefined reference to 'avcodec_find_decoder'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:125: undefined reference to 'avcodec_alloc_context3'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:134: undefined reference to 'avcodec_parameters_to_context'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:142: undefined reference to 'avcodec_open2'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:149: undefined reference to 'av_frame_alloc'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:156: undefined reference to 'av_packet_alloc'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:180: undefined reference to 'av_packet_unref'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:168: undefined reference to 'av_read_frame'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:185: undefined reference to 'avformat_close_input'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:186: undefined reference to 'avformat_free_context'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:187: undefined reference to 'av_packet_free'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:188: undefined reference to 'av_frame_free'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:189: undefined reference to 'avcodec_free_context'
/tmp/ccbsfyh8.o: In function 'decode_packet':
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:207: undefined reference to 'avcodec_send_packet'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:218: undefined reference to 'avcodec_receive_frame'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:230: undefined reference to 'av_get_picture_type_char'
/home/xultz/libav/ffmpeg-libav-tutorial/0_hello_world.c:242: undefined reference to 'av_frame_unref'
collect2: error: ld returned 1 exit status
Makefile:4: recipe for target 'hello_world' failed
make: *** [hello_world] Error 1
I took a look at pkg-config outputs from --libs and --cflags for some libs (lib libavformat, libavutil, etc) and I changed the gcc line on the Makefile to the following, but I couldn't see any changes on the make output:
gcc -g -Wall -I/usr/local/include -o build/hello_world -L/usr/local/lib -lavformat -lavcodec -lswscale -lavutil -lz -lvpx -lm -lswresample -pthread 0_hello_world.c
What else can I do in order to compile the code?
Thank you in advance for any help!
Hi,
I'm compiling with a different setup (on Ubuntu16 and not from ffmpeg sources) but I had a similar error, so my solution might work for you as well.
I moved all the library parameters after the source file name, like this:
gcc -g -Wall -o build/hello_world 0_hello_world.c -lavformat -lavcodec -lswscale -lavutil -lz
and I could compile successfully.
Hi
I use Ubuntu18.04, and ffmpeg-4.0.1 source code, and use
./configure --disable-x86asm --disable-doc --prefix=output
to make, make install
I use
gcc -o build/hello_world -g -Wall 0_hello_world.c -I./include -L./lib -lavformat -lavcodec -lswscale -lavutil -lswresample -lz -lm -lpthread
It could compile well
I have same errors. How to build with CMakeLists.txt in Clion IDE of intellij?
I add -lavformat -lavcodec -lswscale -lavutil -lz
to target_link_libraries
but the output like /usr/bin/ld: cannot find -lavformat_alloc_context
.
I have same errors. How to build with CMakeLists.txt in Clion IDE of intellij? I add
-lavformat -lavcodec -lswscale -lavutil -lz
totarget_link_libraries
but the output like/usr/bin/ld: cannot find -lavformat_alloc_context
.
I solved:
target_link_libraries(avformat avutil)
. Adding other if necessary. I think with lavformat
, I can drop l
characer.
For me, the following worked: gcc -g -Wall -L/home/vandana/ffmpeg/ /home/vandana/ipdecoder/ffmpeg_custom/transcoding.c /home/vandana/ipdecoder/ffmpeg_custom/video_debugging.c -lavformat -lavcodec -lx264 -lavdevice -lavfilter -lavutil -lswscale -lswresample -lm -lz -lpthread -o /home/vandana/ipdecoder/ffmpeg_custom/build/transcoding
Instructions for Ubuntu 20.04, using ffmpeg from master branch on git repo (as of 2021-02-28). Asuming a "ffmpeg" directory created inside home.
- ffmpeg repo:
-
cd ~/ffmpeg
-
git clone https://git.ffmpeg.org/ffmpeg.git repo
-
cd repo
-
./configure --enable-gpl --disable-programs
(this may vary, but the point of "disable programs" is to not replace the ffmpeg executable from ubuntu repos: we just need the libs for this tutorial). -
make
-
sudo make install
-
- ffmpeg-libav-tutorial "hello world" compilation:
-
cd ~/ffmpeg
-
git clone https://github.com/leandromoreira/ffmpeg-libav-tutorial
-
cd ffmpeg-libav-tutorial
-
gcc -g -Wall 0_hello_world.c $(pkg-config --libs libavformat libavcodec libavdevice libavfilter libavutil libswscale libswresample) -lz -o build/hello
-