자바 는 30 줄 코드 만 사용 하여 비디오 오디 오 를 대량으로 변환 하 였 다.
spring boot 프로젝트 pom 파일 에 다음 의존 도 를 추가 합 니 다.
<!-- https://mvnrepository.com/artifact/ws.schild/jave-core -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-core</artifactId>
<version>3.1.1</version>
</dependency>
<!-- -->
<!-- win -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-nativebin-win64</artifactId>
<version>3.1.1</version>
</dependency>
<!-- linux -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-nativebin-linux64</artifactId>
<version>3.1.1</version>
</dependency>
자바 단일 클래스 구현 코드 를 Spring boot 프로젝트 에 복사 하여 아이디어 편집기 메 인 방법 으로 실행 합 니 다.
import ws.schild.jave.Encoder;
import ws.schild.jave.EncoderException;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;
import java.io.File;
import java.util.Arrays;
public class VideoToAudio {
//
private static String outputFormat="mp3";
/**
*
* @param sourceFilePath :
* @return
*/
public static String getNewFileName(String sourceFilePath) {
File source = new File(sourceFilePath);
String fileName=source.getName().substring(0, source.getName().lastIndexOf("."));
return fileName+"."+outputFormat;
}
/**
*
* @param sourceFilePath :
* @param targetFilePath :
* @return
*/
public static void transform(String sourceFilePath, String targetFilePath) {
File source = new File(sourceFilePath);
File target = new File(targetFilePath);
//
AudioAttributes audio = new AudioAttributes();
audio.setCodec(null);
//
EncodingAttributes attrs = new EncodingAttributes();
attrs.setOutputFormat(outputFormat);
attrs.setAudioAttributes(audio);
try {
//
Encoder encoder = new Encoder();
MultimediaObject mediaObject=new MultimediaObject(source);
encoder.encode(mediaObject, target, attrs);
System.out.println(" ...");
} catch (EncoderException e) {
e.printStackTrace();
}
}
/**
*
* @param sourceFolderPath :
* @param targetFolderPath :
* @return
*/
public static void batchTransform(String sourceFolderPath, String targetFolderPath) {
File sourceFolder = new File(sourceFolderPath);
if(sourceFolder.list().length!=0){
Arrays.asList(sourceFolder.list()).forEach(e->{
transform(sourceFolderPath+"\\"+e, targetFolderPath+"\\"+getNewFileName(e));
});
}
}
public static void main(String[] args) {
batchTransform("C:\\Users\\tarzan\\Desktop\\video","C:\\Users\\tarzan\\Desktop\\audio");
}
}
실행 결과 캡 처테스트 결과
비디오 포맷 은 mp4,크기 는 약 6.65MB,오디 오 포맷 MP3 로,크기 는 약 1.60MB,전환 시간 은 1s 정도 다.
자바 가 30 줄 코드 만으로 비디오 오디 오 를 대량으로 변환 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 자바 비디오 오디 오 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.