root@ubuntu:/home/zhangbin/code# gcc -o tutorial03 tutorial03.c -lavformat -lavcodec -lz -lm `sdl-config --cflags --libs`
tutorial03.c:1:28: error: ffmpeg/avcodec.h: No such file or directory
tutorial03.c:2:29: error: ffmpeg/avformat.h: No such file or directory
tutorial03.c:16: error: expected specifier-qualifier-list before ‘AVPacketList’
tutorial03.c: In function ‘packet_queue_init’:
tutorial03.c:29: error: ‘PacketQueue’ has no member named ‘mutex’
tutorial03.c:30: error: ‘PacketQueue’ has no member named ‘cond’
tutorial03.c: At top level:
tutorial03.c:32: error: expected declaration specifiers or ‘...’ before ‘AVPacket’
tutorial03.c: In function ‘packet_queue_put’:
tutorial03.c:34: error: ‘AVPacketList’ undeclared (first use in this function)
tutorial03.c:34: error: (Each undeclared identifier is reported only once
tutorial03.c:34: error: for each function it appears in.)
tutorial03.c:34: error: ‘pkt1’ undeclared (first use in this function)
tutorial03.c:35: error: ‘pkt’ undeclared (first use in this function)
tutorial03.c:45: error: ‘PacketQueue’ has no member named ‘mutex’
tutorial03.c:47: error: ‘PacketQueue’ has no member named ‘last_pkt’
tutorial03.c:48: error: ‘PacketQueue’ has no member named ‘first_pkt’
tutorial03.c:50: error: ‘PacketQueue’ has no member named ‘last_pkt’
tutorial03.c:51: error: ‘PacketQueue’ has no member named ‘last_pkt’
tutorial03.c:52: error: ‘PacketQueue’ has no member named ‘nb_packets’
tutorial03.c:53: error: ‘PacketQueue’ has no member named ‘size’
tutorial03.c:54: error: ‘PacketQueue’ has no member named ‘cond’
tutorial03.c:56: error: ‘PacketQueue’ has no member named ‘mutex’
tutorial03.c: At top level:
tutorial03.c:59: error: expected declaration specifiers or ‘...’ before ‘AVPacket’
tutorial03.c: In function ‘packet_queue_get’:
tutorial03.c:61: error: ‘AVPacketList’ undeclared (first use in this function)
tutorial03.c:61: error: ‘pkt1’ undeclared (first use in this function)
tutorial03.c:64: error: ‘PacketQueue’ has no member named ‘mutex’
tutorial03.c:73: error: ‘PacketQueue’ has no member named ‘first_pkt’
tutorial03.c:75: error: ‘PacketQueue’ has no member named ‘first_pkt’
tutorial03.c:76: error: ‘PacketQueue’ has no member named ‘first_pkt’
tutorial03.c:77: error: ‘PacketQueue’ has no member named ‘last_pkt’
tutorial03.c:78: error: ‘PacketQueue’ has no member named ‘nb_packets’
tutorial03.c:79: error: ‘PacketQueue’ has no member named ‘size’
tutorial03.c:80: error: ‘pkt’ undeclared (first use in this function)
tutorial03.c:88: error: ‘PacketQueue’ has no member named ‘cond’
tutorial03.c:88: error: ‘PacketQueue’ has no member named ‘mutex’
tutorial03.c:91: error: ‘PacketQueue’ has no member named ‘mutex’
tutorial03.c: At top level:
tutorial03.c:95: error: expected ‘)’ before ‘*’ token
tutorial03.c: In function ‘audio_callback’:
tutorial03.c:139: error: ‘AVCodecContext’ undeclared (first use in this function)
tutorial03.c:139: error: ‘aCodecCtx’ undeclared (first use in this function)
tutorial03.c:139: error: expected expression before ‘)’ token
tutorial03.c:142: error: ‘AVCODEC_MAX_AUDIO_FRAME_SIZE’ undeclared (first use in this function)
tutorial03.c: In function ‘main’:
tutorial03.c:170: error: ‘AVFormatContext’ undeclared (first use in this function)
tutorial03.c:170: error: ‘pFormatCtx’ undeclared (first use in this function)
tutorial03.c:172: error: ‘AVCodecContext’ undeclared (first use in this function)
tutorial03.c:172: error: ‘pCodecCtx’ undeclared (first use in this function)
tutorial03.c:173: error: ‘AVCodec’ undeclared (first use in this function)
tutorial03.c:173: error: ‘pCodec’ undeclared (first use in this function)
tutorial03.c:174: error: ‘AVFrame’ undeclared (first use in this function)
tutorial03.c:174: error: ‘pFrame’ undeclared (first use in this function)
tutorial03.c:175: error: ‘AVPacket’ undeclared (first use in this function)
tutorial03.c:175: error: expected ‘;’ before ‘packet’
tutorial03.c:179: error: ‘aCodecCtx’ undeclared (first use in this function)
tutorial03.c:180: error: ‘aCodec’ undeclared (first use in this function)
tutorial03.c:215: error: ‘CODEC_TYPE_VIDEO’ undeclared (first use in this function)
tutorial03.c:219: error: ‘CODEC_TYPE_AUDIO’ undeclared (first use in this function)
tutorial03.c:291: error: ‘packet’ undeclared (first use in this function)
tutorial03.c:302: error: ‘AVPicture’ undeclared (first use in this function)
tutorial03.c:302: error: expected ‘;’ before ‘pict’
tutorial03.c:303: error: ‘pict’ undeclared (first use in this function)
tutorial03.c:312: error: ‘PIX_FMT_YUV420P’ undeclared (first use in this function)
tutorial03.c:313: error: expected expression before ‘)’ token
tutorial03.c:326: error: too many arguments to function ‘packet_queue_put’
root@ubuntu:/home/zhangbin/code#
改了一下头文件
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
会去/usr/local/include/libavcodec/avcodec.h寻找。
root@ubuntu:/home/zhangbin/code# vi tutorial03.c
root@ubuntu:/home/zhangbin/code# gcc -o tutorial03 tutorial03.c -lavformat -lavcodec -lz -lm `sdl-config --cflags --libs`
tutorial03.c: In function ‘audio_decode_frame’:
tutorial03.c:106: warning: ‘avcodec_decode_audio2’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3593)
tutorial03.c: In function ‘main’:
tutorial03.c:295: warning: ‘avcodec_decode_video’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3655)
/tmp/cc6TCXLI.o: In function `main':
tutorial03.c:(.text+0xa23): undefined reference to `img_convert'
collect2: ld returned 1 exit status
================================================
root@ubuntu:/etc/vim# vi vimrc
==============================================
发现原文是tutorial01.c
修改tutorial01.c发现:
root@ubuntu:/home/zhangbin/code# vi tutorial01.c
root@ubuntu:/home/zhangbin/code# gcc -o tutorial01 tutorial01.c -lavformat -lavcodec -lz
tutorial01.c: In function ‘main’:
tutorial01.c:128: warning: ‘avcodec_decode_video’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3655)
tutorial01.c:141: warning: ‘sws_getContext’ is deprecated (declared at /usr/local/include/libswscale/swscale.h:191)
/tmp/ccALn29e.o: In function `main':
tutorial01.c:(.text+0x425): undefined reference to `sws_getContext'
tutorial01.c:(.text+0x47f): undefined reference to `sws_scale'
collect2: ld returned 1 exit status
======================================================================
然后测试一下:
root@ubuntu:/home/zhangbin# tutorial01 oldboy.mp4
tutorial01: command not found
root@ubuntu:/home/zhangbin# ./tutorial01 oldboy.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'oldboy.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isom
creation_time : 2010-10-31 03:36:12
Duration: 00:42:37.76, start: 0.000000, bitrate: 506 kb/s
Stream #0.0(und): Video: h264, yuv420p, 672x378 [PAR 1:1 DAR 16:9], 471 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc
Metadata:
creation_time : 2010-10-26 15:52:54
Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 31 kb/s
Metadata:
creation_time : 2010-10-31 03:36:14
==========================
这次我选了一个305kB的mpg文件,因为作者给的参考就是mpg格式的。