標籤:start weblogic cat info api 原因 ogg integer als
?java視頻轉換的兩種方式,基本上都是基於ffmpeg外掛程式,目前網上對java視頻轉換基本上都是調用外掛程式,拚命令,來實現視頻格式的轉換,然而這種方式在本地是好用的,但是在weblogic伺服器上運行時,就會發生問題,主要原因是window和linux系統不同,所使用ffmpeg外掛程式的格式有所不同.如果在Weblogic伺服器上運行,需要去ffmpeg官網下載linux版本的外掛程式.
首先,記錄下第一種使用ffmpeg外掛程式方式進行視頻格式轉換的代碼地址:
https://www.cnblogs.com/tohxyblog/p/6640786.html
? 其次,主要記錄下使用jave jar包進行視頻格式轉換的方法,因為調用jar包的方式,不需要考慮不同作業系統的問題,在視頻格式轉換時,jave官方給的API都是英文的,不是很好理解,需要注意的是視頻分為兩部分:音頻和映像,其中映像部分有視頻格式和視頻編碼,目前小視頻以及直播都是以H264編碼格式在解碼視頻的,所以如果需要轉換為mp4格式的視頻檔案時,如果在網站上顯示黑屏但是有聲音,主要原因就是視頻編解碼格式不匹配.所以下面我在轉換方法中運用的是flv格式,主要是因為flv不涉及此方面問題,但是缺點就是,flv產生的視頻會大於原視頻檔案,造成網路傳輸時效率降低.
private boolean process(String inputPath,String outputPath){
try {
logger.info("---------視頻轉換開始-------------");
File source = new File(inputPath);
File target = new File(outputPath);
long startTime = System.currentTimeMillis(); //擷取開始時間
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame"); //設定編碼器
audio.setBitRate(new Integer(64000)); //設定位元速率
audio.setChannels(new Integer(1)); //設定聲音頻道
audio.setSamplingRate(new Integer(22050)); //設定節錄率
VideoAttributes video = new VideoAttributes();
video.setCodec("flv"); //設定編碼器
video.setBitRate(new Integer(600000)); //設定位元速率
video.setFrameRate(new Integer(15)); //設定幀率
video.setSize(new VideoSize(640, 480)); //設定解析度
//video.setTag("libx264");
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("flv");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
long endTime = System.currentTimeMillis(); //擷取結束時間
logger.info("-------- -視頻轉換成功,耗時:"+((endTime-startTime)/1000.00)+"s----------");
return true;
} catch (Exception e) {
logger.info("視頻轉換異常:"+e.getMessage());
return false;
}
}?
java視頻轉換那些事