How to compile ffmpeg in UBUNTU14 and build an Eclipse project __ffmpeg

Source: Internet
Author: User

For a person who studies video processing, if you haven't used ffmpeg, it basically means driving but not knowing what the engine is. However, ffmpeg compiler installation and use of the work is not a worry, almost every step will be a lack of library problems and so on, and sometimes a dependency you installed, but installed several, incorrect location or version of the problem may occur.

Strewn, now summarize how to install ffmpeg2.3 in 64-bit Ubuntu14.04. 1. Installation

The first is to download ffmpeg2.3 source code, official website, GitHub have, here no longer repeat. I packed all the files I used and the address was at the end of the article. If you want to build ffplay together, it's best to use ffmpeg2.3 and above, because earlier versions can be implemented by modifying the configuration file, setting compilation parameters, and so on, but often unsuccessful after make. (The Apt-get install can actually be installed directly, but this is not easy to control autonomously).

FFmpeg is complicated because it is actually a framework, or a container, where almost all algorithms for audio, video, and even image processing can be integrated, and can then be invoked and used in accordance with FFmpeg's basic methods. If your algorithm conforms to the relevant specification, it can also be added in. Here we only add two basic libraries, H264 Encoding library x264 and MP3 audio lame.

In fact, there are many kinds of installation methods, Apt-get install directly installed, or compile the installation source code files. Here we use two different methods. Install x264 library: sudo apt-get install-y libx264-dev. Install lame: In the Code folder provided in this article, first enter lame-3.99.5 to execute./configure, and then execute make install when make is complete.

Once we're done, we can install the ffmpeg.

The first is configure, using the./configure--help, you can see that there are many options to set up, and many of the introductory stages are directly by default. If you want to use the engineering, in order to give ffmpeg lose weight, developers will be a large number of unwanted functions and procedures to prohibit, also known as optimization. There are also two--enable-shared and--prefix that need to be highlighted here. Because we want to compile the ffmpeg into a shared library for two development calls, you set the--enable-shared option at compile time, otherwise you only generate a static library. --PREFIX Specifies the installation location, the general user program is installed under/usr/local/, so our final configuration command here is: "./configure--enable-shared--prefix=/usr/local/ ffmpeg2.3 "

After that, execute make to compile, in order to improve speed, you can use Make-j4, for multithreaded compilation. Perform the make install installation when finished.

After the installation is complete, you can see that/usr/local/lib generates a ffmpeg2.3 folder with Bin, include, and Lib files. Executing the program under bin at this time is not going to work. So, configure the environment variables first. Method is: Gedit/etc/profile, adding at the end of the file

Export Path=/usr/local/ffmpeg2.3/bin: $PATH

Then close the file and execute the source/etc/profile command.

Then execute ffmpeg command, no surprise, will be prompted a few so library can not find, I like the method is to write a script, the FFmpeg shared library link file directly copied to/usr/lib. Script content is ffmpeg.sh:

#!/bin/bash
Cp/usr/local/ffmpeg2.3/lib/libavcodec.so.55/usr/lib/x86_64-linux-gnu
cp/usr/local/ Ffmpeg2.3/lib/libavdevice.so.55/usr/lib/x86_64-linux-gnu
cp/usr/local/ffmpeg2.3/lib/libavfilter.so.4/usr/ Lib/x86_64-linux-gnu
Cp/usr/local/ffmpeg2.3/lib/libavformat.so.55/usr/lib/x86_64-linux-gnu
cp/usr/ Local/ffmpeg2.3/lib/libavutil.so.52/usr/lib/x86_64-linux-gnu
cp/usr/local/ffmpeg2.3/lib/libswresample.so.0 /usr/lib/x86_64-linux-gnu
Cp/usr/local/ffmpeg2.3/lib/libswscale.so.2/usr/lib/x86_64-linux-gnu
Note that in the latest Ubuntu system, 32-bit libraries are placed in I386-linux-gnu, 64-bit libraries are placed in X86_64-linux-gnu, if placed directly under/usr/lib, Sometimes you will be prompted to find the library file (when the elder brother installed OpenSSL encountered this situation, because at that time did not know, spent a lot of Kung fu).

Then execute sudo chmod +x ffmpeg.sh. And then execute./ffmpeg.sh
If normal, displaying the following information indicates that the installation was successful:

root@ubuntu:/home/lll/desktop/pis_workspace/ffmpeg1/debug# ffmpeg ffmpeg version 2.6.git Copyright (c) 2000-2015 the FFmpeg developers built with GCC 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.1) configuration:--disable-shared--ENABLE-GPL Able-static--enable-libx264--enable-libmp3lame--enable-pthreads--enable-filter=scale--enable-protocol=udp-- Enable-protocol=file--enable-protocol=unix--enable-encoder=libx264--enable-encoder=libmp3lame--enable-bsf=h264 _mp4toannexb--enable-decoder=mpeg2video--enable-decoder=h264--ENABLE-DECODER=AAC--enable-decoder=ac3-- Enable-decoder=mp3--enable-muxer=mpegts--enable-demuxer=mpegts libavutil 54. 28.100/54. 28.100 Libavcodec 56. 49.101/56. 49.101 Libavformat 56. 40.101/56.  40.101 Libavdevice 56.  4.100/56. 4.100 Libavfilter 5. 22.101/5.  22.101 Libswscale 3.  1.101/3.  1.101 libswresample 1.  2.101/1.  2.101 Libpostproc 53.  3.100/53. 3.100 Hyper fast Audio and Video encoder
usage:ffmpeg [Options] [[infile Options]-I infile] ...

{[outfile options] outfile} ...
 Use-h to get all help or, even better, run ' mans ffmpeg '

2 Build the first FFmpeg engineering method in Eclipse how to separate the testrtspclient from the live555 code from the previous blog and suggest that the first eclipse project be similar. First create a new C project in Eclipse, and then add the ffmpeg include header file, as shown in the following illustration:

Then add the library, there are a lot of libraries to add

This includes: All libraries in FFmpeg: Avcodec, Avdevice, Avfilter, Avformat, Avutil, Swresample, Swscale, and four required libraries: Pthread, m,x264, and Mp3lame. Pthread is the Linux system process library, M is the math library, x264 is the H264 code library, Mp3lame is the MP3 encoding library.

Note that the "Library search path" Here is generally not required, but if you already have other versions of FFmpeg installed on your computer, it's best to specify that otherwise eclipse will load other versions of FFmpeg information when it automatically searches. There will be some strange problems.

When we're done, we create a new ffmpeg1.c file. Write a function to test whether the environment can run.

In fact, we do not have to write their own code, and do not have to find online, in the/usr/local/ffmpeg2.3/share/ffmpeg/examples has the official sample program. We copy the contents of the decoding_encoding.c into the ffmpeg1.c and compile them, and if they are normal, an executable file FFMPEG1 is generated in the debug directory. If you do not succeed, please think for yourself first, no words can give me a message.

After the compilation is successful, copy the test.h264 file in my folder to the debug directory, and then execute the following command:

./FFMPEG1 H264

If the build succeeds there will be the following output:

Encode video File test.h264 [libx264 @ 0x1bc2040] using CPU capabilities:none! [libx264 @ 0x1bc2040] profile high, level 1.3 write frame (size= 2026) write frame (size= 605) write frame (s  Ize= 129) Write frame (size= 588) Write frame (size= 187) write frame (size= 764) Write frame (size= 603) write frame (size= 962) (size= 563), write frame (size= 2234) W Rite (size= 1291) write frame (771 size=) write frame (827 size=) write F  Rame size= 909) write frame (629 size=) Write frame (1083 size=) write frame Size= 661 Write Frame (size= 2432) write frame (size= 1164) write frame (size= 853) write-FRAME (si  Ze= 793) Write frame (size= 681) [libx264 @ 0x1bc2040] Frame i:3 Avg qp:25.59 size:2231 [libx264 @ 0x1bc2040] Frame p:12 Avg qp:24.06 size:859 [libx264 @ 0x1bc2040] fraMe b:10 Avg qp:27.64 size:560 [libx264 @ 0x1bc2040] consecutive b-frames:20.0% 80.0% [libx264 @ 0x1bc2040] MB i 16..4:77.6% 12.3% 10.1% [libx264 @ 0x1bc2040] MB P I16 ... 4:76.6% 0.9% 0.2% P16. 4:20.5% 0.9% 0.9% 0.0% 0.0% skip:0.0% [libx264 @ 0x1bc2040] MB B I16 ... 4:0.0% 0.0% 0.0% B16. 8:11.1% 0.3% 0.0% direct:10.7% skip:77.9% l0:20.3% l1:49.6% bi:30.1% [libx264 @ 0x1bc2040] Final ratefactor:15.85 [ libx264 @ 0x1bc2040] 8x8 transform intra:3.8% inter:51.5% [libx264 @ 0x1bc2040] Direct MVS spatial:0.0% temporal:100.0% [  libx264 @ 0x1bc2040] coded y,uvdc,uvac intra:5.0% 33.6% 4.7% inter:1.8% 36.4% 9.1% [libx264 @ 0x1bc2040] i16 v,h,dc,p: 0% 0% 0% 100% [libx264 @ 0x1bc2040] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:3% 29% 16% 51% 0% 0% 0% 0% 0% [libx264 @ 0X1BC2 040] I4 v,h,dc,ddl,ddr,vr,hd,vl,hu:11% 6% 14% 51% 1% 5% 3% 7% 2% [libx264 @ 0x1bc2040] i8c dc,h,v,p:2% 6% 4% 88 % [libx264 @ 0x1bc2040] weighted p-frames:y:0.0% uv:0.0% [libx264 @ 0x1bc20M] ref P l0:96.4% 0.9% 2.5% 0.1% 0.0% [libx264 @ 0x1bc2040] ref B l0:63.7% 27.6% 8.8% [libx264 @ 0x1bc2040] Kb/s:1
 80.82
All right, then let's enjoy the ffmpeg.
Code download

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.