ffmpeg官網
當前最新版本ffmpeg-3.4.1
java
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0 ./configure make && make install
tar xvfj ffmpeg-3.1.2.tar.bz2
cd ffmpeg-3.1.2 ./configure --enable-shared --prefix=/usr/local/ffmpeg make && make install
echo "export PATH=/usr/local/ffmpeg/bin/:$PATH" >> /etc/profile . /etc/profile
ffmpeg --version
若報錯/usr/local/ffmpeg/bin/ffmpeg: error while loading shared libraries: libavdevice.so.: cannot open shared object file: No such file or directory
,則須要增長動態庫配置:ide
echo "/usr/local/ffmpeg/lib" >> /etc/ld.so.conf ldconfig
成功效果:測試
[dev@Develop ~]$ ffmpeg -version ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-4) configuration: --enable-shared --prefix=/usr/local/ffmpeg libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100
網頁中HTML5的video標籤標準是用H.264方式編碼視頻的MP4文件,把一個其餘編碼格式的MP4文件轉換成H.264編碼的MP4文件:ffmpeg -i in.mp4 -vcodec h264 out.mp4
ui
解決:以H264編解碼爲例,須要先安裝X264庫:編碼
下載X264 git clone http://git.videolan.org/git/x264.git
.net
安裝X264:code
./configure --enable-shared --disable-asm make && make install
./configure --enable-shared --enable-libx264 --enable-gpl --prefix=/usr/local/ffmpeg make && make install # 增長X264 動態庫配置 echo "/usr/local/lib" >> /etc/ld.so.conf ldconfig
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /** * COMMAND: ffmpeg -i in.mp4 -vcodec h264 out.mp4 */ public class TransCode { public static void main(String[] args) { List<String> commend = new ArrayList<String>(); commend.add("/usr/local/ffmpeg/bin/ffmpeg"); commend.add("-i"); commend.add("/home/em/file/in.mp4"); commend.add("-vcodec"); commend.add("h264"); commend.add("-y"); commend.add("/home/em/file/out.mp4"); StringBuffer test = new StringBuffer(); for (int i = 0; i < commend.size(); i++) test.append(commend.get(i) + " "); System.out.println(test); try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(test.toString()); InputStream stderr = proc.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) ; } catch (IOException e) { e.printStackTrace(); } System.out.println("視頻轉換成功!"); } }