ffmpeg-cli-wrapper
ffmpeg-cli-wrapper copied to clipboard
Convert any audio to .mp3
Hi i want to do it as simply as the title says , i am very new with this wrapper but it looks so great project :)
I have read the READMe of repository and the wiki :
How to transform the below to convert any given audio file let's say (.aac) to (.mp3)
Thank you very much :)
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
FFmpegProbeResult in = ffprobe.probe("input.flv");
FFmpegBuilder builder = new FFmpegBuilder()
.setInput(in) // Or filename
.addOutput("output.mp4")
.done();
FFmpegJob job = executor.createJob(builder, new ProgressListener() {
// Using the FFmpegProbeResult determine the duration of the input
final double duration_ns = in.getFormat().duration * TimeUnit.SECONDS.toNanos(1);
@Override
public void progress(Progress progress) {
double percentage = progress.out_time_ns / duration_ns;
// Print out interesting information about the progress
System.out.println(String.format(
"[%.0f%%] status:%s frame:%d time:%s ms fps:%.0f speed:%.2fx",
percentage * 100,
progress.status,
progress.frame,
FFmpegUtils.toTimecode(progress.out_time_ns, TimeUnit.NANOSECONDS),
progress.fps.doubleValue(),
progress.speed
));
}
});
job.run();
For now i am using this code but it fails to convert .aac files to .mp3 for some reason . The output is only
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further detail
s.
[100%] status:end frame:0 time:00:00:02.299841 ms fps:0 speed:17.30x
try {
FFmpeg ffmpeg = new FFmpeg("D:\\GOXR3PLUS STUDIO\\XR3IA\\src\\ffmpegTesters\\ffmpeg.exe");
FFprobe ffprobe = new FFprobe("D:\\GOXR3PLUS STUDIO\\XR3IA\\src\\ffmpegTesters\\ffprobe.exe");
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
//
FFmpegProbeResult in = ffprobe.probe("audio.aac");
FFmpegBuilder builder = new FFmpegBuilder().setInput(in) // Or filename
.addOutput("audio.mp3").done();
FFmpegJob job = executor.createJob(builder, new ProgressListener() {
// Using the FFmpegProbeResult determine the duration of the input
final double duration_ns = in.getFormat().duration * TimeUnit.SECONDS.toNanos(1);
@Override
public void progress(Progress progress) {
double percentage = progress.out_time_ns / duration_ns;
// Print out interesting information about the progress
System.out.println(String.format("[%.0f%%] status:%s frame:%d time:%s ms fps:%.0f speed:%.2fx", percentage * 100, progress.status, progress.frame,
FFmpegUtils.toTimecode(progress.out_time_ns, TimeUnit.NANOSECONDS), progress.fps.doubleValue(), progress.speed));
}
});
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
FFprobe 是什么? 为什么我不用这个 也能给音频转码? 我的代码如下: try{
long start =System.currentTimeMillis();
FFmpeg ffmpeg = new FFmpeg("/Users/langjunnan/Downloads/ffmpeg");
FFmpegBuilder builder = new FFmpegBuilder()
.setInput("/Users/langjunnan/Desktop/1.wav") // 文件名,或FFmpegProbeResult
.addOutput("/Users/langjunnan/Desktop/audio/output_+"+SnowFlakeUtil.getId()+".mp7") // 目的地的文件名
// Override the output if it exists
//.setAudioBitRate(262144)
.setAudioBitRate(327680)
//最多320
.done();
builder.overrideOutputFiles(true);// 如果有文件覆盖
// ffmpeg.run(builder);
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg);
FFmpegJob job = executor.createJob(builder, new ProgressListener() {
@Override
public void progress(Progress progress) {
if(progress.status.equals(Progress.Status.END)){
System.out.println("执行ok");
}
}
});
job.run();
System.out.println(job.getState());
long end=System.currentTimeMillis();
System.out.println("执行完毕!"+(double)(end-start)/1000);
}catch (Exception e){
e.printStackTrace();
}
@goxr3plus According to the console output, the conversion has succeeded.
Try running the code using shell ffmpeg -i audio.aac audio.mp3
to test further