首先完成基本的Java调用ffmpeg代码实现

package com.example.ffmpegtest01.service.impl;

import com.example.ffmpegtest01.service.OperationService;

import org.springframework.stereotype.Service;

import java.io.File;

@Service

public class OperationServiceImpl implements OperationService {

@Override

public Boolean ForAvi(String sourcePath, String targetPath) {//sourcePtah是对应的文件的路径

String webroot = "D:\\devsoft\\ffmpeg\\bin";

Runtime run= null;

System.out.println(new File(webroot).getAbsolutePath());

try{

run = Runtime.getRuntime();

long start = System.currentTimeMillis();

//File diretory = new File("");

System.out.println("开始");

Process p = run.exec(new File(webroot).getAbsolutePath()+"/ffmpeg -i "+sourcePath+" -codec copy "+targetPath);

System.out.println("结束");

long end = System.currentTimeMillis();

System.out.println("转化结束"+(end-start));

p.getOutputStream().close();

p.getInputStream().close();

p.getErrorStream().close();

p.waitFor();

return true;

}catch (Exception e){

e.printStackTrace();

return false;

}finally {

run.freeMemory();

}

}

}

Java操作ffmpeg优秀博客

ffmpeg一些命令

博客借鉴

ffmfeg

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐