1.安装(ubuntu18.04)
a.下载源码:git clone https://gitee.com/mirrors/ffmpeg.git
b.编译:cd ffmpeg && ./configure --enable-gpl --enable-shared && make && make install
2.代码验证:根据《最简单的基于FFMPEG的Helloworld程序》-雷霄骅 修改
hello.cpp
/** * 最简单的FFmpeg Helloworld程序 * Simplest FFmpeg HelloWorld * * 雷霄骅 Lei Xiaohua * leixiaohua1020@126.com * 中国传媒大学/数字电视技术 * Communication University of China / Digital TV Technology * http://blog.csdn.net/leixiaohua1020 * * * 本程序是基于FFmpeg函数的最简单的程序。它可以打印出FFmpeg类库的下列信息: * Protocol: FFmpeg类库支持的协议 * AVFormat: FFmpeg类库支持的封装格式 * AVCodec: FFmpeg类库支持的编解码器 * AVFilter: FFmpeg类库支持的滤镜 * Configure: FFmpeg类库的配置信息 * * This is the simplest program based on FFmpeg API. It can show following * informations about FFmpeg library: * Protocol: Protocols supported by FFmpeg. * AVFormat: Container format supported by FFmpeg. * AVCodec: Encoder/Decoder supported by FFmpeg. * AVFilter: Filters supported by FFmpeg. * Configure: configure information of FFmpeg. * */ #include <stdio.h> #ifdef __cplusplus extern "C" { #endif #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavfilter/avfilter.h> #ifdef __cplusplus }; #endif #define __STDC_CONSTANT_MACROS //FIX struct URLProtocol; /** * Protocol Support Information */ char * urlprotocolinfo(){ char *info=(char *)malloc(40000); memset(info,0,40000); //av_register_all(); struct URLProtocol *pup = NULL; //Input struct URLProtocol **p_temp = &pup; avio_enum_protocols((void **)p_temp, 0); while ((*p_temp) != NULL){ sprintf(info, "%s[In ][%10s]\n", \ info, avio_enum_protocols((void **)p_temp, 0)); } pup = NULL; //Output avio_enum_protocols((void **)p_temp, 1); while ((*p_temp) != NULL){ sprintf(info, "%s[Out][%10s]\n", \ info, avio_enum_protocols((void **)p_temp, 1)); } return info; } /** * AVFormat Support Information */ char * avformatinfo(){ char *info=(char *)malloc(40000); memset(info,0,40000); //av_register_all(); //AVInputFormat *if_temp = av_iformat_next(NULL); //AVOutputFormat *of_temp = av_oformat_next(NULL); void *iteri = NULL; void *itero = NULL; const AVInputFormat *if_temp; const AVOutputFormat *of_temp; //Input while(if_temp = av_demuxer_iterate(&iteri)){ if(!if_temp->priv_class) continue; sprintf(info, "%s[In ] %10s\n", info, if_temp->name); //if_temp=if_temp->next; } //Output while (of_temp = av_muxer_iterate(&itero)){ if(!of_temp->priv_class) continue; sprintf(info, "%s[Out] %10s\n", info, of_temp->name); //of_temp = of_temp->next; } return info; } /** * AVCodec Support Information */ char * avcodecinfo(){ char *info=(char *)malloc(40000); memset(info,0,40000); //av_register_all(); //AVCodec *c_temp = av_codec_next(NULL); void *iter = NULL; const AVCodec *c_temp; while(c_temp = av_codec_iterate(&iter)){ if(!c_temp->priv_class) continue; if (c_temp->decode!=NULL){ sprintf(info, "%s[Dec]", info); }else{ sprintf(info, "%s[Enc]", info); } switch (c_temp->type){ case AVMEDIA_TYPE_VIDEO: sprintf(info, "%s[Video]", info); break; case AVMEDIA_TYPE_AUDIO: sprintf(info, "%s[Audio]", info); break; default: sprintf(info, "%s[Other]", info); break; } sprintf(info, "%s %10s\n", info, c_temp->name); } return info; } /** * AVFilter Support Information */ char * avfilterinfo(){ char *info=(char *)malloc(40000); memset(info,0,40000); //avfilter_register_all(); //AVFilter *f_temp = (AVFilter *)avfilter_next(NULL); void *iter = NULL; const AVFilter *f_temp; while (f_temp = av_filter_iterate(&iter)){ if(!f_temp->priv_class) continue; sprintf(info, "%s[%15s]\n", info, f_temp->name); //f_temp=f_temp->next; } return info; } /** * Configuration Information */ char * configurationinfo(){ char *info=(char *)malloc(40000); memset(info,0,40000); //av_register_all(); sprintf(info, "%s\n", avcodec_configuration()); return info; } int main(int argc, char* argv[]){ char *infostr=NULL; infostr=configurationinfo(); printf("\n<<Configuration>>\n%s",infostr); free(infostr); infostr=urlprotocolinfo(); printf("\n<<URLProtocol>>\n%s",infostr); free(infostr); infostr=avformatinfo(); printf("\n<<AVFormat>>\n%s",infostr); free(infostr); infostr=avcodecinfo(); printf("\n<<AVCodec>>\n%s",infostr); free(infostr); infostr=avfilterinfo(); printf("\n<<AVFilter>>\n%s",infostr); free(infostr); return 0; }
Makefile
CLFAGS = -lavcodec -lavformat -lavfilter all: g++ -o hello hello.cpp $(CLFAGS)
3.运行结果
<<Configuration>>
--enable-gpl --enable-shared
<<URLProtocol>>
[In ][ cache]
[In ][ concat]
[In ][ concatf]
[In ][ crypto]
[In ][ data]
[In ][ffrtmphttp]
[In ][ file]
[In ][ ftp]
[In ][ gopher]
[In ][ hls]
[In ][ http]
[In ][ httpproxy]
[In ][ mmsh]
[In ][ mmst]
[In ][ pipe]
[In ][ rtmp]
[In ][ rtmpt]
[In ][ rtp]
[In ][ srtp]
[In ][ subfile]
[In ][ tcp]
[In ][ udp]
[In ][ udplite]
[In ][ unix]
[In ][ (null)]
[Out][ffrtmphttp]
[Out][ file]
[Out][ ftp]
[Out][ gopher]
[Out][ http]
[Out][ httpproxy]
[Out][ icecast]
[Out][ md5]
[Out][ pipe]
[Out][ prompeg]
[Out][ rtmp]
[Out][ rtmpt]
[Out][ rtp]
[Out][ srtp]
[Out][ tee]
[Out][ tcp]
[Out][ udp]
[Out][ udplite]
[Out][ unix]
[Out][ (null)]
<<AVFormat>>
[In ] aa
[In ] ac3
[In ] acm
[In ] adf
[In ] apng
[In ] aptx
[In ] aptx_hd
[In ] aqtitle
[In ] asf
[In ] av1
[In ] avi
[In ] avs2
[In ] avs3
[In ] bin
[In ] cavsvideo
[In ] cdxl
[In ] codec2
[In ] codec2raw
[In ] concat
[In ] data
[In ] dirac
[In ] dnxhd
[In ] dts
[In ] dvbsub
[In ] dvbtxt
[In ] eac3
[In ] fits
[In ] flac
[In ] flv
[In ] live_flv
[In ] g722
[In ] g726
[In ] g726le
[In ] g729
[In ] gif
[In ] gsm
[In ] h261
[In ] h263
[In ] h264
[In ] hevc
[In ] hls
[In ] idf
[In ] image2
[In ] image2pipe
[In ] alias_pix
[In ] brender_pix
[In ] ingenient
[In ] ipu
[In ] kux
[In ] loas
[In ] m4v
[In ] microdvd
[In ] mjpeg
[In ] mjpeg_2000
[In ] mlp
[In ] mov,mp4,m4a,3gp,3g2,mj2
[In ] mp3
[In ] mpegts
[In ] mpegtsraw
[In ] mpegvideo
[In ] mpjpeg
[In ] mxf
[In ] obu
[In ] alaw
[In ] mulaw
[In ] vidc
[In ] f64be
[In ] f64le
[In ] f32be
[In ] f32le
[In ] s32be
[In ] s32le
[In ] s24be
[In ] s24le
[In ] s16be
[In ] s16le
[In ] s8
[In ] u32be
[In ] u32le
[In ] u24be
[In ] u24le
[In ] u16be
[In ] u16le
[In ] u8
[In ] rawvideo
[In ] rtp
[In ] rtsp
[In ] sbc
[In ] sbg
[In ] sdp
[In ] ser
[In ] shn
[In ] sln
[In ] tak
[In ] tedcaptions
[In ] truehd
[In ] tty
[In ] v210
[In ] v210x
[In ] vc1
[In ] vobsub
[In ] w64
[In ] wav
[In ] webm_dash_manifest
[In ] webvtt
[In ] wsd
[In ] xbin
[In ] bmp_pipe
[In ] cri_pipe
[In ] dds_pipe
[In ] dpx_pipe
[In ] exr_pipe
[In ] gif_pipe
[In ] j2k_pipe
[In ] jpeg_pipe
[In ] jpegls_pipe
[In ] pam_pipe
[In ] pbm_pipe
[In ] pcx_pipe
[In ] pgmyuv_pipe
[In ] pgm_pipe
[In ] pgx_pipe
[In ] photocd_pipe
[In ] pictor_pipe
[In ] png_pipe
[In ] ppm_pipe
[In ] psd_pipe
[In ] qdraw_pipe
[In ] sgi_pipe
[In ] svg_pipe
[In ] sunrast_pipe
[In ] tiff_pipe
[In ] webp_pipe
[In ] xbm_pipe
[In ] xpm_pipe
[In ] xwd_pipe
[Out] adts
[Out] aiff
[Out] alp
[Out] apng
[Out] argo_asf
[Out] argo_cvg
[Out] asf
[Out] ass
[Out] ast
[Out] asf_stream
[Out] avi
[Out] dash
[Out] f4v
[Out] fifo
[Out] fifo_test
[Out] flac
[Out] flv
[Out] framehash
[Out] framemd5
[Out] gif
[Out] hash
[Out] hds
[Out] hls
[Out] image2
[Out] ipod
[Out] ismv
[Out] latm
[Out] md5
[Out] matroska
[Out] matroska
[Out] mov
[Out] mp3
[Out] mp4
[Out] mpeg
[Out] vcd
[Out] dvd
[Out] svcd
[Out] vob
[Out] mpegts
[Out] mpjpeg
[Out] mxf
[Out] mxf_d10
[Out] mxf_opatom
[Out] nut
[Out] oga
[Out] ogg
[Out] ogv
[Out] opus
[Out] psp
[Out] rtp
[Out] rtp_mpegts
[Out] rtsp
[Out] segment
[Out] stream_segment,ssegment
[Out] smoothstreaming
[Out] spx
[Out] spdif
[Out] streamhash
[Out] tee
[Out] 3g2
[Out] 3gp
[Out] wav
[Out] webm
[Out] webm_dash_manifest
[Out] webm_chunk
[Out] webp
<<AVCodec>>
[Enc][Video] amv
[Enc][Video] apng
[Enc][Video] cfhd
[Enc][Video] cinepak
[Enc][Video] cljr
[Enc][Video] dnxhd
[Enc][Video] dvvideo
[Enc][Video] exr
[Enc][Video] ffv1
[Enc][Video] ffvhuff
[Enc][Video] flv
[Enc][Video] gif
[Enc][Video] h261
[Enc][Video] h263
[Enc][Video] h263p
[Enc][Video] huffyuv
[Enc][Video] jpeg2000
[Enc][Video] jpegls
[Enc][Video] ljpeg
[Enc][Video] magicyuv
[Enc][Video] mjpeg
[Enc][Video] mpeg1video
[Enc][Video] mpeg2video
[Enc][Video] mpeg4
[Enc][Video] msmpeg4v2
[Enc][Video] msmpeg4
[Enc][Video] png
[Enc][Video] prores
[Enc][Video] prores_aw
[Enc][Video] prores_ks
[Enc][Video] roqvideo
[Enc][Video] rpza
[Enc][Video] rv10
[Enc][Video] rv20
[Enc][Video] sgi
[Enc][Video] snow
[Enc][Video] speedhq
[Enc][Video] sunrast
[Enc][Video] svq1
[Enc][Video] targa
[Enc][Video] tiff
[Enc][Video] utvideo
[Enc][Video] vc2
[Enc][Video] wmv1
[Enc][Video] wmv2
[Enc][Audio] aac
[Enc][Audio] ac3
[Enc][Audio] ac3_fixed
[Enc][Audio] alac
[Enc][Audio] dca
[Enc][Audio] eac3
[Enc][Audio] flac
[Enc][Audio] opus
[Enc][Audio] sbc
[Enc][Audio] wavpack
[Enc][Audio] adpcm_argo
[Enc][Audio] g726
[Enc][Audio] g726le
[Enc][Audio] adpcm_ima_amv
[Enc][Audio] adpcm_ima_alp
[Enc][Audio] adpcm_ima_apm
[Enc][Audio] adpcm_ima_qt
[Enc][Audio] adpcm_ima_ssi
[Enc][Audio] adpcm_ima_wav
[Enc][Audio] adpcm_ima_ws
[Enc][Audio] adpcm_ms
[Enc][Audio] adpcm_swf
[Enc][Audio] adpcm_yamaha
[Enc][Other] dvdsub
[Enc][Other] mov_text
[Enc][Video] h263_v4l2m2m
[Enc][Video] h264_v4l2m2m
[Enc][Video] hevc_v4l2m2m
[Enc][Video] mpeg4_v4l2m2m
[Enc][Video] vp8_v4l2m2m
[Dec][Video] exr
[Dec][Video] fic
[Dec][Video] fits
[Dec][Video] frwu
[Dec][Video] gif
[Enc][Video] h263_v4l2m2m
[Dec][Video] h264
[Enc][Video] h264_v4l2m2m
[Dec][Video] hevc
[Enc][Video] hevc_v4l2m2m
[Dec][Video] jpeg2000
[Enc][Video] mjpeg
[Dec][Video] mpeg4
[Enc][Video] mpeg4_v4l2m2m
[Enc][Video] mpeg1_v4l2m2m
[Enc][Video] mpeg2_v4l2m2m
[Dec][Video] photocd
[Dec][Video] rasc
[Dec][Video] rawvideo
[Dec][Audio] s302m
[Dec][Video] tiff
[Dec][Video] v210
[Enc][Video] vc1_v4l2m2m
[Enc][Video] vp8_v4l2m2m
[Enc][Video] vp9_v4l2m2m
[Dec][Audio] aac
[Dec][Audio] ac3
[Dec][Audio] ac3_fixed
[Dec][Audio] alac
[Dec][Audio] ape
[Dec][Audio] dca
[Dec][Audio] eac3
[Dec][Audio] evrc
[Dec][Audio] flac
[Dec][Audio] g723_1
[Dec][Audio] opus
[Dec][Audio] tta
[Dec][Audio] g722
[Dec][Other] cc_dec
[Dec][Other] dvbsub
[Dec][Other] dvdsub
[Dec][Other] mov_text
[Dec][Other] pgssub
[Dec][Other] pjs
[Dec][Other] stl
[Dec][Other] subviewer1
[Dec][Other] text
[Dec][Other] vplayer
[Dec][Video] av1
<<AVFilter>>
[ abench]
[ acompressor]
[ acontrast]
[ acue]
[ acrossfade]
[ acrossover]
[ acrusher]
[ adeclick]
[ adeclip]
[ adecorrelate]
[ adelay]
[ adenorm]
[ aecho]
[ aemphasis]
[ aeval]
[ aexciter]
[ afade]
[ afftdn]
[ afftfilt]
[ afir]
[ aformat]
[ afreqshift]
[ afwtdn]
[ agate]
[ aiir]
[ ainterleave]
[ alimiter]
[ allpass]
[ aloop]
[ amerge]
[ ametadata]
[ amix]
[ anequalizer]
[ anlmdn]
[ anlms]
[ apad]
[ aperms]
[ aphaser]
[ aphaseshift]
[ apsyclip]
[ apulsator]
[ arealtime]
[ aresample]
[ arnndn]
[ asegment]
[ aselect]
[ asendcmd]
[ asetnsamples]
[ asetpts]
[ asetrate]
[ asettb]
[ asidedata]
[ asoftclip]
[ asplit]
[ astats]
[ astreamselect]
[ asubboost]
[ asubcut]
[ asupercut]
[ asuperpass]
[ asuperstop]
[ atempo]
[ atilt]
[ atrim]
[ axcorrelate]
[ bandpass]
[ bandreject]
[ bass]
[ biquad]
[ channelmap]
[ channelsplit]
[ chorus]
[ compand]
[compensationdelay]
[ crossfeed]
[ crystalizer]
[ dcshift]
[ deesser]
[ drmeter]
[ dynaudnorm]
[ ebur128]
[ equalizer]
[ extrastereo]
[ firequalizer]
[ flanger]
[ haas]
[ hdcd]
[ headphone]
[ highpass]
[ highshelf]
[ join]
[ loudnorm]
[ lowpass]
[ lowshelf]
[ mcompand]
[ pan]
[sidechaincompress]
[ sidechaingate]
[ silencedetect]
[ silenceremove]
[ speechnorm]
[ stereotools]
[ stereowiden]
[ superequalizer]
[ surround]
[ treble]
[ tremolo]
[ vibrato]
[ volume]
[ aevalsrc]
[ afirsrc]
[ anoisesrc]
[ anullsrc]
[ hilbert]
[ sinc]
[ sine]
[ addroi]
[ alphamerge]
[ amplify]
[ atadenoise]
[ avgblur]
[ bbox]
[ bench]
[ bilateral]
[ bitplanenoise]
[ blackdetect]
[ blackframe]
[ blend]
[ bm3d]
[ boxblur]
[ bwdif]
[ cas]
[ chromahold]
[ chromakey]
[ chromanr]
[ chromashift]
[ ciescope]
[ codecview]
[ colorbalance]
[colorchannelmixer]
[ colorcontrast]
[ colorcorrect]
[ colorize]
[ colorkey]
[ colorhold]
[ colorlevels]
[ colormatrix]
[ colorspace]
[colortemperature]
[ convolution]
[ convolve]
[ cover_rect]
[ crop]
[ cropdetect]
[ cue]
[ curves]
[ datascope]
[ dblur]
[ dctdnoiz]
[ deband]
[ deblock]
[ decimate]
[ deconvolve]
[ dedot]
[ deflate]
[ deflicker]
[ dejudder]
[ delogo]
[ derain]
[ deshake]
[ despill]
[ detelecine]
[ dilation]
[ displace]
[ dnn_classify]
[ dnn_detect]
[ dnn_processing]
[ doubleweave]
[ drawbox]
[ drawgraph]
[ drawgrid]
[ edgedetect]
[ elbg]
[ entropy]
[ epx]
[ eq]
[ erosion]
[ estdif]
[ exposure]
[ extractplanes]
[ fade]
[ fftdnoiz]
[ fftfilt]
[ field]
[ fieldhint]
[ fieldmatch]
[ fieldorder]
[ fillborders]
[ find_rect]
[ floodfill]
[ format]
[ fps]
[ framepack]
[ framerate]
[ framestep]
[ freezedetect]
[ freezeframes]
[ fspp]
[ gblur]
[ geq]
[ gradfun]
[ graphmonitor]
[ grayworld]
[ greyedge]
[ guided]
[ haldclut]
[ hflip]
[ histeq]
[ histogram]
[ hqdn3d]
[ hqx]
[ hstack]
[ hsvhold]
[ hsvkey]
[ hue]
[ hwdownload]
[ hwmap]
[ hwupload]
[ hysteresis]
[ identity]
[ idet]
[ il]
[ inflate]
[ interlace]
[ interleave]
[ kerndeint]
[ kirsch]
[ lagfun]
[ lenscorrection]
[ limiter]
[ loop]
[ lumakey]
[ lut]
[ lut1d]
[ lut2]
[ lut3d]
[ lutrgb]
[ lutyuv]
[ maskedclamp]
[ maskedmax]
[ maskedmerge]
[ maskedmin]
[maskedthreshold]
[ maskfun]
[ median]
[ mergeplanes]
[ mestimate]
[ metadata]
[ midequalizer]
[ minterpolate]
[ mix]
[ monochrome]
[ mpdecimate]
[ msad]
[ negate]
[ nlmeans]
[ nnedi]
[ noformat]
[ noise]
[ normalize]
[ oscilloscope]
[ overlay]
[ owdenoise]
[ pad]
[ palettegen]
[ paletteuse]
[ perms]
[ perspective]
[ phase]
[photosensitivity]
[ pixscope]
[ pp]
[ pp7]
[ premultiply]
[ prewitt]
[ pseudocolor]
[ psnr]
[ pullup]
[ qp]
[ random]
[ readeia608]
[ readvitc]
[ realtime]
[ remap]
[ removegrain]
[ removelogo]
[ rgbashift]
[ roberts]
[ rotate]
[ sab]
[ scale]
[ scale2ref]
[ scdet]
[ scharr]
[ scroll]
[ segment]
[ select]
[ selectivecolor]
[ sendcmd]
[ setdar]
[ setfield]
[ setparams]
[ setpts]
[ setrange]
[ setsar]
[ settb]
[ shear]
[ showinfo]
[ showpalette]
[ shuffleframes]
[ shufflepixels]
[ shuffleplanes]
[ sidedata]
[ signalstats]
[ signature]
[ smartblur]
[ sobel]
[ split]
[ spp]
[ sr]
[ ssim]
[ stereo3d]
[ streamselect]
[ swaprect]
[ swapuv]
[ tblend]
[ telecine]
[ thistogram]
[ threshold]
[ thumbnail]
[ tile]
[ tinterlace]
[ tlut2]
[ tmedian]
[ tmidequalizer]
[ tmix]
[ tonemap]
[ tpad]
[ transpose]
[ trim]
[ unpremultiply]
[ unsharp]
[ untile]
[ v360]
[ vaguedenoiser]
[ vectorscope]
[ vflip]
[ vibrance]
[ vif]
[ vignette]
[ vmafmotion]
[ vstack]
[ w3fdif]
[ waveform]
[ weave]
[ xbr]
[ xfade]
[ xmedian]
[ xstack]
[ yadif]
[ yaepblur]
[ zoompan]
[ allrgb]
[ allyuv]
[ cellauto]
[ color]
[ gradients]
[ haldclutsrc]
[ life]
[ mandelbrot]
[ mptestsrc]
[ nullsrc]
[ pal75bars]
[ pal100bars]
[ rgbtestsrc]
[ sierpinski]
[ smptebars]
[ smptehdbars]
[ testsrc]
[ testsrc2]
[ yuvtestsrc]
[ abitscope]
[ adrawgraph]
[ agraphmonitor]
[ ahistogram]
[ aphasemeter]
[ avectorscope]
[ concat]
[ showcqt]
[ showfreqs]
[ showspatial]
[ showspectrum]
[showspectrumpic]
[ showvolume]
[ showwaves]
[ showwavespic]
[ spectrumsynth]
[ amovie]
[ movie]
[ abuffer]
[ buffer]
[ abuffersink]
[ buffersink]