怎么在Java中使用FFmpeg 處理視頻文件?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都做網(wǎng)站、成都網(wǎng)站設計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的壽寧網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!
FFmpeg是一套可以用來記錄、轉換數(shù)字音頻、視頻,并能將其轉化為流的開源計算機程序。采用LGPL或GPL許可證。它提供了錄制、轉換以及流化音視頻的完整解決方案。它包含了非常先進的音頻/視頻編解碼庫libavcodec,為了保證高可移植性和編解碼質(zhì)量,libavcodec里很多code都是從頭開發(fā)的。
FFmpeg在Linux平臺下開發(fā),但它同樣也可以在其它操作系統(tǒng)環(huán)境中編譯運行,包括Windows、Mac OS X等。這個項目最早由Fabrice Bellard發(fā)起,2004年至2015年間由Michael Niedermayer主要負責維護。許多FFmpeg的開發(fā)人員都來自MPlayer項目,而且當前FFmpeg也是放在MPlayer項目組的服務器上。項目的名稱來自MPEG視頻編碼標準,前面的"FF"代表"Fast Forward"。
首先說明,我是在 https://ffmpeg.zeranoe.com/builds/ 這個地方下載的軟件,Windows 和 Mac 解壓之后即可使用。具體代碼如下:
package cn.bridgeli.demo; import org.junit.Test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; /** * @author BridgeLi * @date 2020/2/29 15:40 */ public class FfmpegTest { private static final String OS = System.getProperty("os.name").toLowerCase(); private static final String FFMPEG_PATH = "/Users/bridgeli/ffmpeg-20200216-8578433-macos64-static/bin/ffmpeg"; @Test public void testFfmpeg() { String inputWavFile = "/Users/bridgeli/inputWavFile.wav"; String inputMp3File = "/Users/bridgeli/inputMp3File.mp3"; String inputMp4File = "/Users/bridgeli/inputMp4File.mp4"; String outMergeMp3File = "/Users/bridgeli/outMergeMp3File.mp3"; String outMergeMp3AndMp4File = "/Users/bridgeli/outMergeMp3AndMp4File.mp4"; String outConcatMp3File = "/Users/bridgeli/outConcatMp3File.mp3"; // 拼接 String command = null; if (OS.contains("mac") || OS.contains("linux")) { command = FFMPEG_PATH + " -i " + inputMp3File + " -i " + inputWavFile + " -filter_complex [0:0][1:0]concat=n=2:v=0:a=1[a] -map [a] " + outConcatMp3File; } else if (OS.contains("windows")) { command = FFMPEG_PATH + " -i " + inputMp3File + " -i " + inputWavFile + " -filter_complex \"[0:0][1:0]concat=n=2:v=0:a=1[a]\" -map \"[a]\" " + outConcatMp3File; } // 合并(視頻和音頻) // String command = FFMPEG_PATH + " -i " + inputMp4File + " -i " + outConcatMp3File + " -c:v copy -c:a aac -strict experimental " + outMergeMp3AndMp4File; // 合并 // String command = FFMPEG_PATH + " -i " + inputMp3File + " -i " + inputWavFile + " -filter_complex amerge -ac 2 -c:a libmp3lame -q:a 4 " + outMergeMp3File; System.out.println(command); Process process = null; try { process = Runtime.getRuntime().exec(command); } catch (IOException e) { e.printStackTrace(); } if (null == process) { return; } try { process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } try (InputStream errorStream = process.getErrorStream(); InputStreamReader inputStreamReader = new InputStreamReader(errorStream); BufferedReader br = new BufferedReader(inputStreamReader)) { String line = null; StringBuffer context = new StringBuffer(); while ((line = br.readLine()) != null) { context.append(line); } System.out.println("error message: " + context); } catch (IOException e) { e.printStackTrace(); } process.destroy(); } }
關于怎么在Java中使用FFmpeg 處理視頻文件問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關知識。
新聞名稱:怎么在Java中使用FFmpeg處理視頻文件
標題路徑:http://chinadenli.net/article2/giscic.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、網(wǎng)站內(nèi)鏈、商城網(wǎng)站、網(wǎng)頁設計公司、電子商務、面包屑導航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)