您的位置:首页 > 运维架构 > Linux

Linux下编译带x264的ffmpeg的配置方法,包含SDL2

2016-09-21 15:59 573 查看
一、环境准备

ffmpeg下载:http://www.ffmpeg.org/download.html

x264下载:http://download.videolan.org/x264/snapshots/

yasm下载:http://yasm.tortall.net/Download.html

二、编译

1、编译yasm。最新的x264,要求yasm1.2以上

./configure --prefix=/usr/local/yasm

make

make install

2、解压x264,进入目录,输入:

./configure --prefix=/usr/local/x264 --enable-shared --enable-static --enable-yasm

make

make install

由于是手动安装的yasm,下面继续的时候,可能会报yasm找不到,需在/etc/profile

export PATH=$PATH:/usr/local/yasm/bin

之后

source /etc/profile

3、解压ffmpeg,进入目录,

然后安装ffmpeg,ffmpeg有许多依赖包,需要一个一个先安装

apt-get install libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev libxext-dev libxfixes-dev

输入:

./configure --prefix=/usr/local/ffmpeg --enable-libmp3lame --enable-libvorbis --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libxvid --enable-postproc --enable-ffserver --enable-ffplay --enable-shared --extra-cflags=-I/usr/local/x264/include --extra-ldflags=-L/usr/local/x264/lib
可能会提示缺少库,缺啥装啥
make

make install

三、配置环境变量及库路径

首先是命令的路径,编辑/etc/profile

export PATH=$PATH:/usr/local/ffmpeg/bin:/usr/local/yasm/bin:/usr/local/x264/bin

其次是链接库路径,编辑/etc/ld.so.conf

/usr/local/ffmpeg/lib

/usr/local/x264/lib
之后执行 sudo ldconfig
编译器默认搜索路径并不包含这两个目录,虽然这里设置了配置文件,但在编译的时候也会报错,仍然需要
-L/usr/local/ffmpeg/lib -L/usr/local/x264/lib来链接库

为了简化,可以直接将
/usr/local/ffmpeg/lib

/usr/local/x264/lib这两个目录中的.so文件直接考到/usr/local/lib目录,一劳永逸

四、在eclipse下搭建一个ffmpeg工程
1.首先建立一个空c工程
2.设置包含路径

/*
* main.c
*
*  Created on: Sep 16, 2016
*      Author: tla001
*/
#include<stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
void example00() ;
int main()
{
SDL_Window* window =NULL;
SDL_Renderer* render=NULL;
SDL_Texture *texture=NULL;
SDL_Rect src,dst;
int width,height;
SDL_Init(SDL_INIT_EVERYTHING);
window=SDL_CreateWindow("hello",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_SHOWN);
render=SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED |SDL_RENDERER_PRESENTVSYNC);
texture=IMG_LoadTexture(render,"./lufi.bmp");
//SDL_UpdateTexture(texture);
if(texture==NULL){
printf("err");
exit(1);
}
SDL_QueryTexture(texture,NULL,NULL,&width,&height);
printf("w=%d h=%d\n",width,height);
src.x=src.y=0;
src.w=width;
src.h=height;
dst.x=0;
dst.y=0;
dst.w=width/2;
dst.h=height/2;
SDL_SetRenderDrawColor(render,0,255,0,255);
SDL_RenderClear(render);
SDL_RenderCopy(render,texture,NULL,&src);
SDL_RenderPresent(render);

SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_DestroyRenderer(render);
SDL_Quit();
//    SDL_Window *pw = SDL_CreateWindow("hello1",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_SHOWN);
//    SDL_Renderer *pr = SDL_CreateRenderer(pw, -1, 0);
//    SDL_Surface *ps = IMG_Load("/home/tla001/Desktop/lufi.png");
//    if(ps==NULL){
//        exit(-1);
//    }
//    SDL_Texture *pt = SDL_CreateTextureFromSurface(pr, ps);
//    SDL_RenderClear(pr);
//    SDL_Rect r;
//    r.x = 0;
//    r.y = 0;
//    r.w = 1000;
//    r.h = 1000;
//    SDL_RenderCopy(pr, pt, NULL, &r);
//    SDL_RenderPresent(pr);
//    //SDL_Flip(pw);
//    SDL_Delay(3000);
//    SDL_Quit();
//example00() ;
return 0;
}
void example00()
{
SDL_Window  *pWindow = NULL;
SDL_Renderer*pRenderer = NULL;

// 1. initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf ("SDL initialize fail:%s\n", SDL_GetError());
return;
}

// 2. create window
pWindow = SDL_CreateWindow("example00:Setting up SDL",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480,
SDL_WINDOW_SHOWN);
if (NULL == pWindow)
{
printf ("Create window fail:%s\n", SDL_GetError());
}

// 3. create renderer
pRenderer = SDL_CreateRenderer(pWindow, -1, 0);

// 4. clear the window to green
SDL_SetRenderDrawColor(pRenderer,0,255,0,255);
SDL_RenderClear(pRenderer);

// 5. show the window
SDL_RenderPresent(pRenderer);

SDL_Delay(5000);  // for display

// 6. exit
SDL_Quit();
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: