java 视频分辨率_Java 转换视频格式 或者 分辨率

packagecom.founder.util.video;importjava.util.ArrayList;importjava.util.List;public classTransferUtil {public static void main(String[] args) throwsFFmpegException {boolean flag = transform("D:\\ffmpeg\\ffmpeg2016\\bin\\ffmpeg.exe", "d:\\ys\\StoryBrooke.mp4", "d:\\ys\\480p.flv", "480x320");

System.out.println(flag);

}/*** 视频转换

*@paramffmpegPath ffmpeg路径

*@paramoldPath 原视频地址

*@paramnewPath 新视频存放地址(包含视频格式)

*@paramresolution 分辨率

*@return*@throwsFFmpegException*/

public static Boolean transform(String ffmpegPath, String oldPath, String newPath, String resolution) throwsFFmpegException {

List command =getFfmpegCommand(ffmpegPath, oldPath, newPath, resolution);if (null != command && command.size() > 0) {returnprocess(command);

}return false;

}private static boolean process(List command) throwsFFmpegException {try{if (null == command || command.size() == 0)return false;

Process videoProcess= new ProcessBuilder(command).redirectErrorStream(true).start();

videoProcess.getInputStream().close();int exitcode =videoProcess.waitFor();if (exitcode == 1)return false;return true;

}catch(Exception e) {throw new FFmpegException("file transfer failed", e);

}

}private static List getFfmpegCommand(String ffmpegPath, String oldfilepath, String outputPath, String resolution) throwsFFmpegException {

List command = new ArrayList();

command.add(ffmpegPath);//添加转换工具路径

command.add("-i"); //添加参数"-i",该参数指定要转换的文件

command.add(oldfilepath); //添加要转换格式的视频文件的路径

command.add("-qscale"); //指定转换的质量

command.add("4");/*command.add("-ab"); //设置音频码率

command.add("64");

command.add("-ac"); //设置声道数

command.add("2");

command.add("-ar"); //设置声音的采样频率

command.add("22050");*/command.add("-r"); //设置帧速率

command.add("24");

command.add("-s"); //设置分辨率

command.add(resolution);

command.add("-y"); //添加参数"-y",该参数指定将覆盖已存在的文件

command.add(outputPath);returncommand;

}

}class FFmpegException extendsException {private static final long serialVersionUID = 1L;publicFFmpegException() {super();

}publicFFmpegException(String message) {super(message);

}publicFFmpegException(Throwable cause) {super(cause);

}publicFFmpegException(String message, Throwable cause) {super(message, cause);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值