记录下centos下 ffmpeg项目编译参数

摘要:
官网下载最新的ffmpeg源文件,直接./confiure--prefix=path_to_install&&make&&makeinstall,期间没有什么问题。但是在写了一个测试文件去测试的时候,总是链接错误,不是缺少这个库就是av***未定义的引用。少的库直接加-l就行了,但是av***里面未定义引用我就郁闷了,最后发现可能是ffmpeg库的引用顺序不对造成的。记录下ffmpeg库引用顺序,反正这个顺序在我这里是可以用的。最后附带下测试代码#!

官网下载最新的ffmpeg源文件,直接./confiure --prefix=path_to_install && make && make install ,期间没有什么问题。(但是在最后想生成动态库的时候有问题,暂时不去解决了,静态的先凑合用吧)

但是在写了一个测试文件去测试的时候,总是链接错误,不是缺少这个库就是av***未定义的引用。少的库直接加-l就行了,但是av***里面未定义引用我就郁闷了,最后发现可能是ffmpeg库的引用顺序不对造成的。

记录下ffmpeg库引用顺序,反正这个顺序在我这里是可以用的。最后附带下测试代码

#! /bin/bash
BIN_PATH=/home/mico/bin
export LD_LIBRARY_PATH=$BIN_PATH/lib:/usr/local/lib64:/usr/lib64

gcc test_ffmpeg.c -L $BIN_PATH/lib -L /usr/local/lib -L /usr/lib64 -I $BIN_PATH/include -lavfilter -lavformat -lavdevice -lavcodec -lswscale -lavutil -lswresample -llzma -lz -lbz2 -pthread -lm -g -o test_ffmpeg.out
echo "well done"
1 /*
2 * Copyright (c) 2010 Nicolas George
3 * Copyright (c) 2011 Stefano Sabatini
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22  */
23 /**
24 * @file
25 * API example for decoding and filtering
26 * @example filtering_video.c
27  */
28 #define _XOPEN_SOURCE 600 /* for usleep */
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <libavcodec/avcodec.h>
33 #include <libavformat/avformat.h>
34 #include <libavfilter/buffersink.h>
35 #include <libavfilter/buffersrc.h>
36 #include <libavutil/opt.h>
37 #define ENABLE_DISPLAY 0
38 #define ENABLE_YUV 1
39 const char *filter_descr = "scale=78:24,transpose=cclock";
40 /*other way:
41 scale=78:24 [scl]; [scl] transpose=cclock // assumes "[in]" and "[out]" to be input output pads respectively
42  */
43 static AVFormatContext *fmt_ctx;
44 static AVCodecContext *dec_ctx;
45 AVFilterContext *buffersink_ctx;
46 AVFilterContext *buffersrc_ctx;
47 AVFilterGraph *filter_graph;
48 static int video_stream_index = -1;
49 static int64_t last_pts =AV_NOPTS_VALUE;
50 
51 #if ENABLE_YUV
52     FILE *fp_yuv;
53 #endif
54 
55 static int open_input_file(const char *filename)
56 {    
57     intret;
58     AVCodec *dec;
59     
60 #if ENABLE_YUV
61     fp_yuv=fopen("output.yuv","wb+");
62 #endif
63 
64     if ((ret = avformat_open_input(&fmt_ctx, filename, NULL, NULL)) < 0) {
65         av_log(NULL, AV_LOG_ERROR, "Cannot open input file
");
66         returnret;
67 }
68     if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
69         av_log(NULL, AV_LOG_ERROR, "Cannot find stream information
");
70         returnret;
71 }
72     /*select the video stream */
73     ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &dec, 0);
74     if (ret < 0) {
75         av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file
");
76         returnret;
77 }
78     video_stream_index =ret;
79     /*create decoding context */
80     dec_ctx =avcodec_alloc_context3(dec);
81     if (!dec_ctx)
82         returnAVERROR(ENOMEM);
83     avcodec_parameters_to_context(dec_ctx, fmt_ctx->streams[video_stream_index]->codecpar);
84     /*init the video decoder */
85     if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) {
86         av_log(NULL, AV_LOG_ERROR, "Cannot open video decoder
");
87         returnret;
88 }
89     return 0;
90 }
91 
92 
93 static int init_filters(const char *filters_descr)
94 {
95     char args[512];
96     int ret = 0;
97     const AVFilter *buffersrc  = avfilter_get_by_name("buffer");
98     const AVFilter *buffersink = avfilter_get_by_name("buffersink");
99     AVFilterInOut *outputs =avfilter_inout_alloc();
100     AVFilterInOut *inputs  =avfilter_inout_alloc();
101     AVRational time_base = fmt_ctx->streams[video_stream_index]->time_base;
102     enum AVPixelFormat pix_fmts[] ={ AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
103     filter_graph =avfilter_graph_alloc();
104     if (!outputs || !inputs || !filter_graph) {
105         ret =AVERROR(ENOMEM);
106         gotoend;
107 }
108     /*buffer video source: the decoded frames from the decoder will be inserted here. */
109     snprintf(args, sizeof(args),
110             "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
111             dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
112 time_base.num, time_base.den,
113             dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);
114     ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
115 args, NULL, filter_graph);
116     if (ret < 0) {
117         av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source
");
118         gotoend;
119 }
120     /*buffer video sink: to terminate the filter chain. */
121     ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
122 NULL, NULL, filter_graph);
123     if (ret < 0) {
124         av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink
");
125         gotoend;
126 }
127     ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts,
128 AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
129     if (ret < 0) {
130         av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format
");
131         gotoend;
132 }
133     /*
134 * Set the endpoints for the filter graph. The filter_graph will
135 * be linked to the graph described by filters_descr.
136      */
137     /*
138 * The buffer source output must be connected to the input pad of
139 * the first filter described by filters_descr; since the first
140 * filter input label is not specified, it is set to "in" by
141 * default.
142      */
143     outputs->name       = av_strdup("in");
144     outputs->filter_ctx =buffersrc_ctx;
145     outputs->pad_idx    = 0;
146     outputs->next       =NULL;
147     /*
148 * The buffer sink input must be connected to the output pad of
149 * the last filter described by filters_descr; since the last
150 * filter output label is not specified, it is set to "out" by
151 * default.
152      */
153     inputs->name       = av_strdup("out");
154     inputs->filter_ctx =buffersink_ctx;
155     inputs->pad_idx    = 0;
156     inputs->next       =NULL;
157     if ((ret =avfilter_graph_parse_ptr(filter_graph, filters_descr,
158                                     &inputs, &outputs, NULL)) < 0)
159         gotoend;
160     if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
161         gotoend;
162 end:
163     avfilter_inout_free(&inputs);
164     avfilter_inout_free(&outputs);
165     returnret;
166 }
167 static void display_frame(const AVFrame *frame, AVRational time_base)
168 {
169     intx, y;
170     uint8_t *p0, *p;
171 int64_t delay;
172     if (frame->pts !=AV_NOPTS_VALUE) {
173         if (last_pts !=AV_NOPTS_VALUE) {
174             /*sleep roughly the right amount of time;
175 * usleep is in microseconds, just like AV_TIME_BASE. */
176             delay = av_rescale_q(frame->pts -last_pts,
177 time_base, AV_TIME_BASE_Q);
178             if (delay > 0 && delay < 1000000)
179 usleep(delay);
180 }
181         last_pts = frame->pts;
182 }
183     /*Trivial ASCII grayscale display. */
184     p0 = frame->data[0];
185     puts("

免责声明:内容来源于网络,仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇转:Linux 编译安装 Mysql5.7使用 ASP.NET 一般处理程序或 WebService 返回 JSON下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

HAProxy基础

一、简介 HAProxy是由C语言编写基于事件驱动模型的一款高效稳定、功能强大的负载均衡软件,其性能可媲美商业负载均衡软件,不过在最新的版本中HAProxy已经分为社区版本和企业版,社区版完全免费,企业版有丰富的额外功能。 优缺点: 优点 支持虚拟主机的,通过frontend指令来实现 能弥补Nginx的一些缺点比如Session的保持,Cookie的引...

Centos 7下Nagios的安装及配置

简介 Nagios 是一款自动化运维工具,可以协助运维人员监控服务器的运行状况,并且拥有报警功能。本文章将介绍其安装方法和详细的配置方法。 nagios 监控服务应用指南 本地资源:负载,CPU,磁盘,内存。IO,RAID,温度,passwd文件变化,本地所有文件指纹识别 网络服务:端口,URL,丢包,进程,网络流量 其他设备:交换机,打印机,wind...

android 系统log文件路径

http://87426628.blog.163.com/blog/static/60693618201310187938621/ 手机的默认的日志目录:  /data/local/tmp/* /data/tmp/* /data/system/usagestats/* /data/system/appusagestates/* /dat...

boost asio 异步实现tcp通讯

---恢复内容开始--- asioboost 目录(?)[-] 一前言 二实现思路 通讯包数据结构 连接对象 连接管理器 服务器端的实现 对象串行化 一、前言 boost asio可算是一个简单易用,功能又强大可跨平台的C++通讯库,效率也表现的不错,linux环境是epoll实现的,而windows环境是iocp实现的。而tcp通讯是项...

logstash使用supervisord

  关于supervisord: supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起。 一...

ffmpeg命令汇总

1. 查看ffmpeg信息: ldd `which ffmpeg` ffmpeg -filters ffmpeg -h filter=drawtext man ffmpeg ffmpeg --help 开启ffmpeg log ffmpeg -loglevel trace -i a.mkv out.yuv 相关log level等级如下: { "quie...